/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
namespace Dali
{
-namespace Integration
-{
-namespace Graphics
-{
-class SurfaceFactory
-{
-public:
- SurfaceFactory()
- {
- }
-};
-
-}
-}
bool TestApplication::mLoggingEnabled = true;
mLastVSyncTime(0u),
mDataRetentionPolicy( policy )
{
- Integration::Graphics::GraphicsCreateInfo info;
+ Dali::Integration::Graphics::GraphicsCreateInfo info;
info.surfaceWidth = 480;
info.surfaceHeight = 800;
info.depthStencilMode = Integration::Graphics::DepthStencilMode::NONE;
- mGraphics = std::unique_ptr<Dali::Integration::Graphics::Graphics>(
- new Dali::Integration::Graphics::Graphics( info,
- Integration::DepthBufferAvailable::FALSE,
- Integration::StencilBufferAvailable::FALSE));
+ mGraphics = std::unique_ptr<Test::Graphics>( new Test::Graphics( info,
+ Integration::DepthBufferAvailable::FALSE,
+ Integration::StencilBufferAvailable::FALSE));
Initialize();
}
#define __DALI_TEST_APPLICATION_H__
/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <test-platform-abstraction.h>
#include "test-gesture-manager.h"
#include "test-render-controller.h"
+#include "test-graphics.h"
#include <dali/public-api/common/dali-common.h>
#include <dali/public-api/signals/connection-tracker.h>
#include <dali/integration-api/core.h>
-#include <dali/integration-api/graphics/graphics.h>
+#include <dali/integration-api/graphics/graphics-interface.h>
#include <dali/integration-api/resource-policies.h>
#include <dali/integration-api/trace.h>
protected:
TestPlatformAbstraction mPlatformAbstraction;
- std::unique_ptr<Integration::Graphics::Graphics> mGraphics;
+ std::unique_ptr<Test::Graphics> mGraphics;
TestRenderController mRenderController;
TestGestureManager mGestureManager;
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "test-graphics-buffer-factory.h"
+
+namespace Test
+{
+
+GraphicsBufferFactory::GraphicsBufferFactory()=default;
+GraphicsBufferFactory::~GraphicsBufferFactory()=default;
+
+
+Dali::Graphics::API::BufferFactory& GraphicsBufferFactory::SetUsageFlags( Dali::Graphics::API::BufferUsageFlags usage )
+{
+ return *this;
+}
+
+Dali::Graphics::API::BufferFactory& GraphicsBufferFactory::SetSize( uint32_t size )
+{
+ return *this;
+}
+
+Dali::Graphics::API::BufferFactory::PointerType GraphicsBufferFactory::Create() const
+{
+ return nullptr;
+}
+
+}
--- /dev/null
+#ifndef TEST_GRAPHICS_BUFFER_FACTORY_H
+#define TEST_GRAPHICS_BUFFER_FACTORY_H
+
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <dali/graphics-api/graphics-api-buffer-factory.h>
+
+namespace Test
+{
+
+class GraphicsBufferFactory : public Dali::Graphics::API::BufferFactory
+{
+public:
+ GraphicsBufferFactory();
+ ~GraphicsBufferFactory();
+
+ Dali::Graphics::API::BufferFactory& SetUsageFlags( Dali::Graphics::API::BufferUsageFlags usage ) override;
+ Dali::Graphics::API::BufferFactory& SetSize( uint32_t size ) override;
+ Dali::Graphics::API::BufferFactory::PointerType Create() const override;
+};
+
+} // Test
+
+#endif //TEST_GRAPHICS_BUFFER_FACTORY_H
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include "test-graphics-controller.h"
+
+
+namespace Test
+{
+
+GraphicsController::GraphicsController()
+{
+}
+
+GraphicsController::~GraphicsController() = default;
+
+
+std::unique_ptr< Dali::Graphics::API::Shader > GraphicsController::CreateShader( const Dali::Graphics::API::BaseFactory< Dali::Graphics::API::Shader >& factory )
+{
+ return factory.Create();
+}
+
+std::unique_ptr< Dali::Graphics::API::Texture > GraphicsController::CreateTexture( const Dali::Graphics::API::BaseFactory< Dali::Graphics::API::Texture >& factory )
+{
+ return factory.Create();
+}
+
+std::unique_ptr< Dali::Graphics::API::Buffer > GraphicsController::CreateBuffer( const Dali::Graphics::API::BaseFactory< Dali::Graphics::API::Buffer >& factory )
+{
+ return factory.Create();
+}
+
+std::unique_ptr< Dali::Graphics::API::Sampler > GraphicsController::CreateSampler( const Dali::Graphics::API::BaseFactory< Dali::Graphics::API::Sampler >& factory )
+{
+ return factory.Create();
+}
+
+std::unique_ptr< Dali::Graphics::API::Pipeline > GraphicsController::CreatePipeline( const Dali::Graphics::API::PipelineFactory& factory )
+{
+ auto& pipelineFactory = const_cast<Dali::Graphics::API::PipelineFactory&>(dynamic_cast<const Dali::Graphics::API::PipelineFactory&>( factory ));
+ return pipelineFactory.Create();
+}
+
+std::unique_ptr< Dali::Graphics::API::Framebuffer > GraphicsController::CreateFramebuffer( const Dali::Graphics::API::BaseFactory< Dali::Graphics::API::Framebuffer >& factory )
+{
+ return factory.Create();
+}
+
+Dali::Graphics::API::TextureFactory& GraphicsController::GetTextureFactory() const
+{
+ return *(const_cast<GraphicsTextureFactory*>(&mTextureFactory));
+}
+
+Dali::Graphics::API::ShaderFactory& GraphicsController::GetShaderFactory() const
+{
+ return *(const_cast<GraphicsShaderFactory*>(&mShaderFactory));
+}
+
+Dali::Graphics::API::BufferFactory& GraphicsController::GetBufferFactory() const
+{
+ return *(const_cast<GraphicsBufferFactory*>(&mBufferFactory));
+}
+
+Dali::Graphics::API::FramebufferFactory& GraphicsController::GetFramebufferFactory() const
+{
+ return *(const_cast<GraphicsFramebufferFactory*>(&mFramebufferFactory));
+}
+
+Dali::Graphics::API::PipelineFactory& GraphicsController::GetPipelineFactory()
+{
+ return *(const_cast<GraphicsPipelineFactory*>(&mPipelineFactory));
+}
+
+Dali::Graphics::API::SamplerFactory& GraphicsController::GetSamplerFactory()
+{
+ return *(const_cast<GraphicsSamplerFactory*>(&mSamplerFactory));
+}
+
+std::unique_ptr< Dali::Graphics::API::RenderCommand > GraphicsController::AllocateRenderCommand()
+{
+ return nullptr;
+}
+
+void GraphicsController::SubmitCommands( std::vector< Dali::Graphics::API::RenderCommand* > commands )
+{
+}
+
+void GraphicsController::BeginFrame()
+{
+}
+
+void GraphicsController::EndFrame()
+{
+}
+
+void GraphicsController::Pause()
+{
+}
+
+void GraphicsController::Resume()
+{
+}
+
+bool GraphicsController::EnableDepthStencilBuffer( bool enableDepth, bool enableStencil )
+{
+ return true;
+}
+
+void GraphicsController::RunGarbageCollector( size_t numberOfDiscardedRenderers )
+{
+}
+
+void GraphicsController::DiscardUnusedResources()
+{
+}
+
+bool GraphicsController::IsDiscardQueueEmpty()
+{
+ return true;
+}
+
+bool GraphicsController::IsDrawOnResumeRequired()
+{
+ return false;
+}
+
+void GraphicsController::WaitIdle()
+{
+}
+
+void GraphicsController::SwapBuffers()
+{
+}
+
+uint32_t GraphicsController::GetSwapchainBufferCount()
+{
+ return 2;
+}
+
+}
--- /dev/null
+#ifndef TEST_GRAPHICS_CONTROLLER_H
+#define TEST_GRAPHICS_CONTROLLER_H
+
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// INTERNAL INCLUDES
+#include <dali/graphics-api/graphics-api-controller.h>
+
+#include "test-graphics-texture-factory.h"
+#include "test-graphics-shader-factory.h"
+#include "test-graphics-buffer-factory.h"
+#include "test-graphics-framebuffer-factory.h"
+#include "test-graphics-sampler-factory.h"
+#include "test-graphics-pipeline-factory.h"
+
+namespace Test
+{
+
+class GraphicsController : public Dali::Graphics::API::Controller
+{
+public:
+ explicit GraphicsController();
+
+ virtual ~GraphicsController();
+
+ /**
+ * @brief Create a new object
+ */
+ std::unique_ptr<Dali::Graphics::API::Shader> CreateShader( const Dali::Graphics::API::BaseFactory<Dali::Graphics::API::Shader>& factory ) override;
+
+ /**
+ * @brief Create a new object
+ */
+ std::unique_ptr<Dali::Graphics::API::Texture> CreateTexture( const Dali::Graphics::API::BaseFactory<Dali::Graphics::API::Texture>& factory ) override;
+
+ /**
+ * @brief Create a new object
+ */
+ std::unique_ptr<Dali::Graphics::API::Buffer> CreateBuffer( const Dali::Graphics::API::BaseFactory<Dali::Graphics::API::Buffer>& factory ) override;
+
+ /**
+ * @brief Create a new object
+ */
+ std::unique_ptr<Dali::Graphics::API::Sampler> CreateSampler( const Dali::Graphics::API::BaseFactory<Dali::Graphics::API::Sampler>& factory ) override;
+
+ /**
+ * @brief Create a new object
+ */
+ std::unique_ptr<Dali::Graphics::API::Framebuffer> CreateFramebuffer( const Dali::Graphics::API::BaseFactory<Dali::Graphics::API::Framebuffer>& factory ) override;
+
+ /**
+ * Creates new pipeline
+ */
+ std::unique_ptr<Dali::Graphics::API::Pipeline> CreatePipeline( const Dali::Graphics::API::PipelineFactory& factory ) override;
+
+ /**
+ * @brief Returns texture factory
+ * @return
+ */
+ Dali::Graphics::API::TextureFactory& GetTextureFactory() const override;
+
+ /**
+ * @brief Returns shader factory
+ * @return
+ */
+ Dali::Graphics::API::ShaderFactory& GetShaderFactory() const override;
+
+ /**
+ * @brief Returns Framebuffer factory
+ * @return
+ */
+ Dali::Graphics::API::FramebufferFactory& GetFramebufferFactory() const override;
+
+ /**
+ * @brief Returns shader factory
+ * @return
+ */
+ Dali::Graphics::API::BufferFactory& GetBufferFactory() const override;
+
+ /**
+ * @brief Returns pipeline factory
+ * @return
+ */
+ Dali::Graphics::API::PipelineFactory& GetPipelineFactory() override;
+
+ /**
+ * @brief Returns sampler factory
+ * @return
+ */
+ Dali::Graphics::API::SamplerFactory& GetSamplerFactory() override;
+
+ /**
+ * @brief alAllocates render command ( depends on implementation );
+ * @return
+ */
+ std::unique_ptr<Dali::Graphics::API::RenderCommand> AllocateRenderCommand() override;
+
+ /**
+ * @brief Submits a list of commands
+ * @param commands
+ */
+ void SubmitCommands( std::vector<Dali::Graphics::API::RenderCommand*> commands ) override;
+
+ /**
+ * @brief Mark the beginning of a frame
+ */
+ void BeginFrame() override;
+
+ /**
+ * @brief Mark the end of a frame
+ */
+ void EndFrame() override;
+
+ /**
+ * @brief Respond to pause lifecycle event
+ */
+ void Pause() override;
+
+ /**
+ * @brief Respond to resume lifecycle event
+ */
+ void Resume() override;
+
+ /**
+ * @brief Enables depth/stencil buffer if supported
+ *
+ * @return True if state changed, False otherwise
+ */
+ bool EnableDepthStencilBuffer( bool enableDepth, bool enableStencil ) override;
+
+ /**
+ * @brief Inform graphics backend if renderers have been discarded.
+ *
+ * @note The graphics backend does not have to run the GC if it is not overly fragmented
+ */
+ void RunGarbageCollector( size_t numberOfDiscardedRenderers ) override;
+
+ /**
+ * @brief Discards all the graphics resources by forcing full
+ * garbage collection.
+ */
+ void DiscardUnusedResources() override;
+
+ /**
+ * @brief Tests whether the graphics discard queue doesn't contain any resources
+ * to be released.
+ *
+ * @return True if queue is empty
+ */
+ bool IsDiscardQueueEmpty() override;
+
+ /**
+ * @brief Test if the graphics subsystem has resumed & should force a draw
+ *
+ * @return true if the graphics subsystem requires a re-draw
+ */
+ bool IsDrawOnResumeRequired() override;
+
+ /**
+ * @brief Waits until all previously submitted commands have been fully
+ * executed.
+ */
+ void WaitIdle() override;
+
+ /**
+ * @brief Swaps graphics buffers
+ */
+ void SwapBuffers() override;
+
+ /**
+ * Returns number of buffers allocated by the swapchain
+ * @return
+ */
+ uint32_t GetSwapchainBufferCount() override;
+
+public:
+ // not copyable
+ GraphicsController( const GraphicsController& ) = delete;
+ GraphicsController& operator=( const GraphicsController& ) = delete;
+
+protected:
+ // derived types should not be moved direcly to prevent slicing
+ GraphicsController( GraphicsController&& ) = default;
+ GraphicsController& operator=( GraphicsController&& ) = default;
+
+private:
+ GraphicsTextureFactory mTextureFactory;
+ GraphicsShaderFactory mShaderFactory;
+ GraphicsFramebufferFactory mFramebufferFactory;
+ GraphicsBufferFactory mBufferFactory;
+ GraphicsPipelineFactory mPipelineFactory;
+ GraphicsSamplerFactory mSamplerFactory;
+};
+
+} // namespace Test
+
+#endif // TEST_GRAPHICS_CONTROLLER_H
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "test-graphics-framebuffer-factory.h"
+
+namespace Test
+{
+GraphicsFramebufferFactory::GraphicsFramebufferFactory() = default;
+GraphicsFramebufferFactory::~GraphicsFramebufferFactory() = default;
+
+Dali::Graphics::API::FramebufferFactory& GraphicsFramebufferFactory::SetSize( const Dali::Graphics::API::RectSize& size )
+{
+ return *this;
+}
+
+Dali::Graphics::API::FramebufferFactory& GraphicsFramebufferFactory::SetColorAttachment(
+ Dali::Graphics::API::TextureDetails::AttachmentId attachmentIndex,
+ const Dali::Graphics::API::Texture& texture,
+ Dali::Graphics::API::TextureDetails::LayerId layer,
+ Dali::Graphics::API::TextureDetails::LevelId level )
+{
+ return *this;
+}
+
+Dali::Graphics::API::FramebufferFactory& GraphicsFramebufferFactory::SetDepthStencilAttachment(
+ const Dali::Graphics::API::Texture& texture,
+ Dali::Graphics::API::TextureDetails::LayerId layer,
+ Dali::Graphics::API::TextureDetails::LevelId level,
+ Dali::Graphics::API::TextureDetails::DepthStencilFlag depthStencilFlag )
+{
+ return *this;
+}
+
+Dali::Graphics::API::FramebufferFactory::PointerType GraphicsFramebufferFactory::Create() const
+{
+ return nullptr;
+}
+
+} // Test
--- /dev/null
+#ifndef TEST_GRAPHICS_FRAMEBUFFER_FACTORY_H
+#define TEST_GRAPHICS_FRAMEBUFFER_FACTORY_H
+
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <dali/graphics-api/graphics-api-framebuffer-factory.h>
+
+namespace Test
+{
+
+class GraphicsFramebufferFactory : public Dali::Graphics::API::FramebufferFactory
+{
+public:
+ GraphicsFramebufferFactory();
+ virtual ~GraphicsFramebufferFactory();
+
+ Dali::Graphics::API::FramebufferFactory& SetSize( const Dali::Graphics::API::RectSize& size ) override;
+
+ Dali::Graphics::API::FramebufferFactory& SetColorAttachment( Dali::Graphics::API::TextureDetails::AttachmentId attachmentIndex,
+ const Dali::Graphics::API::Texture& texture,
+ Dali::Graphics::API::TextureDetails::LayerId layer,
+ Dali::Graphics::API::TextureDetails::LevelId level ) override;
+
+ Dali::Graphics::API::FramebufferFactory& SetDepthStencilAttachment( const Dali::Graphics::API::Texture& texture,
+ Dali::Graphics::API::TextureDetails::LayerId layer,
+ Dali::Graphics::API::TextureDetails::LevelId level,
+ Dali::Graphics::API::TextureDetails::DepthStencilFlag depthStencilFlag ) override;
+ Dali::Graphics::API::FramebufferFactory::PointerType Create() const override;
+
+};
+
+} // Test
+
+#endif //TEST_GRAPHICS_FRAMEBUFFER_FACTORY_H
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "test-graphics-pipeline-factory.h"
+
+namespace Test
+{
+
+GraphicsPipelineFactory::GraphicsPipelineFactory() = default;
+GraphicsPipelineFactory::~GraphicsPipelineFactory() = default;
+
+Dali::Graphics::API::PipelineFactory& GraphicsPipelineFactory::SetColorBlendState( const Dali::Graphics::API::ColorBlendState& state )
+{
+ return *this;
+}
+
+Dali::Graphics::API::PipelineFactory& GraphicsPipelineFactory::SetShaderState( const Dali::Graphics::API::ShaderState& state )
+{
+ return *this;
+}
+
+Dali::Graphics::API::PipelineFactory& GraphicsPipelineFactory::SetViewportState( const Dali::Graphics::API::ViewportState& state )
+{
+ return *this;
+}
+
+
+Dali::Graphics::API::PipelineFactory& GraphicsPipelineFactory::SetFramebufferState( const Dali::Graphics::API::FramebufferState& state )
+{
+ return *this;
+}
+
+Dali::Graphics::API::PipelineFactory& GraphicsPipelineFactory::SetBasePipeline( Dali::Graphics::API::Pipeline& pipeline )
+{
+ return *this;
+}
+
+Dali::Graphics::API::PipelineFactory& GraphicsPipelineFactory::SetDepthStencilState( Dali::Graphics::API::DepthStencilState state )
+{
+ return *this;
+}
+
+Dali::Graphics::API::PipelineFactory& GraphicsPipelineFactory::SetRasterizationState( const Dali::Graphics::API::RasterizationState& state )
+{
+ return *this;
+}
+
+
+Dali::Graphics::API::PipelineFactory& GraphicsPipelineFactory::SetVertexInputState( const Dali::Graphics::API::VertexInputState& state )
+{
+ return *this;
+}
+
+
+Dali::Graphics::API::PipelineFactory& GraphicsPipelineFactory::SetInputAssemblyState( const Dali::Graphics::API::InputAssemblyState& state )
+{
+ return *this;
+}
+
+
+Dali::Graphics::API::PipelineFactory& GraphicsPipelineFactory::SetDynamicStateMask( const Dali::Graphics::API::PipelineDynamicStateMask mask )
+{
+ return *this;
+}
+
+
+Dali::Graphics::API::PipelineFactory& GraphicsPipelineFactory::SetOldPipeline( std::unique_ptr<Dali::Graphics::API::Pipeline> oldPipeline )
+{
+ return *this;
+}
+
+
+std::unique_ptr<Dali::Graphics::API::Pipeline> GraphicsPipelineFactory::Create()
+{
+ return nullptr;
+}
+
+} // Test
--- /dev/null
+#ifndef TEST_GRAPHICS_PIPELINE_FACTORY_H
+#define TEST_GRAPHICS_PIPELINE_FACTORY_H
+
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <dali/graphics-api/graphics-api-pipeline-factory.h>
+
+namespace Test
+{
+
+class GraphicsPipelineFactory : public Dali::Graphics::API::PipelineFactory
+{
+public:
+ GraphicsPipelineFactory();
+ virtual ~GraphicsPipelineFactory();
+
+ Dali::Graphics::API::PipelineFactory& SetColorBlendState( const Dali::Graphics::API::ColorBlendState& state ) override;
+
+ Dali::Graphics::API::PipelineFactory& SetShaderState( const Dali::Graphics::API::ShaderState& state ) override;
+
+ Dali::Graphics::API::PipelineFactory& SetViewportState( const Dali::Graphics::API::ViewportState& state ) override;
+
+ Dali::Graphics::API::PipelineFactory& SetFramebufferState( const Dali::Graphics::API::FramebufferState& state ) override;
+
+ Dali::Graphics::API::PipelineFactory& SetBasePipeline( Dali::Graphics::API::Pipeline& pipeline ) override;
+
+ Dali::Graphics::API::PipelineFactory& SetDepthStencilState( Dali::Graphics::API::DepthStencilState state ) override;
+
+ Dali::Graphics::API::PipelineFactory& SetRasterizationState( const Dali::Graphics::API::RasterizationState& state ) override;
+
+ Dali::Graphics::API::PipelineFactory& SetVertexInputState( const Dali::Graphics::API::VertexInputState& state ) override;
+
+ Dali::Graphics::API::PipelineFactory& SetInputAssemblyState( const Dali::Graphics::API::InputAssemblyState& state ) override;
+
+ Dali::Graphics::API::PipelineFactory& SetDynamicStateMask( const Dali::Graphics::API::PipelineDynamicStateMask mask ) override;
+
+ Dali::Graphics::API::PipelineFactory& SetOldPipeline( std::unique_ptr<Dali::Graphics::API::Pipeline> oldPipeline ) override;
+
+ std::unique_ptr<Dali::Graphics::API::Pipeline> Create() override;
+};
+
+} // Test
+
+#endif //TEST_GRAPHICS_PIPELINE_FACTORY_H
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "test-graphics-sampler-factory.h"
+
+namespace Test
+{
+
+
+GraphicsSamplerFactory::GraphicsSamplerFactory()
+{
+}
+
+GraphicsSamplerFactory::~GraphicsSamplerFactory() = default;
+
+Dali::Graphics::API::SamplerFactory& GraphicsSamplerFactory::SetAddressModeU( Dali::Graphics::API::SamplerAddressMode mode )
+{
+ return *this;
+}
+
+Dali::Graphics::API::SamplerFactory& GraphicsSamplerFactory::SetAddressModeV( Dali::Graphics::API::SamplerAddressMode mode )
+{
+ return *this;
+}
+
+Dali::Graphics::API::SamplerFactory& GraphicsSamplerFactory::SetAddressModeW( Dali::Graphics::API::SamplerAddressMode mode )
+{
+ return *this;
+}
+
+Dali::Graphics::API::SamplerFactory& GraphicsSamplerFactory::SetMinFilter( Dali::Graphics::API::SamplerFilter filter )
+{
+ return *this;
+}
+
+Dali::Graphics::API::SamplerFactory& GraphicsSamplerFactory::SetMagFilter( Dali::Graphics::API::SamplerFilter filter )
+{
+ return *this;
+}
+
+Dali::Graphics::API::SamplerFactory& GraphicsSamplerFactory::SetMipmapMode( Dali::Graphics::API::SamplerMipmapMode mipmapMode )
+{
+ return *this;
+}
+
+Dali::Graphics::API::SamplerFactory& GraphicsSamplerFactory::SetAnisotropyEnable( bool anisotropyEnable )
+{
+ return *this;
+}
+
+Dali::Graphics::API::SamplerFactory& GraphicsSamplerFactory::SetMaxAnisotropy( float maxAnisotropy )
+{
+ return *this;
+}
+
+Dali::Graphics::API::SamplerFactory& GraphicsSamplerFactory::SetMinLod( float minLod )
+{
+ return *this;
+}
+
+Dali::Graphics::API::SamplerFactory& GraphicsSamplerFactory::SetMaxLod( float maxLod )
+{
+ return *this;
+}
+
+Dali::Graphics::API::SamplerFactory& GraphicsSamplerFactory::SetUnnormalizeCoordinates( bool unnormalizedCoordinates )
+{
+ return *this;
+}
+
+Dali::Graphics::API::SamplerFactory& GraphicsSamplerFactory::SetCompareEnable( bool compareEnable )
+{
+ return *this;
+}
+
+Dali::Graphics::API::SamplerFactory& GraphicsSamplerFactory::SetCompareOp( Dali::Graphics::API::CompareOp compareOp )
+{
+ return *this;
+}
+
+Dali::Graphics::API::SamplerFactory::PointerType GraphicsSamplerFactory::Create() const
+{
+ return nullptr;
+};
+
+
+} // Test
--- /dev/null
+#ifndef TEST_GRAPHICS_SAMPLER_FACTORY_H
+#define TEST_GRAPHICS_SAMPLER_FACTORY_H
+
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <dali/graphics-api/graphics-api-sampler-factory.h>
+
+namespace Test
+{
+
+
+class GraphicsSamplerFactory : public Dali::Graphics::API::SamplerFactory
+{
+public:
+ GraphicsSamplerFactory();
+ virtual ~GraphicsSamplerFactory();
+
+ Dali::Graphics::API::SamplerFactory& SetAddressModeU( Dali::Graphics::API::SamplerAddressMode mode ) override;
+
+ Dali::Graphics::API::SamplerFactory& SetAddressModeV( Dali::Graphics::API::SamplerAddressMode mode ) override;
+
+ Dali::Graphics::API::SamplerFactory& SetAddressModeW( Dali::Graphics::API::SamplerAddressMode mode ) override;
+
+ Dali::Graphics::API::SamplerFactory& SetMinFilter( Dali::Graphics::API::SamplerFilter filter ) override;
+
+ Dali::Graphics::API::SamplerFactory& SetMagFilter( Dali::Graphics::API::SamplerFilter filter ) override;
+
+ Dali::Graphics::API::SamplerFactory& SetMipmapMode( Dali::Graphics::API::SamplerMipmapMode mipmapMode ) override;
+
+ Dali::Graphics::API::SamplerFactory& SetAnisotropyEnable( bool anisotropyEnable ) override;
+
+ Dali::Graphics::API::SamplerFactory& SetMaxAnisotropy( float maxAnisotropy ) override;
+
+ Dali::Graphics::API::SamplerFactory& SetMinLod( float minLod ) override;
+
+ Dali::Graphics::API::SamplerFactory& SetMaxLod( float maxLod ) override;
+
+ Dali::Graphics::API::SamplerFactory& SetUnnormalizeCoordinates( bool unnormalizedCoordinates ) override;
+
+ Dali::Graphics::API::SamplerFactory& SetCompareEnable( bool compareEnable ) override;
+
+ Dali::Graphics::API::SamplerFactory& SetCompareOp( Dali::Graphics::API::CompareOp compareOp ) override;
+
+ Dali::Graphics::API::SamplerFactory::PointerType Create() const override;
+};
+
+} // Test
+
+#endif //TEST_GRAPHICS_SAMPLER_FACTORY_H
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "test-graphics-shader-factory.h"
+
+namespace Test
+{
+GraphicsShaderFactory::GraphicsShaderFactory() = default;
+GraphicsShaderFactory::~GraphicsShaderFactory() = default;
+
+Dali::Graphics::API::ShaderFactory& GraphicsShaderFactory::SetShaderModule(
+ Dali::Graphics::API::ShaderDetails::PipelineStage pipelineStage,
+ Dali::Graphics::API::ShaderDetails::Language language,
+ const Dali::Graphics::API::ShaderDetails::ShaderSource& source )
+{
+ return *this;
+}
+
+Dali::Graphics::API::ShaderFactory::PointerType GraphicsShaderFactory::Create() const
+{
+ return nullptr;
+}
+
+} // Test
--- /dev/null
+#ifndef TEST_GRAPHICS_SHADER_FACTORY_H
+#define TEST_GRAPHICS_SHADER_FACTORY_H
+
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <dali/graphics-api/graphics-api-shader-factory.h>
+
+namespace Test
+{
+
+class GraphicsShaderFactory : public Dali::Graphics::API::ShaderFactory
+{
+public:
+ GraphicsShaderFactory();
+ ~GraphicsShaderFactory();
+
+ Dali::Graphics::API::ShaderFactory& SetShaderModule( Dali::Graphics::API::ShaderDetails::PipelineStage pipelineStage,
+ Dali::Graphics::API::ShaderDetails::Language language,
+ const Dali::Graphics::API::ShaderDetails::ShaderSource& source ) override;
+
+ Dali::Graphics::API::ShaderFactory::PointerType Create() const override;
+};
+
+} // Test
+
+#endif //TEST_GRAPHICS_SHADER_FACTORY_H
--- /dev/null
+
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "test-graphics-texture-factory.h"
+
+namespace Test
+{
+
+GraphicsTextureFactory::GraphicsTextureFactory() = default;
+GraphicsTextureFactory::~GraphicsTextureFactory() = default;
+
+Dali::Graphics::API::TextureFactory& GraphicsTextureFactory::SetType(Dali::Graphics::API::TextureDetails::Type type)
+{
+ return *this;
+}
+Dali::Graphics::API::TextureFactory& GraphicsTextureFactory::SetSize(const Dali::Graphics::API::RectSize& size)
+{
+ return *this;
+}
+Dali::Graphics::API::TextureFactory& GraphicsTextureFactory::SetFormat(Dali::Graphics::API::TextureDetails::Format format)
+{
+ return *this;
+}
+Dali::Graphics::API::TextureFactory& GraphicsTextureFactory::SetMipMapFlag(Dali::Graphics::API::TextureDetails::MipMapFlag mipMapFlag)
+{
+ return *this;
+}
+Dali::Graphics::API::TextureFactory& GraphicsTextureFactory::SetUsage( Dali::Graphics::API::TextureDetails::Usage usage )
+{
+ return *this;
+}
+Dali::Graphics::API::TextureFactory& GraphicsTextureFactory::SetData( void* pData )
+{
+ return *this;
+}
+Dali::Graphics::API::TextureFactory& GraphicsTextureFactory::SetDataSize( uint32_t dataSizeInBytes )
+{
+ return *this;
+}
+Dali::Graphics::API::TextureFactory::PointerType GraphicsTextureFactory::Create() const
+{
+ return nullptr;
+}
+
+} // Test
--- /dev/null
+#ifndef TEST_GRAPHICS_TEXTURE_FACTORY_H
+#define TEST_GRAPHICS_TEXTURE_FACTORY_H
+
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <dali/graphics-api/graphics-api-texture-factory.h>
+
+namespace Test
+{
+
+class GraphicsTextureFactory : public Dali::Graphics::API::TextureFactory
+{
+public:
+ GraphicsTextureFactory();
+ virtual ~GraphicsTextureFactory();
+
+ Dali::Graphics::API::TextureFactory& SetType(Dali::Graphics::API::TextureDetails::Type type) override;
+ Dali::Graphics::API::TextureFactory& SetSize(const Dali::Graphics::API::RectSize& size) override;
+ Dali::Graphics::API::TextureFactory& SetFormat(Dali::Graphics::API::TextureDetails::Format format) override;
+ Dali::Graphics::API::TextureFactory& SetMipMapFlag(Dali::Graphics::API::TextureDetails::MipMapFlag mipMapFlag) override;
+ Dali::Graphics::API::TextureFactory& SetUsage( Dali::Graphics::API::TextureDetails::Usage usage ) override;
+ Dali::Graphics::API::TextureFactory& SetData( void* pData ) override;
+ Dali::Graphics::API::TextureFactory& SetDataSize( uint32_t dataSizeInBytes ) override;
+ Dali::Graphics::API::TextureFactory::PointerType Create() const override;
+};
+
+} // Test
+
+#endif //TEST_GRAPHICS_TEXTURE_FACTORY_H
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "test-graphics.h"
+#include "test-graphics-controller.h"
+
+namespace Test
+{
+
+struct Graphics::Impl
+{
+public:
+ GraphicsController controller;
+};
+
+
+
+Graphics::Graphics( const Dali::Integration::Graphics::GraphicsCreateInfo& info,
+ Dali::Integration::DepthBufferAvailable depthBufferAvailable,
+ Dali::Integration::StencilBufferAvailable stencilBufferRequired )
+: GraphicsInterface( info, depthBufferAvailable, stencilBufferRequired ),
+ mImpl(new Graphics::Impl() )
+{
+}
+
+Graphics::~Graphics() = default;
+
+void Graphics::Initialize()
+{
+}
+
+void Graphics::Create()
+{
+}
+
+void Graphics::Destroy()
+{
+}
+
+void Graphics::Pause()
+{
+}
+
+void Graphics::Resume()
+{
+}
+
+void Graphics::PreRender()
+{
+}
+
+void Graphics::PostRender()
+{
+}
+
+Dali::Graphics::API::Controller& Graphics::GetController()
+{
+ return mImpl->controller;
+}
+
+void Graphics::SurfaceResized( unsigned int width, unsigned int height )
+{
+}
+
+
+} // Namespace Test
--- /dev/null
+#ifndef TEST_GRAPHICS_H
+#define TEST_GRAPHICS_H
+
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// INTERNAL INCLUDES
+#include <dali/integration-api/graphics/graphics-interface.h>
+
+// EXTERNAL INCLUDES
+#include <memory>
+
+#define EXPORT_API __attribute__ ((visibility ("default")))
+
+namespace Test
+{
+class Controller;
+
+/**
+ * Graphics implementation class
+ */
+class Graphics : public Dali::Integration::Graphics::GraphicsInterface
+{
+public:
+
+ Graphics( const Dali::Integration::Graphics::GraphicsCreateInfo& info,
+ Dali::Integration::DepthBufferAvailable depthBufferAvailable,
+ Dali::Integration::StencilBufferAvailable stencilBufferRequired );
+
+ ~Graphics();
+
+ void Initialize() override;
+
+ void Create() override;
+
+ void Destroy() override;
+
+ /**
+ * Lifecycle event for pausing application
+ */
+ void Pause() override;
+
+ /**
+ * Lifecycle event for resuming application
+ */
+ void Resume() override;
+
+ /**
+ * Prerender
+ */
+ void PreRender() override;
+
+ /*
+ * Postrender
+ */
+ void PostRender() override;
+
+ /**
+ * Returns controller object
+ * @return
+ */
+ Dali::Graphics::API::Controller& GetController();
+
+ /*
+ * Surface resized
+ */
+ void SurfaceResized( unsigned int width, unsigned int height );
+
+ Dali::Integration::Graphics::GraphicsCreateInfo& GetCreateInfo()
+ {
+ return mCreateInfo;
+ }
+
+private:
+ Dali::Integration::Graphics::GraphicsCreateInfo mCreateInfo;
+
+ struct Impl;
+ Impl* mImpl;
+};
+
+
+} // Namespace Test
+
+#endif // TEST_GRAPHICS_H
-# Copyright (c) 2018 Samsung Electronics Co., Ltd.
+# Copyright (c) 2019 Samsung Electronics Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# limitations under the License.
-SUBDIRS = dali-core/graphics dali-core
+SUBDIRS = dali-core
pkgconfigdir = $(libdir)/pkgconfig
-# Copyright (c) 2018 Samsung Electronics Co., Ltd.
+# Copyright (c) 2019 Samsung Electronics Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
DALI_CFLAGS="$DALI_CFLAGS -D_GLIBCXX_USE_CXX11_ABI=0"
fi
-AC_ARG_ENABLE([vulkan],
- [AC_HELP_STRING([--enable-vulkan],
- [Enables Vulkan support])],
- [enable_vulkan=$enableval],
- [enable_vulkan=no])
-
-DALI_CFLAGS="$DALI_CFLAGS -DDALI_GLES_VERSION=${enable_gles}"
-
if test "x$enable_debug" = "xyes"; then
DALI_CFLAGS="$DALI_CFLAGS -DDEBUG_ENABLED"
fi
DALI_CFLAGS="$DALI_CFLAGS -I${includedir} -DDali=DaliVk"
DALI_LDFLAGS="-L${libdir}"
-# forward VULKAN_SDK path to the graphics library if set correctly
-if test x"$enable_vulkan" != x"no"; then
- PKG_CHECK_MODULES(VULKAN, vulkan, AC_DEFINE(ENABLE_VULKAN, 1, [Vulkan available as package]),
- [ AC_MSG_ERROR([Vulkan not available as a package!]) ]
- )
- DALI_LDFLAGS+=" ${VULKAN_LIBS}"
- DALI_CFLAGS+=" ${VULKAN_CFLAGS}"
- AC_SUBST(VULKAN_SDK)
- AC_SUBST(VULKAN_LIBS)
- AC_SUBST(VULKAN_CFLAGS)
-fi
-AM_CONDITIONAL([VULKAN_SDK_SET], [test x"$enable_vulkan" != x"no"])
AC_SUBST(dataReadWriteDir)
AC_SUBST(dataReadOnlyDir)
devincludepath=${includedir}
AC_SUBST(devincludepath)
-AC_CONFIG_FILES([Makefile dali-core/Makefile dali-core/graphics/Makefile])
+AC_CONFIG_FILES([Makefile dali-core/Makefile])
if test "x$enable_cxx03_abi" = "xyes"; then
AC_CONFIG_FILES([dali-core-vk-cxx03.pc])
Data Dir (Read Only): $dataReadOnlyDir
Backtrace: $enable_backtrace
ScopedLock Backtrace: $enable_lock_backtrace
- Vulkan Support: $enable_vulkan
- OpenGL ES version: $enable_gles
C++03 ABI: $enable_cxx03_abi
Rename so file: $enable_rename_so
"
-# Copyright (c) 2018 Samsung Electronics Co., Ltd.
+# Copyright (c) 2019 Samsung Electronics Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
public_api_src_dir = ../../../dali/public-api
include ../../../dali/public-api/file.list
+graphics_api_src_dir = ../../../dali/graphics-api
+include ../../../dali/graphics-api/file.list
+
devel_api_src_dir = ../../../dali/devel-api
include ../../../dali/devel-api/file.list
$(dali_core_includes) \
$(DALI_CFLAGS)
-
-DALI_CORE_LA_LDFLAGS = $(DALI_LDFLAGS) -Wl,--whole-archive,graphics/libdali-graphics.a,--no-whole-archive
-
DALI_CORE_LA_LIBADD = $(DALI_LDFLAGS) \
$(VULKAN_LIBS) \
-lpthread
libdali_core_vk_la_SOURCES = $(DALI_CORE_LA_SOURCES)
libdali_core_vk_la_CXXFLAGS = $(DALI_CORE_LA_CXXFLAGS)
-libdali_core_vk_la_LIBADD = $(DALI_CORE_LA_LIBADD) graphics/libdali-graphics.a
+libdali_core_vk_la_LIBADD = $(DALI_CORE_LA_LIBADD)
else
libdali_core_vk_cxx11_la_SOURCES = $(DALI_CORE_LA_SOURCES)
libdali_core_vk_cxx11_la_CXXFLAGS = $(DALI_CORE_LA_CXXFLAGS)
-libdali_core_vk_cxx11_la_LIBADD = $(DALI_CORE_LA_LIBADD) graphics/libdali-graphics.a
+libdali_core_vk_cxx11_la_LIBADD = $(DALI_CORE_LA_LIBADD)
endif
platformabstractiondir = $(includedir)/dali/integration-api
platformabstractioneventsdir = $(includedir)/dali/integration-api/events
platformabstractiongraphicsdir = $(includedir)/dali/integration-api/graphics
-platformabstractiongraphicsvulkandir = $(includedir)/dali/integration-api/graphics/vulkan
platformabstraction_HEADERS = $(platform_abstraction_header_files)
platformabstractionevents_HEADERS = $(platform_abstraction_events_header_files)
platformabstractiongraphics_HEADERS = $(graphics_integration_header_files)
-platformabstractiongraphicsvulkan_HEADERS = $(graphics_vulkan_integration_header_files)
+
+# Graphics API (Integration)
+graphicsapidir = $(includedir)/dali/graphics-api
+graphicsapiutilitydir = $(includedir)/dali/graphics-api/utility
+graphicsapi_HEADERS = $(graphics_api_header_files)
+graphicsapiutility_HEADERS = $(graphics_api_utility_header_files)
#devel api (used by adaptor / toolkit
develapidir = $(devincludepath)/dali/devel-api
linker_test_SOURCES = linker-test.cpp \
../../../automated-tests/src/dali/dali-test-suite-utils/test-application.cpp \
+ ../../../automated-tests/src/dali/dali-test-suite-utils/test-graphics-controller.cpp \
+ ../../../automated-tests/src/dali/dali-test-suite-utils/test-graphics.cpp \
+ ../../../automated-tests/src/dali/dali-test-suite-utils/test-graphics-buffer-factory.cpp \
+ ../../../automated-tests/src/dali/dali-test-suite-utils/test-graphics-framebuffer-factory.cpp \
+ ../../../automated-tests/src/dali/dali-test-suite-utils/test-graphics-pipeline-factory.cpp \
+ ../../../automated-tests/src/dali/dali-test-suite-utils/test-graphics-sampler-factory.cpp \
+ ../../../automated-tests/src/dali/dali-test-suite-utils/test-graphics-shader-factory.cpp \
+ ../../../automated-tests/src/dali/dali-test-suite-utils/test-graphics-texture-factory.cpp \
../../../automated-tests/src/dali/dali-test-suite-utils/test-platform-abstraction.cpp \
../../../automated-tests/src/dali/dali-test-suite-utils/test-render-controller.cpp \
../../../automated-tests/src/dali/dali-test-suite-utils/test-gesture-manager.cpp \
+++ /dev/null
-# Copyright (c) 2018 Samsung Electronics Co., Ltd.
-
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-
-# http://www.apache.org/licenses/LICENSE-2.0
-
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-# Parse each file.list
-# These files define <module>_src_files & <module>_header_files,
-# where <module> is the subdirectory from core_src_dir
-
-graphics_api_src_dir = ../../../../dali/graphics-api
-include ../../../../dali/graphics-api/file.list
-
-graphics_src_dir = ../../../../dali/graphics
-include ../../../../dali/graphics/file.list
-
-graphics_integration_dir = ../../../../dali/integration-api/graphics
-include ../../../../dali/integration-api/graphics/file.list
-
-# Build the graphics library
-noinst_LIBRARIES = libdali-graphics.a
-
-libdali_graphics_a_SOURCES = $(graphics_api_src_files) \
- $(graphics_src_files) \
- $(graphics_integration_src_files)
-
-#libdali_graphics_a_LDFLAGS = -fPIC
-
-
-dali_core_includes = \
- -I../../../..
-
-
-gcc_flags = -Wno-return-local-addr -Wsuggest-final-types -Wsuggest-final-methods -Wsuggest-override \
- -Wstack-usage=256 -Wunsafe-loop-optimizations -Wzero-as-null-pointer-constant -Wuseless-cast
-
-# -Wfloat-equal causes issues with vulkan.hpp, removed for now
-cxx_more_warnings = -Wold-style-cast -Woverloaded-virtual -Wdouble-promotion -Wswitch-enum \
- -Wshadow \
- -Wcast-qual -Wcast-align \
- -Wconversion -Wsign-conversion
-
-#-Wlarger-than=1024 # Conflicts with --coverage
-
-# the following warnings should not be enforced
-cxx_warnings_to_remove = \
- -Wno-c++98-compat \
- -Wno-unused-parameter \
- -Wno-unknown-warning-option \
- -Wno-switch \
- -Wno-switch-enum \
- -Wno-error=switch \
- -Wno-error=switch-enum
-
-#the following warnings should be added back when possible
-cxx_warnings_to_preserve = \
- -Wno-weak-vtables
-
-#cxx_flags = -fPIC -std=c++14 -Werror -Wall -Wextra -Weffc++ -Wpedantic \
-# $(cxx_more_warnings) $(cxx_warnings_to_remove) $(cxx_warnings_to_preserve)
-# vulkan.hpp doesn't pass all c++ checks
-cxx_flags = -fPIC -std=c++14 -Werror -Wall -Wextra -Wpedantic \
- $(cxx_more_warnings) $(cxx_warnings_to_remove) $(cxx_warnings_to_preserve)
-
-if VULKAN_SDK_SET
- vulkan_flags = -DVULKAN_HPP_NO_EXCEPTIONS
-endif
-
-libdali_graphics_a_CXXFLAGS = $(cxx_flags) \
- $(dali_core_includes) \
- $(DALI_CFLAGS) \
- $(vulkan_flags)
graphics_api_src_files =
+graphics_api_header_files = \
+ $(graphics_api_src_dir)/graphics-api-base-factory.h \
+ $(graphics_api_src_dir)/graphics-api-buffer-factory.h \
+ $(graphics_api_src_dir)/graphics-api-buffer.h \
+ $(graphics_api_src_dir)/graphics-api-controller.h \
+ $(graphics_api_src_dir)/graphics-api-framebuffer-factory.h \
+ $(graphics_api_src_dir)/graphics-api-framebuffer.h \
+ $(graphics_api_src_dir)/graphics-api-pipeline-factory.h \
+ $(graphics_api_src_dir)/graphics-api-pipeline.h \
+ $(graphics_api_src_dir)/graphics-api-render-command.h \
+ $(graphics_api_src_dir)/graphics-api-sampler-factory.h \
+ $(graphics_api_src_dir)/graphics-api-sampler.h \
+ $(graphics_api_src_dir)/graphics-api-shader-details.h \
+ $(graphics_api_src_dir)/graphics-api-shader-factory.h \
+ $(graphics_api_src_dir)/graphics-api-shader.h \
+ $(graphics_api_src_dir)/graphics-api-texture-details.h \
+ $(graphics_api_src_dir)/graphics-api-texture-factory.h \
+ $(graphics_api_src_dir)/graphics-api-texture.h \
+ $(graphics_api_src_dir)/graphics-api-types-debug.h \
+ $(graphics_api_src_dir)/graphics-api-types.h \
+ $(graphics_api_src_dir)/graphics-api-utility.h
+
+graphics_api_utility_header_files=\
+ $(graphics_api_src_dir)/utility/graphics-asserts.h \
+ $(graphics_api_src_dir)/utility/utility-builder.h \
+ $(graphics_api_src_dir)/utility/utility-memory-pool.h \
+ $(graphics_api_src_dir)/utility/utility-queue.h \
+ $(graphics_api_src_dir)/utility/utility-strong-type.h \
+ $(graphics_api_src_dir)/utility/utility-synchronized.h \
+ $(graphics_api_src_dir)/utility/utility-traits.h
\ No newline at end of file
#define DALI_GRAPHICS_API_RENDER_COMMAND_H
/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
std::vector<PushConstantsBinding> mPushConstantsBindings;
const Pipeline* mPipeline;
+protected:
+ uint32_t mUpdateFlags; // update flags to be handled by implementation
+
+public:
+ // WARNING: Be careful with these - all libraries must be built with DEBUG_ENABLED
+ // to ensure every instantiation has the same size.
#if defined(DEBUG_ENABLED)
// Debug
std::string mDebugString{""};
void* mDebugObject{nullptr};
#endif
-protected:
-
- uint32_t mUpdateFlags; // update flags to be handled by implementation
-
};
} // namespace API
+++ /dev/null
-# Add graphics source files here
-
-graphics_src_files = \
- $(graphics_src_dir)/vulkan/internal/vulkan-command-pool.cpp \
- $(graphics_src_dir)/vulkan/internal/vulkan-surface.cpp \
- $(graphics_src_dir)/vulkan/internal/vulkan-fence.cpp \
- $(graphics_src_dir)/vulkan/internal/vulkan-framebuffer.cpp \
- $(graphics_src_dir)/vulkan/internal/vulkan-queue.cpp \
- $(graphics_src_dir)/vulkan/internal/vulkan-image.cpp \
- $(graphics_src_dir)/vulkan/internal/vulkan-image-view.cpp \
- $(graphics_src_dir)/vulkan/internal/vulkan-command-buffer.cpp \
- $(graphics_src_dir)/vulkan/internal/vulkan-buffer.cpp \
- $(graphics_src_dir)/vulkan/internal/vulkan-debug.cpp \
- $(graphics_src_dir)/vulkan/internal/vulkan-debug-allocator.cpp \
- $(graphics_src_dir)/vulkan/internal/vulkan-framebuffer.cpp \
- $(graphics_src_dir)/vulkan/internal/vulkan-shader.cpp \
- $(graphics_src_dir)/vulkan/internal/vulkan-swapchain.cpp \
- $(graphics_src_dir)/vulkan/internal/vulkan-sampler.cpp \
- $(graphics_src_dir)/vulkan/internal/spirv/vulkan-spirv.cpp \
- $(graphics_src_dir)/vulkan/vulkan-graphics.cpp \
- $(graphics_src_dir)/vulkan/api/vulkan-api-controller.cpp \
- $(graphics_src_dir)/vulkan/api/vulkan-api-shader.cpp \
- $(graphics_src_dir)/vulkan/api/vulkan-api-texture.cpp \
- $(graphics_src_dir)/vulkan/api/vulkan-api-buffer.cpp \
- $(graphics_src_dir)/vulkan/api/vulkan-api-sampler.cpp \
- $(graphics_src_dir)/vulkan/api/vulkan-api-buffer-factory.cpp \
- $(graphics_src_dir)/vulkan/api/vulkan-api-framebuffer.cpp \
- $(graphics_src_dir)/vulkan/api/vulkan-api-framebuffer-factory.cpp \
- $(graphics_src_dir)/vulkan/api/vulkan-api-texture-factory.cpp \
- $(graphics_src_dir)/vulkan/api/vulkan-api-shader-factory.cpp \
- $(graphics_src_dir)/vulkan/api/vulkan-api-sampler-factory.cpp \
- $(graphics_src_dir)/vulkan/api/vulkan-api-render-command.cpp \
- $(graphics_src_dir)/vulkan/api/vulkan-api-pipeline.cpp \
- $(graphics_src_dir)/vulkan/api/vulkan-api-pipeline-factory.cpp \
- $(graphics_src_dir)/vulkan/api/internal/vulkan-api-debug.cpp \
- $(graphics_src_dir)/vulkan/api/internal/vulkan-api-descriptor-set-allocator.cpp \
- $(graphics_src_dir)/vulkan/api/internal/vulkan-api-descriptor-set-requirements.cpp \
- $(graphics_src_dir)/vulkan/api/internal/vulkan-pipeline-cache.cpp \
- $(graphics_src_dir)/vulkan/api/internal/vulkan-pipeline-cache-debug.cpp \
- $(graphics_src_dir)/vulkan/api/internal/vulkan-api-pipeline-impl.cpp \
- $(graphics_src_dir)/thread-pool.cpp
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include "thread-pool.h"
-
-namespace Dali
-{
-namespace Graphics
-{
-
-// WorkerThread ---------------------------------------------------------------------------------
-void WorkerThread::WaitAndExecute()
-{
- while( true )
- {
- Task task;
-
- {
- std::unique_lock< std::mutex > lock{ mTaskQueueMutex };
-
- mConditionVariable.wait( lock, [ this ]() -> bool {
- return !mTaskQueue.empty() || mTerminating;
- } );
-
- if( mTerminating )
- {
- break;
- }
-
- task = mTaskQueue.front();
- }
-
- task( mIndex );
-
- {
- std::lock_guard< std::mutex > lock{ mTaskQueueMutex };
-
- mTaskQueue.pop();
-
- mConditionVariable.notify_one();
- }
- }
-}
-
-WorkerThread::WorkerThread(uint32_t index) : mIndex( index )
-{
- // Have to pass "this" as an argument because WaitAndExecute is a member function.
- mWorker = std::thread{ &WorkerThread::WaitAndExecute, this };
-}
-
-WorkerThread::~WorkerThread()
-{
- if( mWorker.joinable() )
- {
- Wait();
-
- {
- std::lock_guard< std::mutex > lock{ mTaskQueueMutex };
- mTerminating = true;
- mConditionVariable.notify_one();
- }
-
- mWorker.join();
- }
-}
-
-void WorkerThread::AddTask( Task task )
-{
- std::lock_guard< std::mutex > lock{ mTaskQueueMutex };
- mTaskQueue.push( std::move( task ) );
- mConditionVariable.notify_one();
-}
-
-void WorkerThread::Wait()
-{
- std::unique_lock< std::mutex > lock{ mTaskQueueMutex };
- mConditionVariable.wait( lock, [ this ]() -> bool {
- return mTaskQueue.empty();
- } );
-}
-
-// ThreadPool -----------------------------------------------------------------------------------------------
-
-uint32_t ThreadPool::sWorkerIndex{ 0 };
-
-bool ThreadPool::Initialize()
-{
-// LOG( "Initializing thread pool..." );
-
- /**
- * Get the system's supported thread count.
- */
- auto thread_count = std::thread::hardware_concurrency();
-
- if( !thread_count )
- {
- return false;
- }
-
- /**
- * Spawn the worker threads.
- */
- for( auto i = 0u; i < thread_count - 1; i++ )
- {
- /**
- * The workers will execute an infinite loop function
- * and will wait for a job to enter the job queue. Once a job is in the the queue
- * the threads will wake up to acquire and execute it.
- */
- mWorkers.push_back( std::unique_ptr< WorkerThread >( new WorkerThread( i ) ) );
- }
-
- return true;
-}
-
-
-void ThreadPool::Wait()
-{
- for( auto& worker : mWorkers )
- {
- worker->Wait();
- }
-}
-
-std::shared_ptr< Future< void > > ThreadPool::SubmitTask( uint32_t workerIndex, const Task& task )
-{
- auto future = std::shared_ptr< Future< void > >( new Future< void > );
- mWorkers[workerIndex]->AddTask( [task, future]( uint32_t index )
- {
- task( index );
-
- future->mPromise.set_value();
- });
-
- return future;
-}
-
-std::shared_ptr< Future< void > > ThreadPool::SubmitTasks( const std::vector< Task >& tasks )
-{
- auto future = std::shared_ptr< Future< void > >( new Future< void > );
- mWorkers[ sWorkerIndex++ % static_cast< uint32_t >( mWorkers.size() )]->AddTask(
- [ future, tasks ]( uint32_t index ) {
- for( auto& task : tasks )
- {
- task( index );
- }
-
- future->mPromise.set_value();
-
- } );
-
- return future;
-}
-
-size_t ThreadPool::GetWorkerCount() const
-{
- return mWorkers.size();
-}
-
-} //namespace Graphics
-
-} //namespace Dali
+++ /dev/null
-#ifndef DALI_GRAPHICS_THREAD_POOL_H
-#define DALI_GRAPHICS_THREAD_POOL_H
-
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <thread>
-#include <functional>
-#include <mutex>
-#include <queue>
-#include <condition_variable>
-#include <future>
-#include <algorithm>
-#include <iostream>
-
-namespace Dali
-{
-namespace Graphics
-{
-
-using Task = std::function< void(uint32_t) >;
-
-using TaskQueue = std::queue< Task >;
-
-template< typename T >
-class Future final
-{
- friend class ThreadPool;
-
-private:
- std::promise< T > mPromise{};
- std::future< T > mFuture{};
-
-public:
-
- Future()
- {
- mFuture = mPromise.get_future();
- }
-
- ~Future()
- {
- Wait();
- }
-
- T Get() const
- {
- return mFuture.get();
- }
-
- void Wait() const
- {
- if( IsValid() )
- {
- mFuture.wait();
- }
- }
-
- bool IsValid() const
- {
- return mFuture.valid();
- }
-
- void Reset()
- {
- mPromise = std::promise< T >();
- mFuture = mPromise.get_future();
- }
-};
-
-template< typename T >
-class FutureGroup final
-{
- friend class ThreadPool;
-
-private:
- std::vector< std::unique_ptr< Future< T > > > mFutures;
-
-public:
-
- void Wait()
- {
- for( auto& future : mFutures )
- {
- future->Wait();
- }
- }
-
-};
-
-class WorkerThread
-{
-private:
- std::thread mWorker;
-
- uint32_t mIndex;
-
- TaskQueue mTaskQueue;
-
- std::mutex mTaskQueueMutex;
-
- std::condition_variable mConditionVariable;
-
- bool mTerminating{ false };
-
- void WaitAndExecute();
-
-public:
- WorkerThread(uint32_t index);
-
- WorkerThread( const WorkerThread& other ) = delete;
-
- WorkerThread& operator=( const WorkerThread& other ) = delete;
-
- ~WorkerThread();
-
- void AddTask( Task task );
-
- void Wait();
-};
-
-class ThreadPool
-{
-private:
- std::vector< std::unique_ptr< WorkerThread>> mWorkers;
-
- static uint32_t sWorkerIndex;
-
-public:
- bool Initialize();
-
- void Wait();
-
- template< typename ReturnT >
- std::shared_ptr< Future< ReturnT > > SubmitTask( uint32_t workerIndex, std::function< ReturnT(uint32_t) > task )
- {
- auto future = std::shared_ptr< Future< ReturnT > >( new Future< ReturnT > );
- mWorkers[workerIndex]->AddTask( [ task, future ](uint32_t index) {
- auto res = task( index );
- future->mPromise.set_value( res );
- } );
-
- return future;
- }
-
-
- std::shared_ptr< Future< void > > SubmitTask( uint32_t workerIndex, const Task& task );
-
- template< typename ReturnT >
- std::shared_ptr< Future< void > > SubmitTask( std::function< ReturnT(uint32_t) > task )
- {
- return SubmitTask( sWorkerIndex++ % static_cast< uint32_t >( mWorkers.size() ), std::move( task ) );
- }
-
- std::shared_ptr< Future< void > > SubmitTasks( const std::vector< Task >& tasks );
-
- template< typename T, typename Predicate >
- std::shared_ptr< FutureGroup< void > >
- ParallelProcess( std::vector< T >& data, Predicate predicate, bool useMainThread )
- {
- auto workerCount = useMainThread ? mWorkers.size() + 1 : mWorkers.size();
- auto tasksPerThread = data.size() / workerCount;
-
- if (tasksPerThread == 0 ) tasksPerThread = data.size();
-
- auto batches = useMainThread ? (data.size() / tasksPerThread) - 1 : data.size() / tasksPerThread;
-
- auto start = 0ul;
- auto end = 0ul;
-
- auto futureGroup = std::shared_ptr< FutureGroup< void > >( new FutureGroup< void > );
-
- for( auto i = 0u; i < batches; ++i )
- {
- futureGroup->mFutures.emplace_back( new Future< void >() );
- }
-
- for( auto i = 0u; i < batches; ++i )
- {
- if ( end == data.size() )
- {
- break;
- }
-
- if( !useMainThread )
- {
- end = ( i == batches - 1 ) ? start + tasksPerThread + ( data.size() - batches * tasksPerThread ) :
- start + tasksPerThread;
- }
- else
- {
- end = start + tasksPerThread;
- }
-
- auto task = Task(
- [ futureGroup, i, start, end, predicate, &data ](uint32_t index)
- {
- auto sIt = data.begin() + static_cast<int>(start);
- auto eIt = data.begin() + static_cast<int>(end);
- std::for_each( sIt, eIt, predicate );
-
- futureGroup->mFutures[i]->mPromise.set_value();
- } );
-
- mWorkers[sWorkerIndex++ % static_cast< uint32_t >( mWorkers.size() )]->AddTask( task );
-
- start = end;
- }
-
- if( useMainThread )
- {
- end = start + tasksPerThread + ( data.size() - (++batches) * tasksPerThread );
-
- auto sIt = data.begin() + static_cast<int>(start);
- auto eIt = data.begin() + static_cast<int>(end);
- std::for_each( sIt, eIt, predicate );
- }
-
- return futureGroup;
- }
-
- template< typename T, typename Predicate >
- std::shared_ptr< FutureGroup< void > >
- IndexedParallelProcess( std::vector< T >& data, Predicate predicate, bool useMainThread )
- {
- auto workerCount = useMainThread ? mWorkers.size() + 1 : mWorkers.size();
- auto tasksPerThread = data.size() / workerCount;
-
- if (tasksPerThread == 0 )
- {
- tasksPerThread = data.size();
- }
-
- auto batches = useMainThread ? (data.size() / tasksPerThread) - 1 : data.size() / tasksPerThread;
-
- auto start = 0ul;
- auto end = 0ul;
-
- auto futureGroup = std::shared_ptr< FutureGroup< void > >( new FutureGroup< void > );
-
- for( auto i = 0u; i < batches; ++i )
- {
- futureGroup->mFutures.emplace_back( new Future< void >() );
- }
-
- for( auto i = 0u; i < batches; ++i )
- {
- if ( end == data.size() )
- {
- break;
- }
-
- if( !useMainThread )
- {
- end = ( i == batches - 1 ) ? start + tasksPerThread + ( data.size() - batches * tasksPerThread ) :
- start + tasksPerThread;
- }
- else
- {
- end = start + tasksPerThread;
- }
-
- auto task = Task(
- [ futureGroup, i, start, end, predicate, &data ](uint32_t index)
- {
- auto sIt = data.begin() + static_cast<int>(start);
- auto eIt = data.begin() + static_cast<int>(end);
- std::for_each( sIt, eIt, std::bind( predicate, std::placeholders::_1, index ) );
-
- futureGroup->mFutures[i]->mPromise.set_value();
- } );
-
- mWorkers[sWorkerIndex++ % static_cast< uint32_t >( mWorkers.size() )]->AddTask( task );
-
- start = end;
- }
-
- if( useMainThread )
- {
- end = start + tasksPerThread + ( data.size() - (++batches) * tasksPerThread );
-
- auto sIt = data.begin() + static_cast<int>(start);
- auto eIt = data.begin() + static_cast<int>(end);
- std::for_each( sIt, eIt, std::bind( predicate,
- std::placeholders::_1,
- mWorkers.size() /* the main thread will be the last index */ ) );
- }
-
- return futureGroup;
- }
-
- size_t GetWorkerCount() const;
- };
-
-
-} //namespace Graphics
-
-} //namespace Dali
-
-#endif //DALI_GRAPHICS_THREAD_POOL_H
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#if defined(DEBUG_ENABLED)
-
-// INTERNAL INCLUDES
-#include <dali/graphics-api/graphics-api-render-command.h>
-#include <dali/graphics/vulkan/api/vulkan-api-buffer.h>
-#include <dali/graphics/vulkan/api/vulkan-api-texture.h>
-#include <dali/graphics/vulkan/internal/vulkan-buffer.h>
-#include <dali/graphics/vulkan/internal/vulkan-image.h>
-#include <dali/graphics/vulkan/internal/vulkan-image-view.h>
-#include <dali/graphics/vulkan/internal/vulkan-sampler.h>
-
-// EXTERNAL INCLUDES
-#include <sstream>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace API
-{
-
-std::string APItoVK( const Buffer* buffer)
-{
- std::stringstream ss;
- if(!buffer)
- {
- ss << "{ nullptr }" << std::endl;
- return ss.str();
- }
- const auto& vbuffer = static_cast<const VulkanAPI::Buffer&>(*buffer);
- auto vbufferref = vbuffer.GetBufferRef();
- auto vkBuffer = vbufferref->GetVkHandle();
-
- ss << "VulkanAPI::Buffer(" << &vbuffer << ") {" << std::endl;
- ss << " vk::Buffer = " << static_cast<VkBuffer>(vkBuffer) << std::endl;
- ss << " }";
- return ss.str();
-}
-
-std::string APItoVK( const Texture* texture)
-{
- std::stringstream ss;
- if(!texture)
- {
- ss << "{ nullptr }" << std::endl;
- return ss.str();
- }
- const auto& apiTexture = static_cast<const VulkanAPI::Texture&>(*texture);
-
- auto imageRef = apiTexture.GetImageRef();
- auto imageViewRef = apiTexture.GetImageViewRef();
- auto samplerRef = apiTexture.GetSamplerRef();
-
- ss << "VulkanAPI::Texture(" << &apiTexture << ") {" << std::endl;
- ss << " vk::Image = " << static_cast<VkImage>(imageRef->GetVkHandle()) << std::endl;
- ss << " vk::ImageView = " << static_cast<VkImageView>( imageViewRef->GetVkHandle() ) << std::endl;
- ss << " vk::Sampler = " << static_cast<VkSampler>(samplerRef->GetVkHandle()) << std::endl;
- //@ todo: add gpu memory block info too
- ss << " }";
- return ss.str();
-}
-
-std::ostream& operator<<(std::ostream& ss, const RenderCommand::UniformBufferBinding& object)
-{
- ss << " UniformBufferBinding = " << &object << " { " << std::endl;
- ss << " buffer = " << APItoVK(object.buffer) << std::endl;
- ss << " dataSize = " << object.dataSize << std::endl;
- ss << " offset = " << object.offset << std::endl;
- ss << " binding = " << object.binding << std::endl;
- ss << " }" << std::endl;
- return ss;
-}
-
-std::ostream& operator<<(std::ostream& ss, const RenderCommand::TextureBinding& object)
-{
- ss << " TextureBinding = " << &object << " { " << std::endl;
- ss << " texture = " << APItoVK(object.texture) << std::endl;
- ss << " sampler = " << object.sampler << std::endl;
- ss << " binding = " << object.binding << std::endl;
- ss << " }" << std::endl;
- return ss;
-}
-
-std::ostream& operator<<(std::ostream& ss, const RenderCommand::SamplerBinding& object)
-{
- ss << " SamplerBinding = " << &object << " { " << std::endl;
- ss << " sampler = " << object.sampler << std::endl;
- ss << " binding = " << object.binding << std::endl;
- ss << " }" << std::endl;
- return ss;
-}
-
-std::ostream& operator<<(std::ostream& ss, const RenderCommand::IndexBufferBinding& object)
-{
- ss << " IndexBufferBinding = { " << std::endl;
- ss << " buffer = " << APItoVK( object.buffer ) << std::endl;
- ss << " offset = " << object.offset << std::endl;
- ss << " type = " << std::function<std::string()>([&object]() -> std::string {
- switch(object.type)
- {
- case RenderCommand::IndexType::INDEX_TYPE_UINT16:
- return std::string("INDEX_TYPE_UINT16");
- case RenderCommand::IndexType::INDEX_TYPE_UINT32:
- return std::string("INDEX_TYPE_UINT32");
- }
- return "";
- })() << std::endl;
- ss << " }" << std::endl;
- return ss;
-}
-
-std::ostream& operator<<(std::ostream& ss, const RenderCommand::RenderTargetBinding& object)
-{
- ss << " RenderTargetBinding = " << &object << " { " << std::endl;
- ss << " framebuffer = " << object.framebuffer << std::endl;
- ss << " clearColors = " << std::function<std::string()>([&object]() -> std::string {
- if( object.clearColors.empty() )
- {
- return " = nullptr\n";
- }
- std::stringstream s;
- for( auto i = 0u; i < object.clearColors.size(); ++i )
- {
- s << " [" << i << "] = \n" <<
- " clearColors.r = " << object.clearColors[i].r << "\n" <<
- " clearColors.g = " << object.clearColors[i].g << "\n" <<
- " clearColors.b = " << object.clearColors[i].b << "\n" <<
- " clearColors.a = " << object.clearColors[i].a << "\n";
- }
- return s.str();
- })() << std::endl;
- ss << " dsClearColor = [ d = " << object.depthStencilClearColor.depth <<
- ", s = " << object.depthStencilClearColor.stencil << "]\n";
- ss << " }" << std::endl;
- return ss;
-}
-
-std::ostream& operator<<(std::ostream& ss, const RenderCommand::DrawCommand& object)
-{
- ss << " DrawCommand = " << &object << " { " << std::endl;
- ss << " drawType = " << std::function<std::string()>([&object]() -> std::string {
- switch(object.drawType)
- {
- case RenderCommand::DrawType::INDEXED_DRAW:
- return std::string("INDEXED_DRAW");
- case RenderCommand::DrawType::VERTEX_DRAW:
- return std::string("VERTEX_DRAW");
- case RenderCommand::DrawType::UNDEFINED_DRAW:
- return std::string("UNDEFINED_DRAW");
- }
- return "";
- })() << std::endl;
- ss << " union {\n";
- ss << " firstVertex = " << object.firstVertex << std::endl;
- ss << " firstIndex = " << object.firstIndex << std::endl;;
- ss << " }\n";
- ss << " union {\n";
- ss << " vertexCount = " << object.vertexCount << std::endl;
- ss << " indicesCount = " << object.indicesCount << std::endl;;
- ss << " }\n";
- ss << " firstInstance = " << object.firstInstance << std::endl;
- ss << " instanceCount = " << object.instanceCount << std::endl;
- ss << " }" << std::endl;
- return ss;
-}
-
-std::ostream& operator<<(std::ostream& ss, const RenderCommand::PushConstantsBinding& object)
-{
- ss << " PushConstantsBinding = " << &object << " { " << std::endl;
- ss << " data = " << object.data << std::endl;
- ss << " size = " << object.size << std::endl;
- ss << " binding = " << object.binding << std::endl;
- ss << " }" << std::endl;
- return ss;
-}
-
-std::ostream& operator<<(std::ostream& ss, const RenderCommand& object)
-{
- ss << "RenderCommand {\n";
- ss << " mDebugString = " << object.mDebugString << std::endl;
- ss << " mDebugObject = " << object.mDebugObject << std::endl;
- ss << " mVertexBufferBindings = " << std::endl;
- for( auto i = 0u; i < object.mVertexBufferBindings.size(); ++i )
- {
- ss << " " << APItoVK(object.mVertexBufferBindings[i]) << std::endl;
- }
- ss << " }\n" << std::endl;
-
- if(object.mUniformBufferBindings)
- {
- ss << " mUniformBufferBindings = {" << std::endl;
- for( auto i = 0u; i < object.mUniformBufferBindings->size(); ++i )
- {
- ss << (*object.mUniformBufferBindings)[i] << std::endl;
- }
- ss << " }\n" << std::endl;
- }
-
- if( object.mTextureBindings )
- {
- ss << " mTextureBindings {" << std::endl;
- for( auto i = 0u; i < object.mTextureBindings->size(); ++i )
- {
- ss << (*object.mTextureBindings)[i] << std::endl;
- }
- ss << " }\n" << std::endl;
- }
-
- ss << " mSamplerBindings {" << std::endl;
- for( auto i = 0u; i < object.mSamplerBindings.size(); ++i )
- {
- ss << object.mSamplerBindings[i] << std::endl;
- }
- ss << " }\n" << std::endl;
-
- ss << " mPushConstantsBindings {" << std::endl;
- for( auto i = 0u; i < object.mPushConstantsBindings.size(); ++i )
- {
- ss << object.mPushConstantsBindings[i] << std::endl;
- }
- ss << " }\n" << std::endl;
-
- ss << " mIndexBufferBinding {" << std::endl;
- ss << object.mIndexBufferBinding << std::endl;
- ss << " }\n" << std::endl;
-
- ss << " mDrawCommand {" << std::endl;
- ss << object.mDrawCommand << std::endl;
- ss << " }" << std::endl;
- ss << "}" << std::endl;
-
- return ss;
-}
-
-}
-}
-}
-
-#endif
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics/vulkan/api/internal/vulkan-api-descriptor-set-allocator.h>
-#include <dali/graphics/vulkan/api/vulkan-api-controller.h>
-#include <dali/graphics/vulkan/internal/vulkan-debug-allocator.h>
-#include <dali/graphics/vulkan/internal/vulkan-debug.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace VulkanAPI
-{
-namespace Internal
-{
-static const uint32_t DESCRIPTOR_SET_MAX_MULTIPLIER ( 3u );
-
-DescriptorSetAllocator::DescriptorSetAllocator( VulkanAPI::Controller& controller )
-: mController( controller )
-{
-}
-
-DescriptorSetAllocator::~DescriptorSetAllocator()
-{
- // destroy all pools
- std::for_each( mPoolSet.begin(), mPoolSet.end(),[&]( auto& poolset )
- {
- std::for_each( poolset.begin(), poolset.end(), [&]( Pool& pool )
- {
- if( pool.vkPool )
- {
- auto& graphics = mController.GetGraphics();
-
- graphics.GetDevice().freeDescriptorSets( pool.vkPool, pool.vkDescriptorSets );
-
- // destroy each pool
- graphics.GetDevice().destroyDescriptorPool( pool.vkPool, &graphics.GetAllocator() );
- }
- });
- });
-}
-
-void DescriptorSetAllocator::ResolveFreeDescriptorSets()
-{
- auto& graphics = mController.GetGraphics();
-
- const auto bufferIndex = mController.GetCurrentBufferIndex();
- for( auto& pool : mPoolSet[bufferIndex] )
- {
- if( !pool.vkDescriptorSetsToBeFreed.empty() )
- {
- // free unused descriptor sets
- std::vector<vk::DescriptorSet> existingDSToFree;
-
- std::vector<vk::DescriptorSet> newList{};
- auto freeIt = pool.vkDescriptorSetsToBeFreed.begin();
- auto freeEnd = pool.vkDescriptorSetsToBeFreed.end();
- std::for_each(pool.vkDescriptorSets.begin(), pool.vkDescriptorSets.end(), [&](auto &item)
- {
- if( freeIt == pool.vkDescriptorSetsToBeFreed.end()) // no more items to free, just write remaining items
- {
- newList.emplace_back(item);
- }
- else
- {
- auto leftItem = static_cast<VkDescriptorSet>(*freeIt);
- auto rightItem = static_cast<VkDescriptorSet>(item);
- while( freeIt < freeEnd && leftItem < rightItem )
- {
- ++freeIt;
- }
-
- // not reached end yet
- if( freeIt < freeEnd )
- {
- if( leftItem == rightItem )
- {
- existingDSToFree.emplace_back(item);
- ++freeIt;
- }
- else
- {
- newList.emplace_back(item);
- }
- }
- }
- });
-
- if( !existingDSToFree.empty())
- {
- graphics.GetDevice().freeDescriptorSets( pool.vkPool, existingDSToFree );
- }
-
- pool.vkDescriptorSets = std::move( newList );
-
- // update available number of descriptor
- pool.available += uint32_t( existingDSToFree.size() );
-
- // clear the free list
- pool.vkDescriptorSetsToBeFreed.clear();
- }
- }
-}
-
-bool DescriptorSetAllocator::ValidateDescriptorSetList( const DescriptorSetList& list )
-{
- for( auto& pool : mPoolSet[list.reserved->bufferIndex] )
- {
- if( list.reserved->poolUID == pool.uid )
- {
- return true;
- }
- }
- return false;
-}
-
-bool DescriptorSetAllocator::TestIfValid( const DescriptorSetList& list, std::vector<bool>& results ) const
-{
- auto retval = true;
- std::for_each( list.descriptorSets.begin(), list.descriptorSets.end(), [&]( auto& testDs )
- {
- int poolIndex = -1;
- if( (poolIndex = this->GetPoolIndexBySignature( list.reserved->signature, list.reserved->bufferIndex ) ) > -1 )
- {
- auto& pool = mPoolSet[list.reserved->bufferIndex][uint32_t(poolIndex)];
- auto it = std::find_if( pool.vkDescriptorSets.begin(), pool.vkDescriptorSets.end(), [&]( auto& ds )
- {
- return ds == testDs;
- });
-
- auto invalid = ( it == pool.vkDescriptorSets.end() );
- if( invalid )
- {
- retval = false;
- }
- results.emplace_back( !invalid );
- }
- });
- return retval;
-}
-
-void DescriptorSetAllocator::UpdateWithRequirements(
- std::vector<DescriptorSetRequirements>& requirements,
- DescriptorSetAllocationFlags flags )
-{
- ResolveFreeDescriptorSets();
-
- const auto bufferIndex = mController.GetCurrentBufferIndex();
-
- // clean pools dirty flags
- for( auto& pool : mPoolSet[mController.GetCurrentBufferIndex()] )
- {
- pool.dirty = false;
- }
-
- auto& poolset = mPoolSet[bufferIndex];
-
- // For each signature decide whether we should reallocate pool or not.
- // Newly created pool always reallocates
- // Allocation strategy assumes overallocation using threshold
- for( auto& requirement : requirements )
- {
- auto it = std::find_if( poolset.begin(), poolset.end(), [&]( auto& item )
- {
- return item.signature == requirement.layoutSignature;
- });
-
- // Create new pool with signature
- if( it == poolset.end() )
- {
- poolset.emplace_back( requirement.layoutSignature );
- it = poolset.end()-1;
- (*it).signature = requirement.layoutSignature;
- (*it).shouldReallocate = true;
- (*it).available = 0;
- (*it).uid = ++mPoolUID;
- (*it).maxSets = 0;
- requirement.resultDirty = true;
- }
- else
- {
- (*it).shouldReallocate = false;
- requirement.resultDirty = false;
- }
-
- auto& pool = *it;
-
- pool.requiredDescriptorCount = requirement;
- pool.requiredSets = requirement.maxSets;
-
- if( pool.available < pool.requiredSets )//requirement.notAllocatedSets && requirement.notAllocatedSets > pool.available )
- {
- pool.shouldReallocate = true;
- }
- else
- {
- pool.shouldReallocate = false;
- }
-
- if( !requirement.resultDirty && !pool.shouldReallocate )
- {
- continue;
- }
-
- requirement.resultDirty = pool.shouldReallocate;
- }
-
- for( auto& pool : poolset )
- {
- if( pool.shouldReallocate )
- {
- const std::array<vk::DescriptorType, uint32_t(Vulkan::DescriptorType::DESCRIPTOR_TYPE_COUNT)> VK_DESCRIPTOR_TYPE = {
- vk::DescriptorType::eStorageImage,
- vk::DescriptorType::eSampler,
- vk::DescriptorType::eSampledImage,
- vk::DescriptorType::eCombinedImageSampler,
- vk::DescriptorType::eUniformTexelBuffer,
- vk::DescriptorType::eStorageTexelBuffer,
- vk::DescriptorType::eUniformBuffer,
- vk::DescriptorType::eStorageBuffer,
- vk::DescriptorType::eUniformBufferDynamic,
- vk::DescriptorType::eStorageBufferDynamic,
- vk::DescriptorType::eInputAttachment
- };
-
- // prepare pool sizes for the new pool before replacing old pool
- std::vector<vk::DescriptorPoolSize> sizes;
-
- for( auto i = 0u; i < uint32_t( Vulkan::DescriptorType::DESCRIPTOR_TYPE_COUNT ); ++i )
- {
- if( pool.requiredDescriptorCount.requirements[i] )
- {
- sizes.emplace_back( VK_DESCRIPTOR_TYPE[i], pool.requiredDescriptorCount.requirements[i] * DESCRIPTOR_SET_MAX_MULTIPLIER );
- }
- }
-
- vk::DescriptorPoolCreateInfo createInfo;
- createInfo.setMaxSets( pool.requiredSets * DESCRIPTOR_SET_MAX_MULTIPLIER );
- createInfo.setPPoolSizes( sizes.data() );
- createInfo.setPoolSizeCount( uint32_t(sizes.size()) );
- createInfo.setFlags( vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet );
-
- auto& graphics = mController.GetGraphics();
-
- auto newPool = graphics.GetDevice().createDescriptorPool( createInfo, graphics.GetAllocator( "DescriptorPool" ) ).value;
-
- // Update current pool
- pool.maxDescriptorCount = std::move( pool.requiredDescriptorCount );
- pool.maxSets = pool.requiredSets * DESCRIPTOR_SET_MAX_MULTIPLIER;
-
- auto device = graphics.GetDevice();
- auto pGraphics = &graphics;
- auto oldPool = pool.vkPool;
-
- if( oldPool )
- {
- if( !pool.vkDescriptorSets.empty() )
- {
- graphics.GetDevice().freeDescriptorSets( pool.vkPool, pool.vkDescriptorSets );
- }
-
- // clear the free list
- pool.vkDescriptorSetsToBeFreed.clear();
-
- device.destroyDescriptorPool( oldPool, pGraphics->GetAllocator( "DESCRIPTORPOOL" ) );
- }
-
- ++mPoolUID;
-
- // replace pool
- pool.vkPool = newPool;
- pool.dirty = true;
- pool.vkDescriptorSets = {};
- pool.available = pool.maxSets;
-
- pool.uid = mPoolUID;
- }
- }
-}
-
-
-bool DescriptorSetAllocator::AllocateDescriptorSets(
- const std::vector<Dali::Graphics::Vulkan::DescriptorSetLayoutSignature>& signatures,
- const std::vector<vk::DescriptorSetLayout>& layouts,
- DescriptorSetList& descriptorSets )
-{
- // access correct pool
- auto& poolset = mPoolSet[mController.GetCurrentBufferIndex()];
-
- auto& retval = descriptorSets.descriptorSets;
-
- // For each signature look for the right pool
- for( auto& signature : signatures )
- {
- auto it = std::find_if( poolset.begin(), poolset.end(), [&]( auto& item ){
- return item.signature == signature;
- });
-
- // Assert if pool hasn't been found. It should never happen if
- // pools have been updated with correct requirements before allocation requests.
- assert( (it != poolset.end()) && "No pool found for signature. Did UpdateWithRequirements() run with correct requirements?" );
-
- // Check if descriptor sets are already allocated and if pool is dirty.
- // Continue to the next signature if pool hasn't changed and there are already
- // existing sets allocated for the render command
- if( !(*it).dirty && !descriptorSets.descriptorSets.empty() )
- {
- continue;
- }
-
- vk::DescriptorSetAllocateInfo allocateInfo{};
- allocateInfo.setDescriptorSetCount( uint32_t( signatures.size() ) );
- allocateInfo.setDescriptorPool( (*it).vkPool );
- allocateInfo.setPSetLayouts( layouts.data() );
-
- auto& graphics = mController.GetGraphics();
- std::vector<vk::DescriptorSet> result;
- result.resize( allocateInfo.descriptorSetCount );
-
- auto err = graphics.GetDevice().allocateDescriptorSets( &allocateInfo, result.data() );
-
- assert( (err == vk::Result::eSuccess) && "Can't allocate descriptor sets!" );
-
- // reset book-keeping data
- (*it).available -= uint32_t( result.size() );
- descriptorSets.reserved.reset( new DescriptorSetList::Internal() );
- descriptorSets.reserved->pool = (*it).vkPool;
- descriptorSets.reserved->bufferIndex = mController.GetCurrentBufferIndex();
- descriptorSets.reserved->signature = (*it).signature;
- descriptorSets.reserved->poolUID = (*it).uid;
-
- // track descriptor sets
- if( result.size() > 1 )
- {
- (*it).vkDescriptorSets.insert( (*it).vkDescriptorSets.end(), result.begin(), result.end() );
- }
- else
- {
- (*it).vkDescriptorSets.emplace_back( result[0] );
- }
- retval = std::move( result );
-
- // sort for faster lookup
- std::sort( (*it).vkDescriptorSets.begin(), (*it).vkDescriptorSets.end() );
-
- return true;
- }
-
- return false;
-}
-
-int32_t DescriptorSetAllocator::GetPoolIndexBySignature( Vulkan::DescriptorSetLayoutSignature signature, uint32_t bufferIndex ) const
-{
- int32_t retval = {0u};
- for( auto& item : mPoolSet[bufferIndex] )
- {
- if( item.signature == signature )
- {
- return retval;
- }
- ++retval;
- }
- return -1;
-}
-
-void DescriptorSetAllocator::FreeDescriptorSets( std::vector<DescriptorSetList>&& descriptorSets )
-{
- // build free lists
- for( auto& list : descriptorSets )
- {
- auto bufferIndex = list.reserved->bufferIndex;
- std::find_if( mPoolSet[bufferIndex].begin(), mPoolSet[bufferIndex].end(), [&]( Pool& pool )
- {
- if( pool.uid == list.reserved->poolUID && pool.vkPool == list.reserved->pool )
- {
- pool.vkDescriptorSetsToBeFreed.insert( pool.vkDescriptorSetsToBeFreed.end(), list.descriptorSets.begin(), list.descriptorSets.end() );
- return true;
- }
- return false;
- });
- }
-}
-
-void DescriptorSetAllocator::InvalidateAllDescriptorSets()
-{
- auto& graphics = mController.GetGraphics();
- graphics.DeviceWaitIdle();
- for( auto& pool : mPoolSet[mController.GetCurrentBufferIndex()] )
- {
- graphics.GetDevice().destroyDescriptorPool(
- pool.vkPool,
- &mController.GetGraphics().GetAllocator("DESCRIPTORPOOL") );
- }
- mPoolSet[mController.GetCurrentBufferIndex()].clear();
-}
-
-} // Namespace Internal
-
-} // Namespace VulkanAPI
-
-} // Namespace Graphics
-
-} // Namespace Vulkan
\ No newline at end of file
+++ /dev/null
-#ifndef DALI_GRAPHICS_VULKAN_API_DESCRIPTORSETALLOCATOR
-#define DALI_GRAPHICS_VULKAN_API_DESCRIPTORSETALLOCATOR
-
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics/vulkan/vulkan-graphics.h>
-#include <dali/graphics/vulkan/api/internal/vulkan-api-descriptor-set-requirements.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-class Graphics;
-}
-
-namespace VulkanAPI
-{
-class Controller;
-
-namespace Internal
-{
-using DescriptorSetAllocationFlags = uint32_t;
-
-/**
- * Descriptor pools allocator
- *
- * The class provides resizeable descriptor pools per swapchain image.
- * The allocator must be updated with set of requirements in order to compute
- * how much memory should be allocated for the descriptor pool. If current
- * requirements fit pool size then pool stays unchanged. Otherwise, it will
- * be resized. There is always one pool for each descriptor set layout signature
- * per swapchain image.
- *
- * Descriptor set layout signature is similar to the descriptor set layout but
- * it doesn't store bindings. The descriptor set layout must be provided
- * in order to successfully allocate sets for the render command.
- *
- * Resizing involves creating new pool and immediately destroying old one.
- *
- * Descriptor sets allocated by render commands may become invalid due to
- * pool reallocation. The allocator allows to test whether descriptor sets
- * are still valid or new sets must be allocated.
- *
- * Update of the allocator is done for whole frame. It means all renderable data
- * must update the requirements before calling UpdateWithRequirements(). Update
- * must not run more than once per frame.
- */
-class DescriptorSetAllocator
-{
-public:
- /**
- * Class constructor
- *
- * @param[in] controller reference to the Controller object
- */
- DescriptorSetAllocator( VulkanAPI::Controller& controller );
-
- /**
- * Class destructor
- */
- ~DescriptorSetAllocator();
-
-public:
-
- /**
- * Updates allocator with given allocation requirements. This function should run
- * once per frame.
-
- * @param[in,out] Requirements List of requirements
- * @param[in] flags Allocation flags, currently not used
- */
- void UpdateWithRequirements( std::vector<DescriptorSetRequirements>& requirements, DescriptorSetAllocationFlags flags );
-
- /**
- * Allocates descriptor sets for specified layouts and signatures
- *
- * @param[in] signatures List of signatures
- * @param[in] layouts List of layouts
- * @param[out] descriptorSets Returned descriptor sets
- * @return true on success
- */
- bool AllocateDescriptorSets( const std::vector<Dali::Graphics::Vulkan::DescriptorSetLayoutSignature>& signatures,
- const std::vector<vk::DescriptorSetLayout>& layouts,
- DescriptorSetList& descriptorSets );
-
- /**
- * This function takes r-value only as parameter invalidating input
- * @param descriptorSets
- */
- void FreeDescriptorSets( std::vector<DescriptorSetList>&& descriptorSets );
-
- /**
- * Invalidates and releases all descriptor sets forcing recreating pools. This may happen
- * due to DALi staying in idle state.
- */
- void InvalidateAllDescriptorSets();
-
- /**
- * Tests whether DescriptorSetList object is still valid ( for example, the pool
- * it was allocated from still exists ).
- *
- * @param[in] list List containing descriptor sets
- * @param[out] results Output results ( one per each descriptor set )
- * @return True if all valid, false otherwise
- */
- bool TestIfValid( const DescriptorSetList& list, std::vector<bool>& results ) const;
-
- /**
- * Validates whether pools used by the list is still valid
- * This function is faster than TestIfValid()
- * @param list List of descriptor sets
- * @return True if pool is still valid
- */
- bool ValidateDescriptorSetList( const DescriptorSetList& list );
-
-private:
-
- /**
- * Resolves which descriptor sets should be freed
- */
- void ResolveFreeDescriptorSets();
-
- /**
- * Helper function returning index of Pool within Poolset for given signature and buffer index
- * @param[in] signature Layout signature
- * @param[in] bufferIndex update buffer index
- * @return Valid index or -1 if failed
- */
- int32_t GetPoolIndexBySignature( Vulkan::DescriptorSetLayoutSignature signature, uint32_t bufferIndex ) const;
-
- /**
- * Structure wrapping single descriptor pool
- */
- struct Pool
- {
- Pool( Vulkan::DescriptorSetLayoutSignature newSignature )
- : signature( newSignature ){}
- Vulkan::DescriptorSetLayoutSignature signature {};
- vk::DescriptorPool vkPool { nullptr};
-
- // Current capacity of the pool
- uint32_t maxSets { 0 };
- DescriptorSetRequirements maxDescriptorCount {};
-
- // Requested capacity of pool, used when 'shouldReallocate' is True
- uint32_t requiredSets { 0 };
- DescriptorSetRequirements requiredDescriptorCount {};
-
- // Preallocated descriptor sets
- std::vector<vk::DescriptorSet> vkDescriptorSets{ };
-
- uint32_t available { 0u };
- bool shouldReallocate { true };
- bool shouldDiscard { false };
-
- std::vector<vk::DescriptorSet> vkDescriptorSetsToBeFreed {};
-
- bool dirty { false };
- uint32_t uid { 0u };
- };
-
- VulkanAPI::Controller& mController;
-
- using PoolSet = std::vector<Pool>;
- std::array<PoolSet, 2u> mPoolSet;
-
- uint32_t mPoolUID { 0u };
-};
-
-} // Namespace Internal
-
-} // Namespace VulkanAPI
-} // Namespace Graphics
-} // Namespace Dali
-
-#endif // DALI_GRAPHICS_VULKAN_API_DESCRIPTORSETALLOCATOR
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics/vulkan/api/internal/vulkan-api-descriptor-set-requirements.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace VulkanAPI
-{
-
-DescriptorSetList::operator const vk::DescriptorSet*() const
-{
- return descriptorSets.data();
-}
-
-DescriptorSetList::operator const std::vector<vk::DescriptorSet>&() const
-{
- return descriptorSets;
-}
-
-}
-}
-}
+++ /dev/null
-#ifndef DALI_GRAPHICS_VULKAN_API_DESCRIPTORSETREQUIREMENTS
-#define DALI_GRAPHICS_VULKAN_API_DESCRIPTORSETREQUIREMENTS
-
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics/vulkan/vulkan-graphics.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace VulkanAPI
-{
-
-/**
- * Describes requirements of descriptor set allocation
- */
-using DescriptorTypeRequirements = std::array<uint32_t, static_cast<uint32_t>(Vulkan::DescriptorType::DESCRIPTOR_TYPE_COUNT)>;
-struct DescriptorSetRequirements
-{
- Vulkan::DescriptorSetLayoutSignature layoutSignature {};
- DescriptorTypeRequirements requirements {};
- uint32_t maxSets { 0u };
- uint32_t notAllocatedSets { 0u }; // number of sets to be allocated
- bool resultDirty { false }; // output flag, set when descriptorsets must be reallocated
-};
-
-namespace Internal
-{
-class DescriptorSetAllocator;
-}
-
-struct DescriptorSetList
-{
-public:
-
- friend class Internal::DescriptorSetAllocator;
-
- DescriptorSetList() = default;
- ~DescriptorSetList() = default;
- operator const vk::DescriptorSet*() const;
- operator const std::vector<vk::DescriptorSet>&() const;
-
- std::vector<vk::DescriptorSet> descriptorSets;
-
- // only moveable
- DescriptorSetList( const DescriptorSetList& ) = delete;
- DescriptorSetList& operator=( const DescriptorSetList& ) = delete;
- DescriptorSetList( DescriptorSetList&& ) = default;
- DescriptorSetList& operator=( DescriptorSetList&& ) = default;
-
-private:
-
- struct Internal
- {
- Internal() = default;
- ~Internal() = default;
- vk::DescriptorPool pool {};
- uint32_t bufferIndex {};
- Vulkan::DescriptorSetLayoutSignature signature {};
- uint32_t poolUID{ 0u }; // used to identify pools, always incrementing
- };
-
- std::unique_ptr<Internal> reserved; // reserved for internal book-keeping
-};
-
-} // Namespace VulkanAPI
-} // Namespace Graphics
-} // Namespace Dali
-
-#endif // DALI_GRAPHICS_VULKAN_API_DESCRIPTORSETREQUIREMENTS
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics/vulkan/api/internal/vulkan-pipeline-cache.h>
-#include <dali/graphics/vulkan/api/internal/vulkan-api-pipeline-impl.h>
-#include <dali/graphics/vulkan/api/vulkan-api-pipeline-factory.h>
-#include <dali/graphics/vulkan/api/vulkan-api-pipeline.h>
-#include <dali/graphics/vulkan/api/vulkan-api-controller.h>
-#include <dali/graphics/vulkan/internal/spirv/vulkan-spirv.h>
-#include <dali/graphics/vulkan/internal/vulkan-shader.h>
-#include <dali/graphics/vulkan/internal/vulkan-command-buffer.h>
-#include <dali/graphics/vulkan/internal/vulkan-swapchain.h>
-#include <dali/graphics/vulkan/vulkan-graphics.h>
-#include <dali/graphics/vulkan/internal/vulkan-framebuffer.h>
-
-#include <dali/graphics/vulkan/api/vulkan-api-shader.h>
-
-#include <array>
-#include <dali/graphics/vulkan/api/vulkan-api-framebuffer.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace VulkanAPI
-{
-namespace Internal
-{
-using Vulkan::VkAssert;
-namespace
-{
-constexpr vk::BlendOp ConvertBlendOp( Dali::Graphics::API::BlendOp blendOp )
-{
- switch( blendOp )
- {
- case API::BlendOp::ADD:
- return vk::BlendOp::eAdd;
- case API::BlendOp::SUBTRACT:
- return vk::BlendOp::eSubtract;
- case API::BlendOp::REVERSE_SUBTRACT:
- return vk::BlendOp::eReverseSubtract;
- case API::BlendOp::MIN:
- return vk::BlendOp::eMin;
- case API::BlendOp::MAX:
- return vk::BlendOp::eMax;
- }
- return vk::BlendOp{};
-}
-
-constexpr vk::BlendFactor ConvertBlendFactor( Dali::Graphics::API::BlendFactor blendFactor )
-{
- switch( blendFactor )
- {
- case API::BlendFactor::ZERO:
- return vk::BlendFactor::eZero;
- case API::BlendFactor::ONE:
- return vk::BlendFactor::eOne;
- case API::BlendFactor::SRC_COLOR:
- return vk::BlendFactor::eSrcColor;
- case API::BlendFactor::ONE_MINUS_SRC_COLOR:
- return vk::BlendFactor::eOneMinusSrcAlpha;
- case API::BlendFactor::DST_COLOR:
- return vk::BlendFactor::eDstColor;
- case API::BlendFactor::ONE_MINUS_DST_COLOR:
- return vk::BlendFactor::eOneMinusDstColor;
- case API::BlendFactor::SRC_ALPHA:
- return vk::BlendFactor::eSrcAlpha;
- case API::BlendFactor::ONE_MINUS_SRC_ALPHA:
- return vk::BlendFactor::eOneMinusSrcAlpha;
- case API::BlendFactor::DST_ALPHA:
- return vk::BlendFactor::eDstAlpha;
- case API::BlendFactor::ONE_MINUS_DST_ALPHA:
- return vk::BlendFactor::eOneMinusDstAlpha;
- case API::BlendFactor::CONSTANT_COLOR:
- return vk::BlendFactor::eConstantColor;
- case API::BlendFactor::ONE_MINUS_CONSTANT_COLOR:
- return vk::BlendFactor::eOneMinusConstantColor;
- case API::BlendFactor::CONSTANT_ALPHA:
- return vk::BlendFactor::eConstantAlpha;
- case API::BlendFactor::ONE_MINUS_CONSTANT_ALPHA:
- return vk::BlendFactor::eOneMinusConstantAlpha;
- case API::BlendFactor::SRC_ALPHA_SATURATE:
- return vk::BlendFactor::eSrcAlphaSaturate;
- case API::BlendFactor::SRC1_COLOR:
- return vk::BlendFactor::eSrc1Color;
- case API::BlendFactor::ONE_MINUS_SRC1_COLOR:
- return vk::BlendFactor::eOneMinusSrc1Color;
- case API::BlendFactor::SRC1_ALPHA:
- return vk::BlendFactor::eSrc1Alpha;
- case API::BlendFactor::ONE_MINUS_SRC1_ALPHA:
- return vk::BlendFactor::eOneMinusSrc1Alpha;
- }
- return vk::BlendFactor{};
-}
-
-constexpr vk::CompareOp ConvertCompareOp( Dali::Graphics::API::CompareOp compareOp )
-{
- switch( compareOp )
- {
- case API::CompareOp::NEVER:
- return vk::CompareOp::eNever;
- case API::CompareOp::LESS:
- return vk::CompareOp::eLess;
- case API::CompareOp::EQUAL:
- return vk::CompareOp::eEqual;
- case API::CompareOp::LESS_OR_EQUAL:
- return vk::CompareOp::eLessOrEqual;
- case API::CompareOp::GREATER:
- return vk::CompareOp::eGreater;
- case API::CompareOp::NOT_EQUAL:
- return vk::CompareOp::eNotEqual;
- case API::CompareOp::GREATER_OR_EQUAL:
- return vk::CompareOp::eGreaterOrEqual;
- case API::CompareOp::ALWAYS:
- return vk::CompareOp::eAlways;
- }
- return vk::CompareOp{};
-}
-
-constexpr vk::PrimitiveTopology ConvertPrimitiveTopology( Dali::Graphics::API::PrimitiveTopology topology )
-{
- using Dali::Graphics::API::Pipeline;
- switch( topology )
- {
- case API::PrimitiveTopology::POINT_LIST:
- return vk::PrimitiveTopology::ePointList;
- case API::PrimitiveTopology::LINE_LIST:
- return vk::PrimitiveTopology::eLineList;
- case API::PrimitiveTopology::LINE_STRIP:
- return vk::PrimitiveTopology::eLineStrip;
- case API::PrimitiveTopology::TRIANGLE_LIST:
- return vk::PrimitiveTopology::eTriangleList;
- case API::PrimitiveTopology::TRIANGLE_STRIP:
- return vk::PrimitiveTopology::eTriangleStrip;
- case API::PrimitiveTopology::TRIANGLE_FAN:
- return vk::PrimitiveTopology::eTriangleFan;
- }
- return vk::PrimitiveTopology{};
-}
-
-constexpr vk::CullModeFlagBits ConvertCullMode( Dali::Graphics::API::CullMode cullMode )
-{
- switch( cullMode )
- {
- case API::CullMode::NONE:
- return vk::CullModeFlagBits::eNone;
- case API::CullMode::FRONT:
- return vk::CullModeFlagBits::eFront;
- case API::CullMode::BACK:
- return vk::CullModeFlagBits::eBack;
- case API::CullMode::FRONT_AND_BACK:
- return vk::CullModeFlagBits::eFrontAndBack;
- }
- return vk::CullModeFlagBits{};
-}
-
-constexpr vk::PolygonMode ConvertPolygonMode( Dali::Graphics::API::PolygonMode polygonMode )
-{
- switch( polygonMode )
- {
- case API::PolygonMode::FILL:
- return vk::PolygonMode::eFill;
- case API::PolygonMode::LINE:
- return vk::PolygonMode::eLine;
- case API::PolygonMode::POINT:
- return vk::PolygonMode::ePoint;
- }
- return vk::PolygonMode{};
-}
-
-constexpr vk::FrontFace ConvertFrontFace( Dali::Graphics::API::FrontFace frontFace )
-{
- switch( frontFace )
- {
- case API::FrontFace::CLOCKWISE:
- return vk::FrontFace::eClockwise;
- case API::FrontFace::COUNTER_CLOCKWISE:
- return vk::FrontFace::eCounterClockwise;
- }
- return vk::FrontFace{};
-}
-
-
-constexpr vk::StencilOp ConvertStencilOp( Dali::Graphics::API::StencilOp stencilOp )
-{
- switch( stencilOp )
- {
- case API::StencilOp::KEEP: return vk::StencilOp::eKeep;
- case API::StencilOp::ZERO: return vk::StencilOp::eZero;
- case API::StencilOp::REPLACE: return vk::StencilOp::eReplace;
- case API::StencilOp::INCREMENT_AND_CLAMP: return vk::StencilOp::eIncrementAndClamp;
- case API::StencilOp::DECREMENT_AND_CLAMP: return vk::StencilOp::eDecrementAndClamp;
- case API::StencilOp::INVERT: return vk::StencilOp::eInvert;
- case API::StencilOp::INCREMENT_AND_WRAP: return vk::StencilOp::eIncrementAndWrap;
- case API::StencilOp::DECREMENT_AND_WRAP: return vk::StencilOp::eDecrementAndWrap;
- }
- return {};
-}
-
-}
-
-struct Pipeline::PipelineCreateInfo
-{
- PipelineFactory::Info info;
-};
-
-struct Pipeline::VulkanPipelineState
-{
- VulkanPipelineState() = default;
-
- ~VulkanPipelineState() = default;
-
- vk::PipelineColorBlendStateCreateInfo colorBlend;
- std::vector< vk::PipelineColorBlendAttachmentState > colorBlendAttachmentState;
-
- vk::PipelineDepthStencilStateCreateInfo depthStencil;
- vk::PipelineInputAssemblyStateCreateInfo inputAssembly;
- vk::PipelineMultisampleStateCreateInfo multisample;
- vk::PipelineRasterizationStateCreateInfo rasterization;
- vk::PipelineTessellationStateCreateInfo tesselation;
- vk::PipelineVertexInputStateCreateInfo vertexInput;
-
- /**
- * Dynamic state configuration
- */
- struct DynamicState
- {
- vk::PipelineDynamicStateCreateInfo stateCreateInfo;
- std::vector<vk::DynamicState> stateList;
- } dynamicState;
-
- /**
- * Viewport state configuration
- */
- struct ViewportState
- {
- vk::PipelineViewportStateCreateInfo createInfo;
- std::vector< vk::Viewport > viewports;
- std::vector< vk::Rect2D > scissors;
- } viewport;
-
- vk::Pipeline pipeline {};
- vk::PipelineLayout pipelineLayout {};
-
- vk::RenderPass renderpass {};
-};
-
-Pipeline::Pipeline( Vulkan::Graphics& graphics, Controller& controller, const PipelineFactory* factory )
-: mGraphics( controller.GetGraphics() ),
- mController( controller )
-{
- mHashCode = factory->GetHashCode();
-
- // copy info
- mCreateInfo = std::unique_ptr< PipelineCreateInfo >( new PipelineCreateInfo( { factory->GetCreateInfo() } ) );
-
- mPipelineCache = factory->mPipelineCache;
-}
-
-Pipeline::~Pipeline()
-{
- if( mVulkanPipelineState )
- {
- auto device = mGraphics.GetDevice();
- auto descriptorSetLayouts = mVkDescriptorSetLayouts;
- auto allocator = &mGraphics.GetAllocator();
- auto pipelineLayout = mVulkanPipelineState->pipelineLayout;
- auto pipeline = mVulkanPipelineState->pipeline;
-
- mVulkanPipelineState = nullptr;
-
- // Discard unused descriptor set layouts
- mGraphics.DiscardResource( [ device, descriptorSetLayouts, pipeline, pipelineLayout, allocator ]() {
-
- // Destroy pipeline
- device.destroyPipeline( pipeline, allocator );
-
- // Destroy pipeline layout
- device.destroyPipelineLayout( pipelineLayout, allocator );
-
- // Destroy descriptor set layouts
- for( const auto& descriptorSetLayout : descriptorSetLayouts )
- {
- device.destroyDescriptorSetLayout( descriptorSetLayout, allocator );
- }
-
- } );
- }
-}
-
-uint32_t GetLocationIndex( const std::vector< Vulkan::SpirV::SPIRVVertexInputAttribute >& attribs, uint32_t location )
-{
- auto retval = 0u;
-
- for( auto&& attr : attribs )
- {
- if( attr.location == location )
- {
- return retval;
- }
- retval++;
- }
- return -1u;
-}
-
-bool Pipeline::Initialise()
-{
- if( mVulkanPipelineState )
- {
- return false;
- }
-
- mVulkanPipelineState = std::unique_ptr< VulkanPipelineState >( new VulkanPipelineState() );
-
- // get shaders
- const auto& shader = static_cast<const VulkanAPI::Shader*>(mCreateInfo->info.shaderState.shaderProgram);
- auto vertexShader = shader->GetShader( vk::ShaderStageFlagBits::eVertex );
- auto fragmentShader = shader->GetShader( vk::ShaderStageFlagBits::eFragment );
-
- // retrieve input attributes descriptions
- std::vector< Vulkan::SpirV::SPIRVVertexInputAttribute > attribs{};
- vertexShader->GetSPIRVReflection()
- .GetVertexInputAttributes( attribs );
-
- std::vector< vk::VertexInputAttributeDescription > attributeDescriptions{};
- std::vector< vk::VertexInputBindingDescription > bindingDescriptions{};
-
- const auto& bufferBindings = mCreateInfo->info.vertexInputState.bufferBindings;
- const auto& attributes = mCreateInfo->info.vertexInputState.attributes;
-
- // vertex buffer bindings match order of buffers
- for( uint32_t bindingIndex = 0u; bindingIndex < bufferBindings.size(); ++bindingIndex )
- {
- bindingDescriptions.emplace_back( vk::VertexInputBindingDescription{}
- .setBinding( bindingIndex )
- .setInputRate(
- bufferBindings[bindingIndex].inputRate ==
- API::VertexInputRate::PER_VERTEX
- ? vk::VertexInputRate::eVertex
- : vk::VertexInputRate::eInstance )
- .setStride( bufferBindings[bindingIndex].stride ) );
- }
-
- // create attribute descriptions
- if( !attribs.empty() && attribs.size() == attribs.size() )
- {
- for( auto&& vb : attributes )
- {
- attributeDescriptions.emplace_back( vk::VertexInputAttributeDescription{}
- .setBinding( vb.binding )
- .setFormat( attribs[GetLocationIndex( attribs, vb.location )].format )
- .setLocation( vb.location )
- .setOffset( vb.offset ) );
- }
- }
- else // incompatible pipeline
- {
- return false;
- }
-
- // prepare vertex input state
- auto vertexInputState = vk::PipelineVertexInputStateCreateInfo{}
- .setVertexBindingDescriptionCount( Vulkan::U32( bindingDescriptions.size() ) )
- .setPVertexBindingDescriptions( bindingDescriptions.data() )
- .setVertexAttributeDescriptionCount( Vulkan::U32( attributeDescriptions.size() ) )
- .setPVertexAttributeDescriptions( attributeDescriptions.data() );
-
- std::vector< vk::PipelineShaderStageCreateInfo > shaderStages =
- {
- vk::PipelineShaderStageCreateInfo{}
- .setModule( vertexShader->GetVkHandle() )
- .setStage( vk::ShaderStageFlagBits::eVertex )
- .setPName( "main" ),
- vk::PipelineShaderStageCreateInfo{}
- .setModule( fragmentShader->GetVkHandle() )
- .setStage( vk::ShaderStageFlagBits::eFragment )
- .setPName( "main" )
- };
-
- auto framebuffer = static_cast<const VulkanAPI::Framebuffer*>(mCreateInfo->info.framebufferState.framebuffer);
- auto swapchain = mGraphics.GetSwapchainForFBID( 0 );
- auto framebufferObject = framebuffer ? framebuffer->GetFramebufferRef() : swapchain->GetCurrentFramebuffer();
-
- mVulkanPipelineState->pipelineLayout = PreparePipelineLayout();
-
- vk::GraphicsPipelineCreateInfo pipelineInfo;
- pipelineInfo
- .setSubpass( 0 )
- .setRenderPass( framebufferObject->GetRenderPass() )
- .setBasePipelineHandle( nullptr )
- .setBasePipelineIndex( 0 )
- .setLayout( mVulkanPipelineState->pipelineLayout )
- .setPColorBlendState( PrepareColorBlendStateCreateInfo() )
- .setPDepthStencilState( PrepareDepthStencilStateCreateInfo() )
- .setPDynamicState( PrepareDynamicStateCreatInfo() )
- .setPInputAssemblyState( PrepareInputAssemblyStateCreateInfo() )
- .setPMultisampleState( PrepareMultisampleStateCreateInfo() )
- .setPRasterizationState( PrepareRasterizationStateCreateInfo() )
- .setPTessellationState( PrepareTesselationStateCreateInfo() )
- .setPVertexInputState( &vertexInputState )
- .setPViewportState( PrepareViewportStateCreateInfo() )
- .setPStages( shaderStages.data() )
- .setStageCount( Vulkan::U32( shaderStages.size() ) );
-
- mVulkanPipelineState->renderpass = pipelineInfo.renderPass;
- mVulkanPipelineState->pipeline = VkAssert( mGraphics.GetDevice().createGraphicsPipeline( mGraphics. GetVulkanPipelineCache(), pipelineInfo, mGraphics.GetAllocator( "PIPELINE" ) ) );
-
- return true;
-}
-
-
-const vk::PipelineColorBlendStateCreateInfo* Pipeline::PrepareColorBlendStateCreateInfo()
-{
- const auto& factoryInfo = mCreateInfo->info;
-
- // blending enabled
- bool blendEnable = factoryInfo.colorBlendState.blendEnable;
-
- // color write mask
- vk::ColorComponentFlags colorWriteMask{};
- colorWriteMask |= ( factoryInfo.colorBlendState.colorComponentWriteBits & 1 ) ? vk::ColorComponentFlagBits::eR
- : vk::ColorComponentFlagBits{};
- colorWriteMask |= ( factoryInfo.colorBlendState.colorComponentWriteBits & 2 ) ? vk::ColorComponentFlagBits::eG
- : vk::ColorComponentFlagBits{};
- colorWriteMask |= ( factoryInfo.colorBlendState.colorComponentWriteBits & 4 ) ? vk::ColorComponentFlagBits::eB
- : vk::ColorComponentFlagBits{};
- colorWriteMask |= ( factoryInfo.colorBlendState.colorComponentWriteBits & 8 ) ? vk::ColorComponentFlagBits::eA
- : vk::ColorComponentFlagBits{};
-
- auto srcColorBlendFactor = ConvertBlendFactor( factoryInfo.colorBlendState.srcColorBlendFactor );
- auto dstColorBlendFactor = ConvertBlendFactor( factoryInfo.colorBlendState.dstColorBlendFactor );
- auto srcAlphaBlendFactor = ConvertBlendFactor( factoryInfo.colorBlendState.srcAlphaBlendFactor );
- auto dstAlphaBlendFactor = ConvertBlendFactor( factoryInfo.colorBlendState.dstAlphaBlendFactor );
- auto colorBlendOp = ConvertBlendOp( factoryInfo.colorBlendState.colorBlendOp );
- auto alphaBlendOp = ConvertBlendOp( factoryInfo.colorBlendState.alphaBlendOp );
-
- auto blendAttachmentState = vk::PipelineColorBlendAttachmentState{}
- .setBlendEnable( vk::Bool32( blendEnable ) )
- .setColorWriteMask( colorWriteMask )
- .setSrcColorBlendFactor( srcColorBlendFactor )
- .setDstColorBlendFactor( dstColorBlendFactor )
- .setSrcAlphaBlendFactor( srcAlphaBlendFactor )
- .setDstAlphaBlendFactor( dstAlphaBlendFactor )
- .setColorBlendOp( colorBlendOp )
- .setAlphaBlendOp( alphaBlendOp );
-
- mVulkanPipelineState->colorBlendAttachmentState.emplace_back( blendAttachmentState );
-
- mVulkanPipelineState->colorBlend
- .setBlendConstants( { factoryInfo.colorBlendState.blendConstants[0],
- factoryInfo.colorBlendState.blendConstants[1],
- factoryInfo.colorBlendState.blendConstants[2],
- factoryInfo.colorBlendState.blendConstants[3] } )
- .setAttachmentCount( 1 )
- .setPAttachments( mVulkanPipelineState->colorBlendAttachmentState.data() );
-
- return &mVulkanPipelineState->colorBlend;
-}
-
-const vk::PipelineDepthStencilStateCreateInfo* Pipeline::PrepareDepthStencilStateCreateInfo()
-{
- const auto& dsInfo = mCreateInfo->info.depthStencilState;
- auto retval = &( mVulkanPipelineState->depthStencil
- .setDepthTestEnable( vk::Bool32( dsInfo.depthTestEnable ) )
- .setDepthWriteEnable( vk::Bool32( dsInfo.depthWriteEnable ) )
- .setDepthCompareOp( ConvertCompareOp( dsInfo.depthCompareOp ) )
- .setDepthBoundsTestEnable( false )
- .setStencilTestEnable( vk::Bool32( dsInfo.stencilTestEnable ) ) );
-
- if( dsInfo.stencilTestEnable )
- {
- auto frontOpState = vk::StencilOpState{}
- .setCompareOp( ConvertCompareOp( dsInfo.front.compareOp ) )
- .setCompareMask( dsInfo.front.compareMask )
- .setDepthFailOp( ConvertStencilOp( dsInfo.front.depthFailOp ) )
- .setFailOp( ConvertStencilOp( dsInfo.front.failOp ) )
- .setPassOp( ConvertStencilOp( dsInfo.front.passOp ) )
- .setReference( dsInfo.front.reference )
- .setWriteMask( dsInfo.front.writeMask );
-
- retval->setFront( frontOpState );
- retval->setBack( frontOpState );
- }
-
- return retval;
-}
-
-const vk::PipelineDynamicStateCreateInfo* Pipeline::PrepareDynamicStateCreatInfo()
-{
- // if no mask set, disable dynamic states
- if( !mCreateInfo->info.dynamicStateMask )
- {
- return nullptr;
- }
-
- mVulkanPipelineState->dynamicState = {};
-
- const vk::DynamicState STATES[] =
- {
- vk::DynamicState::eViewport,
- vk::DynamicState::eScissor,
- vk::DynamicState::eLineWidth,
- vk::DynamicState::eDepthBias,
- vk::DynamicState::eBlendConstants,
- vk::DynamicState::eDepthBounds,
- vk::DynamicState::eStencilCompareMask,
- vk::DynamicState::eStencilWriteMask,
- vk::DynamicState::eStencilReference
- };
-
- std::vector<vk::DynamicState> dynamicStates{};
-
- for( auto i = 0u; i < API::PIPELINE_DYNAMIC_STATE_COUNT; ++i )
- {
- if(mCreateInfo->info.dynamicStateMask & (1u << i))
- {
- dynamicStates.push_back(STATES[i]);
- }
- }
-
- mVulkanPipelineState->dynamicState.stateList = std::move(dynamicStates);
- mVulkanPipelineState->dynamicState.stateCreateInfo.setDynamicStateCount( uint32_t(mVulkanPipelineState->dynamicState.stateList.size()) );
- mVulkanPipelineState->dynamicState.stateCreateInfo.setPDynamicStates( mVulkanPipelineState->dynamicState.stateList.data() );
- return &mVulkanPipelineState->dynamicState.stateCreateInfo;
-}
-
-const vk::PipelineInputAssemblyStateCreateInfo* Pipeline::PrepareInputAssemblyStateCreateInfo()
-{
- const auto& iaInfo = mCreateInfo->info.inputAssemblyState;
- //@todo support topology and restart
- return &( mVulkanPipelineState->inputAssembly
- .setPrimitiveRestartEnable( vk::Bool32( iaInfo.primitiveRestartEnable ) )
- .setTopology( ConvertPrimitiveTopology( iaInfo.topology ) ) );
-}
-
-const vk::PipelineMultisampleStateCreateInfo* Pipeline::PrepareMultisampleStateCreateInfo()
-{
- return &( mVulkanPipelineState->multisample
- .setSampleShadingEnable( vk::Bool32( false ) )
- .setRasterizationSamples( vk::SampleCountFlagBits::e1 )
- .setAlphaToCoverageEnable( vk::Bool32( false ) )
- .setMinSampleShading( 1.0f )
- .setPSampleMask( nullptr ) );
-}
-
-const vk::PipelineRasterizationStateCreateInfo* Pipeline::PrepareRasterizationStateCreateInfo()
-{
- const auto& rsInfo = mCreateInfo->info.rasterizationState;
- return &( mVulkanPipelineState->rasterization
- .setCullMode( ConvertCullMode( rsInfo.cullMode ) )
- .setDepthBiasClamp( 0.0f )
- .setDepthBiasEnable( vk::Bool32( false ) )
- .setDepthClampEnable( vk::Bool32( false ) )
- .setFrontFace( ConvertFrontFace( rsInfo.frontFace ) )
- .setPolygonMode( ConvertPolygonMode( rsInfo.polygonMode ) )
- .setRasterizerDiscardEnable( vk::Bool32( false ) )
- .setLineWidth( 1.0f ) );
-}
-
-const vk::PipelineViewportStateCreateInfo* Pipeline::PrepareViewportStateCreateInfo()
-{
- const auto& vpInfo = mCreateInfo->info.viewportState;
- const auto& dynamicStateInfo = mCreateInfo->info.dynamicStateMask;
-
- // Use maximum viewport size in case we use dynamic viewport state
- auto width = dynamicStateInfo & API::PipelineDynamicStateBits::VIEWPORT_BIT ?
- float( mGraphics.GetPhysicalDevice().getProperties().limits.maxFramebufferWidth ) : vpInfo.viewport.width;
- auto height = dynamicStateInfo & API::PipelineDynamicStateBits::VIEWPORT_BIT ?
- float( mGraphics.GetPhysicalDevice().getProperties().limits.maxFramebufferHeight ) : vpInfo.viewport.height;
-
- // viewports
- mVulkanPipelineState->viewport.viewports.emplace_back( vpInfo.viewport.x, vpInfo.viewport.y, width, height );
- mVulkanPipelineState->viewport.viewports[0].setMinDepth( vpInfo.viewport.minDepth );
- mVulkanPipelineState->viewport.viewports[0].setMaxDepth( vpInfo.viewport.maxDepth );
-
- // scissors
- if( vpInfo.scissorTestEnable )
- {
- mVulkanPipelineState->viewport.scissors.emplace_back(vk::Rect2D({
- static_cast<int32_t>(vpInfo.scissor.x),
- static_cast<int32_t>(vpInfo.scissor.y)
- },
- {
- Vulkan::U32(vpInfo.scissor.width),
- Vulkan::U32(vpInfo.scissor.height)
- }));
- }
- else
- {
- mVulkanPipelineState->viewport.scissors.emplace_back(vk::Rect2D(
- { static_cast<int32_t>(0), static_cast<int32_t>(0) },
- { Vulkan::U32(width), Vulkan::U32(height) })
- );
- }
- auto& viewState = mVulkanPipelineState->viewport;
-
- return &( mVulkanPipelineState->viewport.createInfo.
- setViewportCount( Vulkan::U32( viewState.viewports.size() ) ).
- setPViewports( viewState.viewports.data() ).
- setPScissors( viewState.scissors.data() ).
- setScissorCount( Vulkan::U32( viewState.scissors.size() ) ) );
-}
-
-const vk::PipelineTessellationStateCreateInfo* Pipeline::PrepareTesselationStateCreateInfo()
-{
- return nullptr;
-}
-
-const vk::PipelineLayout Pipeline::PreparePipelineLayout()
-{
- // descriptor set layout
- const auto& shader = static_cast<const VulkanAPI::Shader*>(mCreateInfo->info.shaderState.shaderProgram);
- auto vertexShader = shader->GetShader( vk::ShaderStageFlagBits::eVertex );
- auto fragmentShader = shader->GetShader( vk::ShaderStageFlagBits::eFragment );
-
- auto vshDsLayouts = vertexShader->GetSPIRVReflection()
- .GenerateDescriptorSetLayoutCreateInfo();
- auto fshDsLayouts = fragmentShader->GetSPIRVReflection()
- .GenerateDescriptorSetLayoutCreateInfo();
-
- decltype( vshDsLayouts ) layouts;
- layouts.resize( std::max( vshDsLayouts.size(), fshDsLayouts.size() ) );
-
- std::vector< vk::DescriptorSetLayout > dsLayouts;
-
- for( auto i = 0u; i < layouts.size(); ++i )
- {
- std::vector< vk::DescriptorSetLayoutBinding > dsBindings;
-
- // concatenate bindings per set
- if( !vshDsLayouts.empty() && vshDsLayouts[i].bindingCount )
- {
- dsBindings.insert(
- dsBindings.end(), vshDsLayouts[i].pBindings, vshDsLayouts[i].pBindings + vshDsLayouts[i].bindingCount );
- }
- if( !fshDsLayouts.empty() && fshDsLayouts[i].bindingCount )
- {
- dsBindings.insert(
- dsBindings.end(), fshDsLayouts[i].pBindings, fshDsLayouts[i].pBindings + fshDsLayouts[i].bindingCount );
- }
-
- GenerateDescriptorSetLayoutSignatures( dsBindings );
-
- layouts[i].pBindings = dsBindings.data();
- layouts[i].bindingCount = Vulkan::U32( dsBindings.size() );
-
- dsLayouts.emplace_back( VkAssert( mGraphics.GetDevice()
- .createDescriptorSetLayout( layouts[i], mGraphics.GetAllocator() ) ) );
- }
-
- mVkDescriptorSetLayouts = dsLayouts;
-
- // create layout
- auto pipelineLayoutCreateInfo = vk::PipelineLayoutCreateInfo{}
- .setSetLayoutCount( Vulkan::U32( dsLayouts.size() ) )
- .setPSetLayouts( dsLayouts.data() )
- .setPPushConstantRanges( nullptr )
- .setPushConstantRangeCount( 0 );
-
- return VkAssert( mGraphics.GetDevice().createPipelineLayout( pipelineLayoutCreateInfo, mGraphics.GetAllocator("PIPELINELAYOUT") ) );
-}
-
-void Pipeline::GenerateDescriptorSetLayoutSignatures( const std::vector< vk::DescriptorSetLayoutBinding >& bindings )
-{
- auto descriptorTypesAndCount = std::vector< std::tuple< uint32_t, Vulkan::DescriptorType > >{};
-
- std::for_each( bindings.cbegin(),
- bindings.cend(),
- [ & ]( const vk::DescriptorSetLayoutBinding binding ) {
- auto value = binding.descriptorCount;
- Vulkan::DescriptorType descriptorType;
-
- switch( binding.descriptorType )
- {
- case vk::DescriptorType::eStorageImage:
- descriptorType = Vulkan::DescriptorType::STORAGE_IMAGE;
- break;
- case vk::DescriptorType::eSampler:
- descriptorType = Vulkan::DescriptorType::SAMPLER;
- break;
- case vk::DescriptorType::eSampledImage:
- descriptorType = Vulkan::DescriptorType::SAMPLED_IMAGE;
- break;
- case vk::DescriptorType::eCombinedImageSampler:
- descriptorType = Vulkan::DescriptorType::COMBINED_IMAGE_SAMPLER;
- break;
- case vk::DescriptorType::eUniformTexelBuffer:
- descriptorType = Vulkan::DescriptorType::UNIFORM_TEXEL_BUFFER;
- break;
- case vk::DescriptorType::eStorageTexelBuffer:
- descriptorType = Vulkan::DescriptorType::STORAGE_TEXEL_BUFFER;
- break;
- case vk::DescriptorType::eUniformBuffer:
- descriptorType = Vulkan::DescriptorType::UNIFORM_BUFFER;
- break;
- case vk::DescriptorType::eStorageBuffer:
- descriptorType = Vulkan::DescriptorType::STORAGE_BUFFER;
- break;
- case vk::DescriptorType::eUniformBufferDynamic:
- descriptorType = Vulkan::DescriptorType::DYNAMIC_UNIFORM_BUFFER;
- break;
- case vk::DescriptorType::eStorageBufferDynamic:
- descriptorType = Vulkan::DescriptorType::DYNAMIC_STORAGE_BUFFER;
- break;
- case vk::DescriptorType::eInputAttachment:
- descriptorType = Vulkan::DescriptorType::INPUT_ATTACHMENT;
- break;
- }
-
- auto found = std::find_if( descriptorTypesAndCount.begin(),
- descriptorTypesAndCount.end(),
- [ & ]( std::tuple< uint32_t, Vulkan::DescriptorType > tuple )
- {
- return descriptorType == std::get< Vulkan::DescriptorType >( tuple );
- } );
-
- if( found == descriptorTypesAndCount.end() )
- {
- descriptorTypesAndCount.emplace_back( value, descriptorType );
- }
- else
- {
- auto& valueRef = std::get< uint32_t >( *found );
- valueRef += value;
- }
- } );
-
- auto signature = Vulkan::DescriptorSetLayoutSignature{};
- std::for_each( descriptorTypesAndCount.begin(),
- descriptorTypesAndCount.end(),
- [ & ]( const std::tuple< uint32_t, Vulkan::DescriptorType > tuple )
- {
- signature.EncodeValue( std::get< uint32_t >( tuple ),
- std::get< Vulkan::DescriptorType >( tuple ) );
- } );
-
- mDescriptorSetLayoutSignatures.emplace_back( signature );
-}
-
-void Pipeline::Reference()
-{
- ++mRefCounter;
-}
-
-void Pipeline::Dereference()
-{
- if( mRefCounter )
- {
- if( --mRefCounter == 0 )
- {
- Destroy();
- }
- }
-}
-
-void Pipeline::Destroy()
-{
- if( mPipelineCache )
- {
- mPipelineCache->RemovePipeline( this );
- }
-}
-
-uint32_t Pipeline::GetHashCode() const
-{
- return mHashCode;
-}
-
-const vk::Pipeline& Pipeline::GetVkPipeline() const
-{
- return mVulkanPipelineState->pipeline;
-}
-
-const vk::PipelineLayout& Pipeline::GetVkPipelineLayout() const
-{
- return mVulkanPipelineState->pipelineLayout;
-}
-
-const std::vector< vk::DescriptorSetLayout >& Pipeline::GetVkDescriptorSetLayouts() const
-{
- return mVkDescriptorSetLayouts;
-}
-
-const std::vector< Vulkan::DescriptorSetLayoutSignature >& Pipeline::GetDescriptorSetLayoutSignatures() const
-{
- return mDescriptorSetLayoutSignatures;
-}
-
-API::PipelineDynamicStateMask Pipeline::GetDynamicStateMask() const
-{
- return mCreateInfo->info.dynamicStateMask;
-}
-
-void Pipeline::Bind( Vulkan::RefCountedCommandBuffer& commandBuffer )
-{
- commandBuffer->GetVkHandle().bindPipeline( vk::PipelineBindPoint::eGraphics, mVulkanPipelineState->pipeline );
-}
-
-bool Pipeline::HasDepthEnabled() const
-{
- return mCreateInfo->info.depthStencilState.depthTestEnable || mCreateInfo->info.depthStencilState.depthWriteEnable;
-}
-
-bool Pipeline::HasStencilEnabled() const
-{
- // @todo: work out proper condition
- return mCreateInfo->info.depthStencilState.stencilTestEnable;
-}
-
-} // Internal
-} // VulkanAPI
-} // Graphics
-} // Dal
-
+++ /dev/null
-#ifndef DALI_GRAPHICS_VULKAN_API_PIPELINE_IMPL_H
-#define DALI_GRAPHICS_VULKAN_API_PIPELINE_IMPL_H
-
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics/vulkan/internal/vulkan-types.h>
-#include <atomic>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-class Graphics;
-}
-
-namespace VulkanAPI
-{
-class Pipeline;
-
-class Controller;
-
-class PipelineFactory;
-
-class PipelineCache;
-namespace Internal
-{
-class Pipeline
-{
-public:
-
- Pipeline( Vulkan::Graphics& graphics, Controller& controller, const PipelineFactory* factory );
-
- ~Pipeline();
-
- uint32_t GetHashCode() const;
-
- bool Initialise();
-
- void Reference();
-
- void Dereference();
-
- void Destroy();
-
- const vk::Pipeline& GetVkPipeline() const;
-
- const vk::PipelineLayout& GetVkPipelineLayout() const;
-
- const std::vector< vk::DescriptorSetLayout >& GetVkDescriptorSetLayouts() const;
-
- const std::vector< Vulkan::DescriptorSetLayoutSignature >& GetDescriptorSetLayoutSignatures() const;
-
- API::PipelineDynamicStateMask GetDynamicStateMask() const;
-
- void Bind( Vulkan::RefCountedCommandBuffer& commandBuffer );
-
- bool HasDepthEnabled() const;
-
- bool HasStencilEnabled() const;
-
-private:
-
- const vk::PipelineColorBlendStateCreateInfo* PrepareColorBlendStateCreateInfo();
-
- const vk::PipelineDepthStencilStateCreateInfo* PrepareDepthStencilStateCreateInfo();
-
- const vk::PipelineInputAssemblyStateCreateInfo* PrepareInputAssemblyStateCreateInfo();
-
- const vk::PipelineMultisampleStateCreateInfo* PrepareMultisampleStateCreateInfo();
-
- const vk::PipelineRasterizationStateCreateInfo* PrepareRasterizationStateCreateInfo();
-
- const vk::PipelineTessellationStateCreateInfo* PrepareTesselationStateCreateInfo();
-
- const vk::PipelineViewportStateCreateInfo* PrepareViewportStateCreateInfo();
-
- const vk::PipelineDynamicStateCreateInfo* PrepareDynamicStateCreatInfo();
-
- const vk::PipelineLayout PreparePipelineLayout();
-
- void GenerateDescriptorSetLayoutSignatures( const std::vector< vk::DescriptorSetLayoutBinding >& bindings );
-
-
- Vulkan::Graphics& mGraphics;
- Controller& mController;
- uint32_t mHashCode;
-
- std::atomic_int mRefCounter{ 0u };
-
- // wrapper for copy of cSreate data
- struct PipelineCreateInfo;
- std::unique_ptr< PipelineCreateInfo > mCreateInfo;
-
- struct VulkanPipelineState;
- std::unique_ptr< VulkanPipelineState > mVulkanPipelineState;
-
- std::vector< Vulkan::DescriptorSetLayoutSignature > mDescriptorSetLayoutSignatures;
- std::vector< vk::DescriptorSetLayout > mVkDescriptorSetLayouts;
-
- PipelineCache* mPipelineCache;
-};
-
-
-}
-
-}
-}
-}
-
-#endif //DALI_GRAPHICS_VULKAN_API_PIPELINE_IMPL_H
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics/vulkan/api/internal/vulkan-pipeline-cache-debug.h>
-#include <dali/graphics/vulkan/api/internal/vulkan-api-pipeline-impl.h>
-#include <dali/graphics/vulkan/api/vulkan-api-pipeline.h>
-#include <dali/graphics-api/graphics-api-types-debug.h>
-#include <sstream>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace VulkanAPI
-{
-#if defined(DEBUG_ENABLED)
-
-std::string PipelineCacheDebug::DebugPrintPipelineInfo( const PipelineFactory::Info& info ) const
-{
- std::stringstream ss;
- // shader
- ss << " Shader: " << info.shaderState.shaderProgram << std::endl;
-
- // vertex input state
- ss << " VI : " << std::endl;
- {
- // attributes
- int k = 0;
- for (auto &&i : info.vertexInputState.attributes)
- {
- ss << " attribute[" << k++ << "]" << std::endl;
- ss << " binding = " << i.binding << std::endl;
- ss << " offset = " << i.offset << std::endl;
- ss << " location = " << i.location << std::endl;
- }
- // bindings
- k = 0;
- for (auto &&i : info.vertexInputState.bufferBindings)
- {
- ss << " binding[" << k++ << "]" << std::endl;
- ss << " inputRate = " << API::Debug::str(i.inputRate) << std::endl;
- ss << " stride = " << i.stride << std::endl;
- }
- }
-
- // vertex input state
- ss << " IA : " << std::endl;
- ss << " primitiveRestartEnable: " << info.inputAssemblyState.primitiveRestartEnable << std::endl;
- ss << " topology : " << API::Debug::str(info.inputAssemblyState.topology) << std::endl;
-
- // depth/stencil
- const auto& ds = info.depthStencilState;
- ss << " DS : " << std::endl;
- ss << " depthTestEnable: " << ds.depthTestEnable << std::endl;
- ss << " depthWriteEnable: " << ds.depthWriteEnable << std::endl;
- ss << " depthCompareOp: " << API::Debug::str(ds.depthCompareOp) << std::endl;
- ss << " stencilTestEnable: " << ds.stencilTestEnable << std::endl;
-
- // rasterization state
- const auto& rs = info.rasterizationState;
- ss << " RS : " << std::endl;
- ss << " polygonMode : " << API::Debug::str(rs.polygonMode) << std::endl;
- ss << " frontFace : " << API::Debug::str(rs.frontFace) << std::endl;
- ss << " cullMode : " << API::Debug::str(rs.cullMode) << std::endl;
-
- const auto& cb = info.colorBlendState;
- ss << " CB : " << std::endl;
- ss << " colorBlendOp : " << API::Debug::str(cb.colorBlendOp) << std::endl;
- ss << " alphaBlendOp : " << API::Debug::str(cb.alphaBlendOp) << std::endl;
- ss << " blendConstants : " << cb.blendConstants[0] << ", " << cb.blendConstants[1] << ", " << cb.blendConstants[2] << ", " << cb.blendConstants[3] << std::endl;
- ss << " srcColorBlendFactor : " << API::Debug::str(cb.srcColorBlendFactor) << std::endl;
- ss << " srcAlphaBlendFactor : " << API::Debug::str(cb.srcAlphaBlendFactor) << std::endl;
- ss << " dstColorBlendFactor : " << API::Debug::str(cb.dstColorBlendFactor) << std::endl;
- ss << " dstAlphaBlendFactor : " << API::Debug::str(cb.dstAlphaBlendFactor) << std::endl;
- ss << " blendEnable : " << cb.blendEnable << std::endl;
- ss << " logicOpEnable : " << cb.logicOpEnable << std::endl;
- ss << " logicOp : " << "UNDEFINED" << std::endl;
- ss << " colorComponentWriteBits : " << cb.colorComponentWriteBits << std::endl;
-
- const auto& vp = info.viewportState;
- ss << " VP : " << std::endl;
- ss << " viewport : { " << vp.viewport.x << ", "
- << vp.viewport.y << ", "
- << vp.viewport.width << ", "
- << vp.viewport.height << " } " << std::endl;
- return ss.str();
-}
-
-std::string PipelineCacheDebug::DebugPrintPipeline( const VulkanAPI::Pipeline& pipeline ) const
-{
- std::stringstream ss;
- auto impl = pipeline.GetImplementation();
-
- // find pipeline in cache
- const PipelineFactory::Info* info { nullptr };
- for( auto&& i : mPipelineCache.mCacheMap )
- {
- for (auto&& j : i.second)
- {
- if( j.pipelineImpl.get() == impl )
- {
- info = j.info.get();
- break;
- }
- }
- if( info )
- {
- break;
- }
- }
-
- if(!info)
- {
- return "Invalid pipeline!";
- }
- ss << "Pipeline id = " << &pipeline << ":" << std::endl;
- ss << DebugPrintPipelineInfo(*info);
- return ss.str();
-}
-
-std::string PipelineCacheDebug::DebugPrint() const
-{
- std::stringstream ss;
- for( auto&& cacheEntry : mPipelineCache.mCacheMap )
- {
- for( auto&& info: cacheEntry.second )
- {
- ss << "Pipeline id = " << info.pipelineImpl.get() << ":" << std::endl;
- ss << DebugPrintPipelineInfo( *info.info.get() );
- }
- }
- return ss.str();
-}
-#endif
-
-} // namespace VulkanAPI
-} // namespace Graphics
-} // namespace Dali
-
+++ /dev/null
-#ifndef DALI_GRAPHICS_VULKAN_API_PIPELINE_CACHE_DEBUG_H
-#define DALI_GRAPHICS_VULKAN_API_PIPELINE_CACHE_DEBUG_H
-
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics/vulkan/api/internal/vulkan-pipeline-cache.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace VulkanAPI
-{
-#if defined(DEBUG_ENABLED)
-class PipelineCacheDebug
-{
-public:
-
- PipelineCacheDebug(PipelineCache& pipelineCache)
- : mPipelineCache( pipelineCache ) {}
-
- PipelineCache& mPipelineCache;
-
- std::string DebugPrintPipelineInfo( const PipelineFactory::Info& info ) const;
-
- std::string DebugPrintPipeline( const VulkanAPI::Pipeline& pipeline ) const;
-
- std::string DebugPrint() const;
-};
-#endif
-}
-}
-}
-
-#endif //DALI_VULKAN_161117_VULKAN_PIPELINE_CACHE_DEBUG_H
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics/vulkan/api/internal/vulkan-pipeline-cache.h>
-#include <dali/graphics/vulkan/api/internal/vulkan-api-pipeline-impl.h>
-#include <dali/graphics/vulkan/api/vulkan-api-pipeline.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace VulkanAPI
-{
-
-PipelineCache::PipelineCache() = default;
-
-PipelineCache::~PipelineCache() = default;
-
-Internal::Pipeline* PipelineCache::GetPipeline( const VulkanAPI::PipelineFactory& factory ) const
-{
- auto hashCode = factory.GetHashCode();
- auto iter = mCacheMap.find( hashCode );
- if( iter == mCacheMap.end() )
- {
- return nullptr;
- }
-
- auto& entries = iter->second;
-
- // return quickly if there's only one entry
- if( entries.size() == 1 )
- {
- return entries[0].pipelineImpl.get();
- }
-
- for( auto&& entry : entries )
- {
- if( !std::memcmp( &entry.info, &factory.GetCreateInfo(), sizeof( entry.info ) ) )
- {
- return entry.pipelineImpl.get();
- }
- }
-
- return nullptr;
-}
-
-bool PipelineCache::SavePipeline( const VulkanAPI::PipelineFactory& factory, std::unique_ptr< Internal::Pipeline > pipeline )
-{
- // hash factory
- auto hashCode = factory.GetHashCode();
- auto iter = mCacheMap.find( hashCode );
- std::vector< CacheEntry >* cacheEntries{ nullptr };
-
- if( iter == mCacheMap.end() )
- {
- mCacheMap[hashCode] = std::vector< CacheEntry >{};
- cacheEntries = &mCacheMap[hashCode];
- }
- else
- {
- cacheEntries = &iter->second;
- }
-
- // pass the ownership to the cache
- CacheEntry entry;
- entry.pipelineImpl = std::move( pipeline );
- entry.info = std::unique_ptr< PipelineFactory::Info >( new PipelineFactory::Info( factory.GetCreateInfo() ) );
- cacheEntries->push_back( std::move( entry ) );
- return true;
-}
-
-void PipelineCache::Compile()
-{
- for( auto& item : mCacheMap )
- {
- for( auto& pipeline : item.second )
- {
- pipeline.pipelineImpl->Initialise();
- }
- }
-}
-
-bool PipelineCache::RemovePipeline( Internal::Pipeline* pipeline )
-{
- auto hashCode = pipeline->GetHashCode();
- auto iter = mCacheMap.find( hashCode );
- if( iter == mCacheMap.end() )
- {
- return false;
- }
-
- // delete pipeline
- if( iter->second.size() == 1 )
- {
- iter->second.clear();
- mCacheMap.erase( iter );
- }
- else
- {
- int32_t i = 0;
- for( auto&& entry : iter->second )
- {
- if( entry.pipelineImpl.get() == pipeline )
- {
-
- iter->second.erase( iter->second.begin() + i );
- if( iter->second.empty() )
- {
- mCacheMap.erase( iter );
- }
- break;
- }
- ++i;
- }
- }
-
- return true;
-}
-
-uint32_t PipelineCache::GetCacheSize() const
-{
- auto retval = 0u;
- for( auto& item : mCacheMap )
- {
- retval += uint32_t(item.second.size());
- }
- return retval;
-}
-
-} // VulkanAPI
-} // Graphics
-} // Dali
+++ /dev/null
-#ifndef DALI_GRAPHICS_VULKAN_API_PIPELINE_CACHE_H
-#define DALI_GRAPHICS_VULKAN_API_PIPELINE_CACHE_H
-
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics-api/graphics-api-pipeline.h>
-#include <dali/graphics/vulkan/api/vulkan-api-pipeline-factory.h>
-
-#include <memory>
-#include <map>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-class Graphics;
-} // Vulkan
-
-namespace VulkanAPI
-{
-class Controller;
-namespace Internal
-{
-class Pipeline;
-
-} // Internal
-
-class Controller;
-class PipelineFactory;
-class Pipeline;
-
-class PipelineCache
-{
-public:
-
- PipelineCache();
-
- ~PipelineCache();
-
- /**
- * Finds a pipeline based on the factory setup
- * @return pipeline implementation or nullptr if pipeline isn't part of cache
- */
- Internal::Pipeline* GetPipeline( const VulkanAPI::PipelineFactory& factory ) const;
-
- /**
- * Saves pipeline in the cache
- * @param pipeline
- * @return
- */
- bool SavePipeline( const VulkanAPI::PipelineFactory& factory, std::unique_ptr< Internal::Pipeline > pipeline );
-
- /**
- * Removes unused pipeline
- */
- bool RemovePipeline( Internal::Pipeline* pipeline );
-
- /**
- * Compiles all pending pipelines
- */
- void Compile();
-
-private:
-
- friend class PipelineCacheDebug;
-
- /**
- * Computes pipeline cache size
- * @return
- */
- uint32_t GetCacheSize() const;
-
-private:
-
- struct CacheEntry
- {
- std::unique_ptr< Internal::Pipeline > pipelineImpl;
- std::unique_ptr< PipelineFactory::Info > info{}; // to compare if hash collision occurs
- };
-
- std::map< uint32_t, std::vector< CacheEntry>> mCacheMap;
-};
-} // VulkanAPI
-} // Graphics
-} // Dali
-
-#endif // DALI_GRAPHICS_VULKAN_API_PIPELINE_CACHE_H
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics/vulkan/api/vulkan-api-buffer-factory.h>
-#include <dali/graphics/vulkan/api/vulkan-api-buffer.h>
-#include <dali/graphics/vulkan/vulkan-graphics.h>
-#include <dali/graphics/vulkan/internal/vulkan-buffer.h>
-#include <dali/graphics/vulkan/api/vulkan-api-controller.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace VulkanAPI
-{
-BufferFactory::BufferFactory( Controller& controller )
- : mController( controller ), mGraphics( controller.GetGraphics() )
-{
-
-}
-
-BufferFactory& BufferFactory::SetUsageFlags( Dali::Graphics::API::BufferUsageFlags usage )
-{
- if( usage & uint32_t( API::BufferUsage::TRANSFER_DST ) )
- {
- mUsage |= vk::BufferUsageFlagBits::eTransferDst;
- }
- if( usage & uint32_t( API::BufferUsage::TRANSFER_SRC ) )
- {
- mUsage |= vk::BufferUsageFlagBits::eTransferSrc;
- }
- if( usage & uint32_t( API::BufferUsage::UNIFORM_TEXEL_BUFFER ) )
- {
- mUsage |= vk::BufferUsageFlagBits::eUniformTexelBuffer;
- }
- if( usage & uint32_t( API::BufferUsage::STORAGE_TEXEL_BUFFER ) )
- {
- mUsage |= vk::BufferUsageFlagBits::eStorageTexelBuffer;
- }
- if( usage & uint32_t( API::BufferUsage::UNIFORM_BUFFER ) )
- {
- mUsage |= vk::BufferUsageFlagBits::eUniformBuffer;
- }
- if( usage & uint32_t( API::BufferUsage::STORAGE_BUFFER ) )
- {
- mUsage |= vk::BufferUsageFlagBits::eStorageBuffer;
- }
- if( usage & uint32_t( API::BufferUsage::INDEX_BUFFER ) )
- {
- mUsage |= vk::BufferUsageFlagBits::eIndexBuffer;
- }
- if( usage & uint32_t( API::BufferUsage::VERTEX_BUFFER ) )
- {
- mUsage |= vk::BufferUsageFlagBits::eVertexBuffer;
- }
- if( usage & uint32_t( API::BufferUsage::INDIRECT_BUFFER ) )
- {
- mUsage |= vk::BufferUsageFlagBits::eIndexBuffer;
- }
- return *this;
-}
-
-BufferFactory& BufferFactory::SetSize( uint32_t size )
-{
- mSize = size;
- return *this;
-}
-
-std::unique_ptr< API::Buffer > BufferFactory::Create() const
-{
- auto retval = std::make_unique< VulkanAPI::Buffer >( mController, mUsage, mUsageHints, mSize );
- if( retval->Initialise() )
- {
- return std::unique_ptr< API::Buffer >{ retval.release() };
- }
- return nullptr;
-}
-
-
-} // namespace VulkanAPI
-} // namespace Graphics
-} // namespace Dali
+++ /dev/null
-#ifndef DALI_GRAPHICS_VULKAN_API_BUFFER_FACTORY_H
-#define DALI_GRAPHICS_VULKAN_API_BUFFER_FACTORY_H
-
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics/vulkan/internal/vulkan-types.h>
-#include <dali/graphics-api/graphics-api-buffer-factory.h>
-#include <dali/graphics-api/graphics-api-buffer.h>
-#include <dali/graphics-api/graphics-api-types.h>
-
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-class Graphics;
-}
-namespace VulkanAPI
-{
-class Controller;
-
-class BufferFactory : public Dali::Graphics::API::BufferFactory
-{
-public:
-
- explicit BufferFactory( Controller& controller );
-
- VulkanAPI::BufferFactory& SetUsageFlags( Dali::Graphics::API::BufferUsageFlags usage ) override;
-
- VulkanAPI::BufferFactory& SetSize( uint32_t size ) override;
-
- PointerType Create() const override;
-
-private:
-
- Controller& mController;
- Vulkan::Graphics& mGraphics;
- vk::BufferUsageFlags mUsage;
- API::Buffer::UsageHint mUsageHints;
- uint32_t mSize;
-};
-
-} // namespace VulkanAPI
-} // namespace Graphics
-} // namespace Dali
-
-#endif // DALI_GRAPHICS_VULKAN_API_BUFFER_FACTORY_H
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics/vulkan/api/vulkan-api-buffer.h>
-#include <dali/graphics/vulkan/vulkan-graphics.h>
-#include <dali/graphics/vulkan/internal/vulkan-buffer.h>
-#include <dali/graphics/vulkan/api/vulkan-api-controller.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace VulkanAPI
-{
-
-Buffer::Buffer( Controller& controller,
- vk::BufferUsageFlags usage,
- API::Buffer::UsageHint usageHints,
- uint32_t size )
- : mController( controller ),
- mGraphics( controller.GetGraphics() ),
- mUsage( usage ),
- mUsageHints( usageHints ),
- mSize( size )
-{
-
-}
-
-bool Buffer::Initialise()
-{
- // create buffer
- mBufferRef = mGraphics.CreateBuffer( mSize, mUsage );
-
- // allocate memory
- // todo: host visible should be only for dynamic buffers
- auto memory = mGraphics.AllocateMemory( mBufferRef, vk::MemoryPropertyFlagBits::eHostVisible );
- mGraphics.BindBufferMemory( mBufferRef, std::move(memory), 0 );
-
- return true;
-}
-
-void* Buffer::Map()
-{
- return mBufferRef->GetMemory()->Map();
-}
-
-void Buffer::Unmap()
-{
- mBufferRef->GetMemory()->Unmap();
-}
-
-void Buffer::Flush()
-{
- mBufferRef->GetMemory()->Flush();
-}
-
-void Buffer::DestroyNow()
-{
- mBufferRef->DestroyNow();
-}
-
-void Buffer::Write( void* src, uint32_t srcSize, uint32_t dstOffset )
-{
- // depends whether the buffer is host visible or device local
- // TODO: implement in-GPU copying, for now all buffers are host-visible
- auto transfer = std::make_unique< VulkanAPI::BufferMemoryTransfer >();
- transfer->srcPtr = new char[srcSize];
- memcpy( transfer->srcPtr, src, srcSize );
- transfer->dstBuffer = mBufferRef;
- transfer->dstOffset = dstOffset;
- transfer->srcSize = srcSize;
- mController.ScheduleBufferMemoryTransfer( std::move( transfer ) );
-}
-
-Vulkan::RefCountedBuffer Buffer::GetBufferRef() const
-{
- return mBufferRef;
-}
-
-}
-}
-}
+++ /dev/null
-#ifndef DALI_GRAPHICS_VULKAN_API_BUFFER_H
-#define DALI_GRAPHICS_VULKAN_API_BUFFER_H
-
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics-api/graphics-api-buffer.h>
-#include <dali/graphics/vulkan/internal/vulkan-types.h>
-
-#include <memory>
-
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace VulkanAPI
-{
-class Controller;
-
-/**
- * Buffer represents a Buffer-type resource
- */
-class Buffer : public Graphics::API::Buffer
-{
-public:
-
- explicit Buffer( Controller& controller,
- vk::BufferUsageFlags usage,
- API::Buffer::UsageHint usageHints,
- uint32_t size );
-
- bool Initialise();
-
- /**
- * Maps buffer only when host visible or nullptr when device local
- * @return
- */
- void* Map() override;
-
- /**
- * Unmaps previously accessed buffer
- */
- void Unmap() override;
-
- /**
- * Flushes buffer
- */
- void Flush() override;
-
- /**
- * Destroys buffer immediately with
- */
- void DestroyNow() override;
-
- /**
- * Writes into the buffer
- * @param src
- * @param srcSize
- * @param dstOffset
- */
- void Write( void* src, uint32_t srcSize, uint32_t dstOffset ) override;
-
- Vulkan::RefCountedBuffer GetBufferRef() const;
-
-private:
-
- Controller& mController;
- Vulkan::Graphics& mGraphics;
- vk::BufferUsageFlags mUsage{ vk::BufferUsageFlagBits::eVertexBuffer };
- API::Buffer::UsageHint mUsageHints;
- uint32_t mSize;
-
- Vulkan::RefCountedBuffer mBufferRef;
-};
-}
-} // namespace Graphics
-} // namespace Dali
-#endif // DALI_GRAPHICS_VULKAN_API_BUFFER_H
+++ /dev/null
-/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics/vulkan/api/vulkan-api-controller.h>
-
-#include <dali/graphics/vulkan/vulkan-graphics.h>
-#include <dali/graphics/vulkan/internal/vulkan-buffer.h>
-#include <dali/graphics/vulkan/internal/vulkan-command-buffer.h>
-#include <dali/graphics/vulkan/internal/vulkan-command-pool.h>
-#include <dali/graphics/vulkan/internal/vulkan-framebuffer.h>
-#include <dali/graphics/vulkan/internal/vulkan-surface.h>
-#include <dali/graphics/vulkan/internal/vulkan-sampler.h>
-#include <dali/graphics/vulkan/internal/vulkan-image.h>
-#include <dali/graphics/vulkan/internal/vulkan-image-view.h>
-#include <dali/graphics/vulkan/internal/vulkan-swapchain.h>
-#include <dali/graphics/vulkan/internal/vulkan-debug.h>
-#include <dali/graphics/vulkan/internal/vulkan-fence.h>
-
-// API
-#include <dali/graphics/vulkan/api/vulkan-api-shader.h>
-#include <dali/graphics/vulkan/api/vulkan-api-texture.h>
-#include <dali/graphics/vulkan/api/vulkan-api-buffer.h>
-#include <dali/graphics/vulkan/api/vulkan-api-framebuffer.h>
-#include <dali/graphics/vulkan/api/vulkan-api-texture-factory.h>
-#include <dali/graphics/vulkan/api/vulkan-api-shader-factory.h>
-#include <dali/graphics/vulkan/api/vulkan-api-buffer-factory.h>
-#include <dali/graphics/vulkan/api/vulkan-api-pipeline.h>
-#include <dali/graphics/vulkan/api/vulkan-api-pipeline-factory.h>
-#include <dali/graphics/vulkan/api/vulkan-api-framebuffer-factory.h>
-#include <dali/graphics/vulkan/api/vulkan-api-sampler-factory.h>
-#include <dali/graphics/vulkan/api/vulkan-api-render-command.h>
-#include <dali/graphics/vulkan/api/internal/vulkan-pipeline-cache.h>
-#include <dali/graphics/vulkan/api/internal/vulkan-api-descriptor-set-allocator.h>
-
-#include <dali/graphics/thread-pool.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace VulkanAPI
-{
-namespace DepthStencilFlagBits
-{
-static constexpr uint32_t DEPTH_BUFFER_BIT = 1; // depth buffer enabled
-static constexpr uint32_t STENCIL_BUFFER_BIT = 2; // stencil buffer enabled
-}
-
-// State of the depth-stencil buffer
-using DepthStencilFlags = uint32_t;
-
-struct Controller::Impl
-{
- struct RenderPassData
- {
- // only move semantics
- RenderPassData( vk::RenderPassBeginInfo _beginInfo,
- std::vector< vk::ClearValue >&& _clearColorValues,
- Vulkan::RefCountedFramebuffer _framebuffer )
- : beginInfo( _beginInfo ),
- colorValues( std::move( _clearColorValues ) ),
- framebuffer( std::move( _framebuffer ) ),
- renderCommands()
- {
- }
-
- // no default constructor!
- RenderPassData() = delete;
-
- vk::RenderPassBeginInfo beginInfo{};
- std::vector< vk::ClearValue > colorValues{};
- Vulkan::RefCountedFramebuffer framebuffer{};
- std::vector< Dali::Graphics::API::RenderCommand* > renderCommands;
- };
-
- Impl( Controller& owner, Dali::Graphics::Vulkan::Graphics& graphics )
- : mGraphics( graphics ),
- mOwner( owner ),
- mDepthStencilBufferCurrentState( 0u ),
- mDepthStencilBufferRequestedState( 0u )
- {
- }
-
- ~Impl() = default;
-
- // TODO: @todo this function initialises basic buffers, shaders and pipeline
- // for the prototype ONLY
- bool Initialise()
- {
- // Create factories
- mShaderFactory = MakeUnique< VulkanAPI::ShaderFactory >( mGraphics );
- mTextureFactory = MakeUnique< VulkanAPI::TextureFactory >( mOwner );
- mBufferFactory = MakeUnique< VulkanAPI::BufferFactory >( mOwner );
- mFramebufferFactory = MakeUnique< VulkanAPI::FramebufferFactory >( mOwner );
- mPipelineFactory = MakeUnique< VulkanAPI::PipelineFactory >( mOwner );
- mSamplerFactory = MakeUnique< VulkanAPI::SamplerFactory >( mOwner );
-
- mDefaultPipelineCache = MakeUnique< VulkanAPI::PipelineCache >();
- mDescriptorSetAllocator = MakeUnique< VulkanAPI::Internal::DescriptorSetAllocator>( mOwner );
-
- return mThreadPool.Initialize();
- }
-
- void UpdateDepthStencilBuffer()
- {
- // if we enable depth/stencil dynamically we need to block and invalidate pipeline cache
- // enable depth-stencil
- if( mDepthStencilBufferCurrentState != mDepthStencilBufferRequestedState )
- {
- DALI_LOG_INFO( gLogFilter, Debug::Verbose, "UpdateDepthStencilBuffer(): New state: DEPTH: %d, STENCIL: %d\n", int(mDepthStencilBufferRequestedState&1), int((mDepthStencilBufferRequestedState>>1)&1) );
-
- // Formats
- const std::array<vk::Format, 4> DEPTH_STENCIL_FORMATS = {
- vk::Format::eUndefined, // no depth nor stencil needed
- vk::Format::eD16Unorm, // only depth buffer
- vk::Format::eS8Uint, // only stencil buffer
- vk::Format::eD24UnormS8Uint // depth and stencil buffers
- };
-
- mGraphics.DeviceWaitIdle();
-
- mGraphics.GetSwapchainForFBID(0u)->SetDepthStencil( DEPTH_STENCIL_FORMATS[mDepthStencilBufferRequestedState] );
-
- // make sure GPU finished any pending work
- mGraphics.DeviceWaitIdle();
-
- mDepthStencilBufferCurrentState = mDepthStencilBufferRequestedState;
- }
- }
-
- void AcquireNextFramebuffer()
- {
- // for all swapchains acquire new framebuffer
- auto surface = mGraphics.GetSurface( 0u );
-
- auto swapchain = mGraphics.GetSwapchainForFBID( 0u );
-
- if ( mGraphics.IsSurfaceResized() )
- {
- swapchain->Invalidate();
- }
-
- // We won't run garbage collection in case there are pending resource transfers.
- swapchain->AcquireNextFramebuffer( !mOwner.HasPendingResourceTransfers() );
-
- if( !swapchain->IsValid() )
- {
- // make sure device doesn't do any work before replacing swapchain
- mGraphics.DeviceWaitIdle();
-
- // replace swapchain
- swapchain = mGraphics.ReplaceSwapchainForSurface( surface, std::move(swapchain) );
-
- // get new valid framebuffer
- swapchain->AcquireNextFramebuffer( !mOwner.HasPendingResourceTransfers() );
- }
- }
-
- void CompilePipelines()
- {
- // could be using another thread...could be...
- mDefaultPipelineCache->Compile();
- }
-
- void BeginFrame()
- {
- // Acquire next framebuffer image
- AcquireNextFramebuffer();
-
- // Compile all pipelines that haven't been initialised yet
- CompilePipelines();
-
- mRenderPasses.clear();
- mCurrentFramebuffer.Reset();
- }
-
- void EndFrame()
- {
- // Update descriptor sets if there are any updates
- // swap all swapchains
- auto swapchain = mGraphics.GetSwapchainForFBID( 0u );
-
- if( !mRenderPasses.empty() )
- {
- // Ensure there are enough command buffers for each render pass,
- swapchain->AllocateCommandBuffers( mRenderPasses.size() );
- std::vector<Vulkan::RefCountedCommandBuffer>& renderPassBuffers = swapchain->GetCommandBuffers();
- uint32_t index = 0;
- for( auto& renderPassData : mRenderPasses )
- {
- ProcessRenderPassData( renderPassBuffers[index], renderPassData );
- ++index;
- }
- }
- else
- {
- auto primaryCommandBuffer = swapchain->GetLastCommandBuffer();
- primaryCommandBuffer->Begin( vk::CommandBufferUsageFlagBits::eOneTimeSubmit, nullptr );
- primaryCommandBuffer->BeginRenderPass( vk::RenderPassBeginInfo{}
- .setFramebuffer( swapchain->GetCurrentFramebuffer()->GetVkHandle() )
- .setRenderPass(swapchain->GetCurrentFramebuffer()->GetRenderPass() )
- .setRenderArea( { {0, 0}, { swapchain->GetCurrentFramebuffer()->GetWidth(), swapchain->GetCurrentFramebuffer()->GetHeight() } } )
- .setPClearValues( swapchain->GetCurrentFramebuffer()->GetClearValues().data() )
- .setClearValueCount( uint32_t(swapchain->GetCurrentFramebuffer()->GetClearValues().size()) ), vk::SubpassContents::eInline );
- primaryCommandBuffer->EndRenderPass();
- primaryCommandBuffer->End();
- }
-
- for( auto& future : mMemoryTransferFutures )
- {
- future->Wait();
- future.reset();
- }
-
- mMemoryTransferFutures.clear();
-
- swapchain->Present();
- }
-
- API::TextureFactory& GetTextureFactory() const
- {
- return *( mTextureFactory.get() );
- }
-
- API::ShaderFactory& GetShaderFactory() const
- {
- return *( mShaderFactory.get() );
- }
-
- API::BufferFactory& GetBufferFactory() const
- {
- return *( mBufferFactory.get() );
- }
-
- API::FramebufferFactory& GetFramebufferFactory() const
- {
- mFramebufferFactory->Reset();
- return *( mFramebufferFactory.get() );
- }
-
-
- std::unique_ptr< API::RenderCommand > AllocateRenderCommand()
- {
- return std::make_unique< VulkanAPI::RenderCommand >( mOwner, mGraphics );
- }
-
- void UpdateRenderPass( const std::vector< Dali::Graphics::API::RenderCommand* >& commands, uint32_t startIndex, uint32_t endIndex )
- {
- auto firstCommand = static_cast<VulkanAPI::RenderCommand*>(commands[startIndex]);
- auto renderTargetBinding = firstCommand->GetRenderTargetBinding();
-
- Vulkan::RefCountedFramebuffer framebuffer{ nullptr };
- if( renderTargetBinding.framebuffer )
- {
- framebuffer = static_cast<const VulkanAPI::Framebuffer&>(*renderTargetBinding.framebuffer).GetFramebufferRef();
- }
- else
- {
- // use first surface/swapchain as render target
- auto surface = mGraphics.GetSurface( 0u );
- auto swapchain = mGraphics.GetSwapchainForFBID( 0u );
- framebuffer = swapchain->GetCurrentFramebuffer();
- }
-
- if( framebuffer != mCurrentFramebuffer )
- {
- mCurrentFramebuffer = framebuffer;
-
- // @todo Only do if there is a color attachment and color clear is enabled and there is a clear color
- auto newColors = mCurrentFramebuffer->GetClearValues();
- newColors[0].color.setFloat32( { renderTargetBinding.clearColors[0].r,
- renderTargetBinding.clearColors[0].g,
- renderTargetBinding.clearColors[0].b,
- renderTargetBinding.clearColors[0].a
- } );
-
- mRenderPasses.emplace_back(
- vk::RenderPassBeginInfo{}
- .setRenderPass( mCurrentFramebuffer->GetRenderPass() )
- .setFramebuffer( mCurrentFramebuffer->GetVkHandle() )
- .setRenderArea( vk::Rect2D( { 0, 0 }, { mCurrentFramebuffer->GetWidth(),
- mCurrentFramebuffer->GetHeight() } ) )
- .setClearValueCount( uint32_t( newColors.size() ) )
- .setPClearValues( newColors.data() ),
- std::move( newColors ),
- framebuffer );
-
- }
-
- auto& vector = mRenderPasses.back().renderCommands;
- vector.insert( vector.end(), commands.begin()+int(startIndex), commands.begin()+int(endIndex) );
- }
-
- /**
- * Submits number of commands in one go ( simiar to vkCmdExecuteCommands )
- * @param commands
- */
- void SubmitCommands( std::vector< Dali::Graphics::API::RenderCommand* > commands )
- {
- /*
- * analyze descriptorset needs pers signature
- */
- std::vector<DescriptorSetRequirements> dsRequirements {};
- for( auto& command : commands )
- {
- auto vulkanCommand = static_cast<VulkanAPI::RenderCommand*>( command );
- vulkanCommand->UpdateDescriptorSetAllocationRequirements( dsRequirements, *mDescriptorSetAllocator.get() );
- }
-
- if( !mDescriptorSetsFreeList.empty() )
- {
- mDescriptorSetAllocator->FreeDescriptorSets( std::move( mDescriptorSetsFreeList ) );
- mDescriptorSetsFreeList.clear();
- }
-
- /*
- * Update descriptor pools based on the requirements
- */
- if( dsRequirements.size() )
- {
- mDescriptorSetAllocator->UpdateWithRequirements( dsRequirements, 0u );
- }
-
- /**
- * Allocate descriptor sets for all signatures that requirements forced
- * recreating pools
- */
- for( auto& command : commands )
- {
- auto vulkanCommand = static_cast<VulkanAPI::RenderCommand*>( command );
- vulkanCommand->AllocateDescriptorSets( *mDescriptorSetAllocator );
- }
-
- mMemoryTransferFutures.emplace_back( mThreadPool.SubmitTask(0, Task([this](uint32_t workerIndex){
- // if there are any scheduled writes
- if( !mBufferTransferRequests.empty() )
- {
- for( auto&& req : mBufferTransferRequests )
- {
- void* dst = req->dstBuffer->GetMemory()->Map();
- memcpy( dst, &*req->srcPtr, req->srcSize );
- req->dstBuffer->GetMemory()->Flush();
- req->dstBuffer->GetMemory()->Unmap();
- }
- mBufferTransferRequests.clear();
- }
-
- // execute all scheduled resource transfers
- ProcessResourceTransferRequests();
- })) );
-
- // the list of commands may be empty, but still we may have scheduled memory
- // transfers
- if( commands.empty() )
- {
- return;
- }
-
- // Update render pass data per framebuffer
- const Dali::Graphics::API::Framebuffer* currFramebuffer = nullptr;
- uint32_t previousPassBeginIndex = 0u;
- uint32_t index = 0u;
- for( auto& command : commands )
- {
- if( command->mRenderTargetBinding.framebuffer != currFramebuffer )
- {
- if( index )
- {
- UpdateRenderPass( commands, previousPassBeginIndex, index );
- }
- previousPassBeginIndex = index;
- currFramebuffer = command->mRenderTargetBinding.framebuffer;
- }
- ++index;
- }
- UpdateRenderPass( commands, previousPassBeginIndex, index );
- }
-
- // @todo: possibly optimise
- bool TestCopyRectIntersection( const ResourceTransferRequest* srcRequest, const ResourceTransferRequest* currentRequest )
- {
- auto srcOffset = srcRequest->bufferToImageInfo.copyInfo.imageOffset;
- auto srcExtent = srcRequest->bufferToImageInfo.copyInfo.imageExtent;
-
- auto curOffset = currentRequest->bufferToImageInfo.copyInfo.imageOffset;
- auto curExtent = currentRequest->bufferToImageInfo.copyInfo.imageExtent;
-
- auto offsetX0 = std::min( srcOffset.x, curOffset.x );
- auto offsetY0 = std::min( srcOffset.y, curOffset.y );
- auto offsetX1 = std::max( srcOffset.x+int32_t(srcExtent.width), curOffset.x+int32_t(curExtent.width) );
- auto offsetY1 = std::max( srcOffset.y+int32_t(srcExtent.height), curOffset.y+int32_t(curExtent.height) );
-
- return ( (offsetX1 - offsetX0) < (int32_t(srcExtent.width) + int32_t(curExtent.width)) &&
- (offsetY1 - offsetY0) < (int32_t(srcExtent.height) + int32_t(curExtent.height)) );
-
- }
-
-
- void ProcessResourceTransferRequests( bool immediateOnly = false )
- {
- std::lock_guard<std::recursive_mutex> lock(mResourceTransferMutex);
- if(!mResourceTransferRequests.empty())
- {
- using ResourceTransferRequestList = std::vector<const ResourceTransferRequest*>;
-
- /**
- * Structure associating unique images and lists of transfer requests for which
- * the key image is a destination. It contains separate lists of requests per image.
- * Each list of requests groups non-intersecting copy operations into smaller batches.
- */
- struct ResourceTransferRequestPair
- {
- ResourceTransferRequestPair( const Vulkan::RefCountedImage& key )
- : image( key ), requestList{{}}
- {
- }
-
- Vulkan::RefCountedImage image;
- std::vector<ResourceTransferRequestList> requestList;
- };
-
- // Map of all the requests where 'image' is a key.
- std::vector<ResourceTransferRequestPair> requestMap;
-
- auto highestBatchIndex = 1u;
-
- // Collect all unique destination images and all transfer requests associated with them
- for( const auto& req : mResourceTransferRequests )
- {
- Vulkan::RefCountedImage image { nullptr };
- if( req.requestType == TransferRequestType::BUFFER_TO_IMAGE )
- {
- image = req.bufferToImageInfo.dstImage;
- }
- else if ( req.requestType == TransferRequestType::IMAGE_TO_IMAGE )
- {
- image = req.imageToImageInfo.dstImage;
- }
-
- assert( image );
-
- auto predicate = [&]( auto& item )->bool {
- return image->GetVkHandle() == item.image->GetVkHandle();
- };
- auto it = std::find_if( requestMap.begin(), requestMap.end(), predicate );
-
- if( it == requestMap.end() )
- {
- // initialise new array
- requestMap.emplace_back( image );
- it = requestMap.end()-1;
- }
-
- auto& transfers = it->requestList;
-
- // Compare with current transfer list whether there are any intersections
- // with current image copy area. If intersection occurs, start new list
- auto& currentList = transfers.back();
-
- bool intersects( false );
- for( auto& item : currentList )
- {
- // if area intersects create new list
- if( (intersects = TestCopyRectIntersection( item, &req )) )
- {
- transfers.push_back({});
- highestBatchIndex = std::max( highestBatchIndex, uint32_t(transfers.size()) );
- break;
- }
- }
-
- // push request to the most recently created list
- transfers.back().push_back( &req );
- }
-
- // For all unique images prepare layout transition barriers as all of them must be
- // in eTransferDstOptimal layout
- std::vector<vk::ImageMemoryBarrier> preLayoutBarriers;
- std::vector<vk::ImageMemoryBarrier> postLayoutBarriers;
- for( auto& item : requestMap )
- {
- auto image = item.image;
- // add barrier
- preLayoutBarriers.push_back( mGraphics.CreateImageMemoryBarrier( image, image->GetImageLayout(), vk::ImageLayout::eTransferDstOptimal ) );
- postLayoutBarriers.push_back( mGraphics.CreateImageMemoryBarrier( image, vk::ImageLayout::eTransferDstOptimal, vk::ImageLayout::eShaderReadOnlyOptimal ) );
- image->SetImageLayout( vk::ImageLayout::eShaderReadOnlyOptimal );
- }
-
- // Build command buffer for each image until reaching next sync point
- auto commandBuffer = mGraphics.CreateCommandBuffer( true );
-
- // Fence between submissions
- auto fence = mGraphics.CreateFence( {} );
-
- /**
- * The loop iterates through requests for each unique image. It parallelizes
- * transfers to images until end of data in the batch.
- * After submitting copy commands the loop waits for the fence to be signalled
- * and repeats recording for the next batch of transfer requests.
- */
- for( auto i = 0u; i < highestBatchIndex; ++i )
- {
- commandBuffer->Begin( vk::CommandBufferUsageFlagBits::eOneTimeSubmit, nullptr );
-
- // change image layouts only once
- if( i == 0 )
- {
- commandBuffer->PipelineBarrier( vk::PipelineStageFlagBits::eTopOfPipe, vk::PipelineStageFlagBits::eTransfer, {}, {}, {}, preLayoutBarriers );
- }
-
- for( auto& item : requestMap )
- {
- auto& batchItem = item.requestList;
- if( batchItem.size() <= i )
- {
- continue;
- }
-
- auto& requestList = batchItem[i];
-
- // record all copy commands for this batch
- for( auto& req : requestList )
- {
- if( req->requestType == TransferRequestType::BUFFER_TO_IMAGE )
- {
- commandBuffer->CopyBufferToImage( req->bufferToImageInfo.srcBuffer,
- req->bufferToImageInfo.dstImage, vk::ImageLayout::eTransferDstOptimal,
- { req->bufferToImageInfo.copyInfo } );
-
- }
- else if( req->requestType == TransferRequestType::IMAGE_TO_IMAGE )
- {
- commandBuffer->CopyImage( req->imageToImageInfo.srcImage, vk::ImageLayout::eTransferSrcOptimal,
- req->imageToImageInfo.dstImage, vk::ImageLayout::eTransferDstOptimal,
- { req->imageToImageInfo.copyInfo });
- }
- }
- }
-
- // if this is the last batch restore original layouts
- if( i == highestBatchIndex - 1 )
- {
- commandBuffer->PipelineBarrier( vk::PipelineStageFlagBits::eTransfer, vk::PipelineStageFlagBits::eFragmentShader, {}, {}, {}, postLayoutBarriers );
- }
- commandBuffer->End();
-
- // submit to the queue
- mGraphics.Submit( mGraphics.GetTransferQueue(0u), { Vulkan::SubmissionData{ {}, {}, { commandBuffer }, {} } }, fence );
- mGraphics.WaitForFence( fence );
- mGraphics.ResetFence( fence );
- }
-
- // Destroy staging resources immediately
- for( auto& request : mResourceTransferRequests )
- {
- if( request.requestType == TransferRequestType::BUFFER_TO_IMAGE )
- {
- auto& buffer = request.bufferToImageInfo.srcBuffer;
- assert( buffer.GetRefCount() == 1 );
- buffer->DestroyNow();
- }
- else if( request.requestType == TransferRequestType::IMAGE_TO_IMAGE )
- {
- auto& image = request.imageToImageInfo.srcImage;
- assert( image.GetRefCount() == 1 );
- image->DestroyNow();
- }
- }
-
- // Clear transfer queue
- mResourceTransferRequests.clear();
- }
- }
-
- void InvalidateSwapchain()
- {
- auto swapchain = mGraphics.GetSwapchainForFBID( 0u );
- swapchain->Invalidate();
- }
-
- void ProcessRenderPassData( Vulkan::RefCountedCommandBuffer commandBuffer, const RenderPassData& renderPassData )
- {
- commandBuffer->Begin( vk::CommandBufferUsageFlagBits::eOneTimeSubmit, nullptr );
- commandBuffer->BeginRenderPass( renderPassData.beginInfo, vk::SubpassContents::eInline );
-
- // update descriptor sets
- for( auto&& command : renderPassData.renderCommands )
- {
- auto apiCommand = static_cast<VulkanAPI::RenderCommand*>(command);
- apiCommand->PrepareResources();
- }
-
- if( mDescriptorWrites.size() )
- {
- mGraphics.GetDevice().updateDescriptorSets( uint32_t( mDescriptorWrites.size() ), mDescriptorWrites.data(), 0, nullptr );
- mDescriptorWrites.clear();
- mDescriptorInfoStack.clear();
- }
-
- for( auto&& command : renderPassData.renderCommands )
- {
-#if defined(DEBUG_ENABLED)
- if( getenv( "LOG_VULKAN_API" ) )
- {
- DALI_LOG_STREAM( gVulkanFilter, Debug::General, *command );
- }
-#endif
-
- auto apiCommand = static_cast<VulkanAPI::RenderCommand*>(command);
-
- // skip if there's no valid pipeline
- if( !apiCommand->GetVulkanPipeline() )
- {
- continue;
- }
-
- apiCommand->BindPipeline( commandBuffer );
-
- //@todo add assert to check the pipeline render pass nad the inherited render pass are the same
-
- // set dynamic state
- if( apiCommand->mDrawCommand.scissorTestEnable )
- {
- vk::Rect2D scissorRect( { apiCommand->mDrawCommand.scissor.x,
- apiCommand->mDrawCommand.scissor.y },
- { apiCommand->mDrawCommand.scissor.width,
- apiCommand->mDrawCommand.scissor.height } );
-
- commandBuffer->SetScissor( 0, 1, &scissorRect );
- }
-
- // dynamic state: viewport
- auto vulkanApiPipeline = static_cast<const VulkanAPI::Pipeline*>(apiCommand->GetPipeline());
-
- auto dynamicStateMask = vulkanApiPipeline->GetDynamicStateMask();
- if( (dynamicStateMask & API::PipelineDynamicStateBits::VIEWPORT_BIT) && apiCommand->mDrawCommand.viewportEnable )
- {
- auto viewportRect = apiCommand->mDrawCommand.viewport;
-
- vk::Viewport viewport( viewportRect.x,
- viewportRect.y,
- viewportRect.width,
- viewportRect.height,
- viewportRect.minDepth,
- viewportRect.maxDepth );
-
- commandBuffer->SetViewport( 0, 1, &viewport );
- }
-
- // bind vertex buffers
- auto binding = 0u;
- for( auto&& vb : apiCommand->GetVertexBufferBindings() )
- {
- commandBuffer->BindVertexBuffer( binding++, static_cast<const VulkanAPI::Buffer&>( *vb ).GetBufferRef(), 0 );
- }
-
- // note: starting set = 0
- const auto& descriptorSets = apiCommand->GetDescriptorSets();
- commandBuffer->BindDescriptorSets( descriptorSets, vulkanApiPipeline->GetVkPipelineLayout(), 0, uint32_t( descriptorSets.size() ) );
-
- // draw
- const auto& drawCommand = apiCommand->GetDrawCommand();
-
- const auto& indexBinding = apiCommand->GetIndexBufferBinding();
- if( indexBinding.buffer )
- {
- commandBuffer->BindIndexBuffer( static_cast<const VulkanAPI::Buffer&>(*indexBinding.buffer).GetBufferRef(),
- 0, vk::IndexType::eUint16 );
- commandBuffer->DrawIndexed( drawCommand.indicesCount,
- drawCommand.instanceCount,
- drawCommand.firstIndex,
- 0,
- drawCommand.firstInstance );
- }
- else
- {
- commandBuffer->Draw( drawCommand.vertexCount,
- drawCommand.instanceCount,
- drawCommand.firstVertex,
- drawCommand.firstInstance );
- }
- }
-
- commandBuffer->EndRenderPass();
- commandBuffer->End();
- }
-
- bool EnableDepthStencilBuffer( bool enableDepth, bool enableStencil )
- {
- mDepthStencilBufferRequestedState = ( enableDepth ? DepthStencilFlagBits::DEPTH_BUFFER_BIT : 0u ) |
- ( enableStencil ? DepthStencilFlagBits::STENCIL_BUFFER_BIT : 0u );
-
- auto retval = mDepthStencilBufferRequestedState != mDepthStencilBufferCurrentState;
-
- UpdateDepthStencilBuffer();
-
- return retval;
- }
-
- void RunGarbageCollector( size_t numberOfDiscardedRenderers )
- {
- // @todo Decide what GC's to run.
- }
-
- void DiscardUnusedResources()
- {
- mGraphics.GetGraphicsQueue(0).GetVkHandle().waitIdle();
-
- mGraphics.GetSwapchainForFBID(0)->ResetAllCommandBuffers();
-
- mGraphics.CollectGarbage();
-
- mDescriptorSetAllocator->InvalidateAllDescriptorSets();
- }
-
- bool IsDiscardQueueEmpty()
- {
- return mGraphics.GetDiscardQueue(0u).empty() && mGraphics.GetDiscardQueue(1u).empty();
- }
-
- void SwapBuffers()
- {
- mGraphics.SwapBuffers();
- }
-
- uint32_t GetSwapchainBufferCount()
- {
- return mGraphics.GetSwapchainForFBID(0u)->GetImageCount();
- }
-
- std::unique_ptr< PipelineCache > mDefaultPipelineCache;
- std::unique_ptr< VulkanAPI::Internal::DescriptorSetAllocator > mDescriptorSetAllocator;
-
- Vulkan::Graphics& mGraphics;
- Controller& mOwner;
-
- std::unique_ptr< VulkanAPI::TextureFactory > mTextureFactory;
- std::unique_ptr< VulkanAPI::ShaderFactory > mShaderFactory;
- std::unique_ptr< VulkanAPI::BufferFactory > mBufferFactory;
- std::unique_ptr< VulkanAPI::PipelineFactory > mPipelineFactory;
- std::unique_ptr< VulkanAPI::FramebufferFactory > mFramebufferFactory;
- std::unique_ptr< VulkanAPI::SamplerFactory > mSamplerFactory;
-
- // used for UBOs
- std::vector< std::unique_ptr< VulkanAPI::BufferMemoryTransfer > > mBufferTransferRequests;
-
- // used for texture<->buffer<->memory transfers
- std::vector< ResourceTransferRequest > mResourceTransferRequests;
-
- Vulkan::RefCountedFramebuffer mCurrentFramebuffer;
- std::vector< RenderPassData > mRenderPasses;
-
- ThreadPool mThreadPool;
-
- std::vector< std::shared_ptr< Future<void> > > mMemoryTransferFutures;
-
- std::vector<vk::WriteDescriptorSet> mDescriptorWrites;
-
- struct DescriptorInfo
- {
- vk::DescriptorImageInfo imageInfo;
- vk::DescriptorBufferInfo bufferInfo;
- };
-
- std::deque<DescriptorInfo> mDescriptorInfoStack;
-
- std::mutex mDescriptorWriteMutex{};
- std::recursive_mutex mResourceTransferMutex{};
-
- DepthStencilFlags mDepthStencilBufferCurrentState { 0u };
- DepthStencilFlags mDepthStencilBufferRequestedState { 0u };
-
- std::vector<DescriptorSetList> mDescriptorSetsFreeList;
-
- uint32_t mBufferIndex{0u};
- bool mDrawOnResume{ false };
-};
-
-// TODO: @todo temporarily ignore missing return type, will be fixed later
-
-std::unique_ptr< API::Shader > Controller::CreateShader( const API::BaseFactory< API::Shader >& factory )
-{
- return factory.Create();
-}
-
-std::unique_ptr< API::Texture > Controller::CreateTexture( const API::BaseFactory< API::Texture >& factory )
-{
- return factory.Create();
-}
-
-std::unique_ptr< API::Buffer > Controller::CreateBuffer( const API::BaseFactory< API::Buffer >& factory )
-{
- return factory.Create();
-}
-
-std::unique_ptr< API::Sampler > Controller::CreateSampler( const API::BaseFactory< API::Sampler >& factory )
-{
- return factory.Create();
-}
-
-std::unique_ptr< API::Pipeline > Controller::CreatePipeline( const API::PipelineFactory& factory )
-{
- auto& pipelineFactory = const_cast<PipelineFactory&>(dynamic_cast<const PipelineFactory&>( factory ));
-
- // if no custom cache, use default one
- if( !pipelineFactory.mPipelineCache )
- {
- pipelineFactory.mPipelineCache = mImpl->mDefaultPipelineCache.get();
- }
-
- return mImpl->mPipelineFactory->Create();
-}
-
-std::unique_ptr< API::Framebuffer > Controller::CreateFramebuffer( const API::BaseFactory< API::Framebuffer >& factory )
-{
- return factory.Create();
-}
-
-std::unique_ptr< Controller > Controller::New( Vulkan::Graphics& vulkanGraphics )
-{
- return std::make_unique< Controller >( vulkanGraphics );
-}
-
-Controller::Controller( Vulkan::Graphics& vulkanGraphics ) : mImpl( std::make_unique< Impl >( *this, vulkanGraphics ) )
-{
-}
-
-void Controller::Initialise()
-{
- mImpl->Initialise();
-}
-
-Controller::~Controller() = default;
-
-Controller::Controller() = default;
-
-Controller& Controller::operator=( Controller&& ) noexcept = default;
-
-void Controller::BeginFrame()
-{
- mImpl->mDrawOnResume = false;
- mStats.samplerTextureBindings = 0;
- mStats.uniformBufferBindings = 0;
-
- //@ todo, not multithreaded yet
- mImpl->mDescriptorWrites.clear();
-
- mStats.frame++;
- mImpl->BeginFrame();
-}
-
-void Controller::PushDescriptorWrite( const vk::WriteDescriptorSet& write )
-{
- vk::DescriptorImageInfo* pImageInfo { nullptr };
- vk::DescriptorBufferInfo* pBufferInfo { nullptr };
- std::lock_guard<std::mutex> lock( mImpl->mDescriptorWriteMutex );
- if( write.pImageInfo )
- {
- mImpl->mDescriptorInfoStack.emplace_back();
- mImpl->mDescriptorInfoStack.back().imageInfo = *write.pImageInfo;
- pImageInfo = &mImpl->mDescriptorInfoStack.back().imageInfo;
- }
- else if( write.pBufferInfo )
- {
- mImpl->mDescriptorInfoStack.emplace_back();
- mImpl->mDescriptorInfoStack.back().bufferInfo = *write.pBufferInfo;
- pBufferInfo = &mImpl->mDescriptorInfoStack.back().bufferInfo;
- }
- mImpl->mDescriptorWrites.emplace_back( write );
- mImpl->mDescriptorWrites.back().pBufferInfo = pBufferInfo;
- mImpl->mDescriptorWrites.back().pImageInfo = pImageInfo;
-}
-
-void Controller::FreeDescriptorSets( DescriptorSetList&& descriptorSetList )
-{
- if( descriptorSetList.descriptorSets.empty() )
- {
- return;
- }
- mImpl->mDescriptorSetsFreeList.emplace_back( std::move( descriptorSetList ) );
-}
-
-bool Controller::TestDescriptorSetsValid( VulkanAPI::DescriptorSetList& descriptorSetList, std::vector<bool>& results ) const
-{
- return mImpl->mDescriptorSetAllocator->TestIfValid( descriptorSetList, results );
-}
-
-void Controller::EndFrame()
-{
- mImpl->EndFrame();
-
-#if(DEBUG_ENABLED)
- // print stats
- PrintStats();
-#endif
-}
-
-void Controller::PrintStats()
-{
- DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Frame: %d\n", int(mStats.frame));
- DALI_LOG_INFO( gLogFilter, Debug::Verbose, " UBO bindings: %d\n", int(mStats.uniformBufferBindings));
- DALI_LOG_INFO( gLogFilter, Debug::Verbose, " Tex bindings: %d\n", int(mStats.samplerTextureBindings));
-}
-
-void Controller::Pause()
-{
-}
-
-void Controller::Resume()
-{
- // Ensure we re-draw at least once:
- mImpl->mDrawOnResume = true;
-}
-
-API::TextureFactory& Controller::GetTextureFactory() const
-{
- return mImpl->GetTextureFactory();
-}
-
-API::ShaderFactory& Controller::GetShaderFactory() const
-{
- return mImpl->GetShaderFactory();
-}
-
-API::BufferFactory& Controller::GetBufferFactory() const
-{
- return mImpl->GetBufferFactory();
-}
-
-API::FramebufferFactory& Controller::GetFramebufferFactory() const
-{
- return mImpl->GetFramebufferFactory();
-}
-
-API::PipelineFactory& Controller::GetPipelineFactory()
-{
- mImpl->mPipelineFactory->Reset();
- return *mImpl->mPipelineFactory;
-}
-
-API::SamplerFactory& Controller::GetSamplerFactory()
-{
- return mImpl->mSamplerFactory->Reset();
-}
-
-Vulkan::Graphics& Controller::GetGraphics() const
-{
- return mImpl->mGraphics;
-}
-
-void Controller::ScheduleBufferMemoryTransfer( std::unique_ptr< VulkanAPI::BufferMemoryTransfer > transferRequest )
-{
- mImpl->mBufferTransferRequests.emplace_back( std::move( transferRequest ) );
-}
-
-void Controller::ScheduleResourceTransfer( VulkanAPI::ResourceTransferRequest&& transferRequest )
-{
- std::lock_guard<std::recursive_mutex> lock(mImpl->mResourceTransferMutex);
- mImpl->mResourceTransferRequests.emplace_back( std::move(transferRequest) );
-
- // if we requested immediate upload then request will be processed instantly with skipping
- // all the deferred update requests
- if( !mImpl->mResourceTransferRequests.back().deferredTransferMode )
- {
- mImpl->ProcessResourceTransferRequests( true );
- }
-}
-
-bool Controller::HasPendingResourceTransfers() const
-{
- return !mImpl->mResourceTransferRequests.empty();
-}
-
-void Controller::SubmitCommands( std::vector< API::RenderCommand* > commands )
-{
- mImpl->SubmitCommands( std::move( commands ) );
-}
-
-std::unique_ptr< API::RenderCommand > Controller::AllocateRenderCommand()
-{
- return mImpl->AllocateRenderCommand();
-}
-
-bool Controller::EnableDepthStencilBuffer( bool enableDepth, bool enableStencil )
-{
- return mImpl->EnableDepthStencilBuffer( enableDepth, enableStencil );
-}
-
-void Controller::RunGarbageCollector( size_t numberOfDiscardedRenderers )
-{
- mImpl->RunGarbageCollector( numberOfDiscardedRenderers );
-}
-
-void Controller::DiscardUnusedResources()
-{
- mImpl->DiscardUnusedResources();
-}
-
-bool Controller::IsDiscardQueueEmpty()
-{
- return mImpl->IsDiscardQueueEmpty();
-}
-
-bool Controller::IsDrawOnResumeRequired()
-{
- return mImpl->mDrawOnResume;
-}
-
-void Controller::WaitIdle()
-{
- mImpl->mGraphics.GetGraphicsQueue(0u).GetVkHandle().waitIdle();
-}
-
-void Controller::SwapBuffers()
-{
- mImpl->SwapBuffers();
-}
-
-uint32_t Controller::GetSwapchainBufferCount()
-{
- return mImpl->GetSwapchainBufferCount();
-}
-
-uint32_t Controller::GetCurrentBufferIndex()
-{
- return mImpl->mGraphics.GetCurrentBufferIndex();
-}
-
-} // namespace VulkanAPI
-} // namespace Graphics
-} // namespace Dali
+++ /dev/null
-#ifndef DALI_GRAPHICS_VULKAN_API_CONTROLLER_H
-#define DALI_GRAPHICS_VULKAN_API_CONTROLLER_H
-
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// INTERNAL INCLUDES
-#include <dali/graphics-api/graphics-api-controller.h>
-#include <dali/graphics/vulkan/internal/vulkan-buffer.h>
-#include <dali/graphics/vulkan/internal/vulkan-image.h>
-#include <dali/graphics/vulkan/internal/vulkan-types.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-
-namespace Vulkan
-{
-class Graphics;
-class Buffer;
-class Image;
-}
-
-namespace VulkanAPI
-{
-class Controller;
-class UboManager;
-class DescriptorSetList;
-
-/**
- * Structure describes deferred memory transfer
- * Source memory is owned by the buffer and will be discarded
- * when transfer is completed
- */
-struct BufferMemoryTransfer
-{
- BufferMemoryTransfer() = default;
-
- ~BufferMemoryTransfer()
- {
- delete [] srcPtr;
- }
-
- char* srcPtr{ nullptr };
- uint32_t srcSize{ 0u };
-
- Vulkan::RefCountedBuffer dstBuffer;
- uint32_t dstOffset{ 0u };
-};
-
-enum class TransferRequestType
-{
- BUFFER_TO_IMAGE,
- IMAGE_TO_IMAGE,
- BUFFER_TO_BUFFER,
- IMAGE_TO_BUFFER,
- UNDEFINED
-};
-
-/**
- * Structure describing blitting request Buffer to Image
- */
-struct ResourceTransferRequest
-{
- ResourceTransferRequest( TransferRequestType type )
- : requestType( type )
- {}
-
- TransferRequestType requestType;
-
- struct
- {
- Vulkan::RefCountedBuffer srcBuffer { nullptr }; /// Source buffer
- Vulkan::RefCountedImage dstImage { nullptr }; /// Destination image
- vk::BufferImageCopy copyInfo { }; /// Vulkan specific copy info
- } bufferToImageInfo;
-
- struct
- {
- Vulkan::RefCountedImage srcImage { nullptr }; /// Source image
- Vulkan::RefCountedImage dstImage { nullptr }; /// Destination image
- vk::ImageCopy copyInfo { }; /// Vulkan specific copy info
- } imageToImageInfo;
-
- bool deferredTransferMode{ true }; // Vulkan implementation prefers deferred mode
-
- // delete copy
- ResourceTransferRequest( const ResourceTransferRequest& ) = delete;
- ResourceTransferRequest& operator=( const ResourceTransferRequest& ) = delete;
- ResourceTransferRequest& operator=( ResourceTransferRequest&& obj ) = delete;
-
- ResourceTransferRequest( ResourceTransferRequest&& obj )
- {
- requestType = obj.requestType;
- deferredTransferMode = obj.deferredTransferMode;
-
- if( requestType == TransferRequestType::BUFFER_TO_IMAGE )
- {
- bufferToImageInfo.srcBuffer = std::move( obj.bufferToImageInfo.srcBuffer );
- bufferToImageInfo.dstImage = std::move( obj.bufferToImageInfo.dstImage );
- bufferToImageInfo.copyInfo = std::move( obj.bufferToImageInfo.copyInfo );
- }
- else if( requestType == TransferRequestType::IMAGE_TO_IMAGE )
- {
- imageToImageInfo.srcImage = std::move( obj.imageToImageInfo.srcImage );
- imageToImageInfo.dstImage = std::move( obj.imageToImageInfo.dstImage );
- imageToImageInfo.copyInfo = std::move( obj.imageToImageInfo.copyInfo );
- }
- }
-
-};
-
-/**
- * @brief Interface class for Manager types in the graphics API.
- */
-class Controller : public Dali::Graphics::API::Controller
-{
-public:
-
- explicit Controller( Vulkan::Graphics& vulkanGraphics );
-
- void Initialise();
-
- /**
- * Must be created from VulkanGraphics
- * @param vulkanGraphics
- * @return
- */
- static std::unique_ptr< Controller > New( Vulkan::Graphics& vulkanGraphics );
-
- /**
- * @brief Create a new object
- */
- std::unique_ptr< API::Shader > CreateShader( const API::BaseFactory< API::Shader >& factory ) override;
-
- /**
- * @brief Create a new object
- */
- std::unique_ptr< API::Texture > CreateTexture( const API::BaseFactory< API::Texture >& factory ) override;
-
- /**
- * @brief Create a new object
- */
- std::unique_ptr< API::Buffer > CreateBuffer( const API::BaseFactory< API::Buffer >& factory ) override;
-
- /**
- * @brief Create a new object
- */
- std::unique_ptr< API::Sampler > CreateSampler( const API::BaseFactory< API::Sampler >& factory ) override;
-
- /**
- * @brief Create a new object
- */
- std::unique_ptr< API::Pipeline > CreatePipeline( const API::PipelineFactory& factory ) override;
-
- /**
- * @brief Create a new object
- */
- std::unique_ptr< API::Framebuffer > CreateFramebuffer( const API::BaseFactory< API::Framebuffer >& factory ) override;
-
- void SubmitCommands( std::vector< API::RenderCommand* > commands ) override;
-
- std::unique_ptr< API::RenderCommand > AllocateRenderCommand() override;
-
- virtual void BeginFrame() override;
-
- void EndFrame() override;
-
- void Pause() override;
-
- void Resume() override;
-
- bool EnableDepthStencilBuffer( bool enableDepth, bool enableStencil ) override;
-
- void RunGarbageCollector( size_t numberOfDiscardedRenderers ) override;
-
- void DiscardUnusedResources() override;
-
- bool IsDiscardQueueEmpty() override;
-
- bool IsDrawOnResumeRequired() override;
-
- void WaitIdle() override;
-
- void SwapBuffers() override;
-
- uint32_t GetSwapchainBufferCount() override;
-
- // VULKAN only
-
- uint32_t GetCurrentBufferIndex();
-
-public:
-
- Vulkan::Graphics& GetGraphics() const;
-
- void ScheduleBufferMemoryTransfer( std::unique_ptr< VulkanAPI::BufferMemoryTransfer > transferRequest );
-
- void ScheduleResourceTransfer( VulkanAPI::ResourceTransferRequest&& transferRequest );
-
- void PushDescriptorWrite( const vk::WriteDescriptorSet& write );
-
- /**
- * Pushes descriptorsets to be freed by the allocator.
- * The descriptor sets must not be used any more by the renderer
- * @param descriptorSets
- */
- void FreeDescriptorSets( VulkanAPI::DescriptorSetList&& descriptorSetList );
-
- bool TestDescriptorSetsValid( VulkanAPI::DescriptorSetList& descriptorSetList, std::vector<bool>& results ) const;
-
- bool HasPendingResourceTransfers() const;
-
-public:
-
- API::TextureFactory& GetTextureFactory() const override;
-
- API::ShaderFactory& GetShaderFactory() const override;
-
- API::BufferFactory& GetBufferFactory() const override;
-
- API::PipelineFactory& GetPipelineFactory() override;
-
- API::FramebufferFactory& GetFramebufferFactory() const override;
-
- API::SamplerFactory& GetSamplerFactory() override;
-
-public:
- // not copyable
- Controller( const Controller& ) = delete;
-
- Controller& operator=( const Controller& ) = delete;
-
- ~Controller() override;
-
-protected:
- // derived types should not be moved direcly to prevent slicing
- Controller( Controller&& ) noexcept = default;
-
- Controller& operator=( Controller&& ) noexcept;
-
- /**
- * Objects of this type should not directly.
- */
- Controller();
-
-private:
- struct Impl;
- std::unique_ptr< Impl > mImpl;
-
-public:
- struct Stats
- {
- uint32_t frame { 0u };
- uint32_t uniformBufferBindings { 0u };
- uint32_t samplerTextureBindings { 0u };
- };
-
- void PrintStats();
-
- Stats mStats;
-};
-
-} // namespace VulkanAPI
-} // namespace Graphics
-} // namespace Dali
-
-#endif // DALI_GRAPHICS_VULKAN_API_CONTROLLER_H
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics/vulkan/api/vulkan-api-framebuffer-factory.h>
-#include <dali/graphics/vulkan/api/vulkan-api-framebuffer.h>
-#include <dali/graphics/vulkan/vulkan-graphics.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace VulkanAPI
-{
-
-
-FramebufferFactory::FramebufferFactory( Controller& controller )
-: mController( controller ),
- mWidth(0u),
- mHeight(0u),
- mColorAttachments(),
- mDepthStencilAttachment()
-{
-}
-
-FramebufferFactory::~FramebufferFactory() = default;
-
-void FramebufferFactory::Reset()
-{
- mWidth=0;
- mHeight=0;
- mColorAttachments.clear();
- mDepthStencilAttachment.texture = nullptr;
-}
-
-Graphics::API::FramebufferFactory& FramebufferFactory::SetSize(const API::RectSize& size)
-{
- mWidth = uint32_t(size.width);
- mHeight = uint32_t(size.height);
- return *this;
-}
-
-/**
- * Set a color attachment for the framebuffer
- */
-Graphics::API::FramebufferFactory& FramebufferFactory::SetColorAttachment(
- Graphics::API::TextureDetails::AttachmentId attachmentIndex,
- const Graphics::API::Texture& texture,
- Graphics::API::TextureDetails::LayerId layer,
- Graphics::API::TextureDetails::LevelId level )
-{
- if( mColorAttachments.size() <= attachmentIndex )
- {
- mColorAttachments.resize( attachmentIndex+1 );
- }
- mColorAttachments[attachmentIndex] = ColorAttachment{ &texture, layer, level };
-
- return *this;
-}
-
-/**
- * Set a depth attachment for the framebuffer
- */
-Graphics::API::FramebufferFactory& FramebufferFactory::SetDepthStencilAttachment(
- const Graphics::API::Texture& texture,
- Graphics::API::TextureDetails::LayerId layer,
- Graphics::API::TextureDetails::LevelId level,
- Graphics::API::TextureDetails::DepthStencilFlag depthStencilFlag )
-{
- mDepthStencilAttachment = DepthAttachment{ &texture, layer, level,depthStencilFlag };
-
- return *this;
-}
-
-std::unique_ptr<Graphics::API::Framebuffer> FramebufferFactory::Create() const
-{
- auto retval = std::make_unique<VulkanAPI::Framebuffer>( mController, mWidth, mHeight );
-
- if( retval->Initialise( mColorAttachments, mDepthStencilAttachment ) )
- {
- return std::move( retval );
- }
-
- return nullptr;
-}
-
-
-} // namespace VulkanAPI
-} // namespace Graphics
-} // namespace Dali
+++ /dev/null
-#ifndef DALI_GRAPHICS_VULKAN_API_FRAMEBUFFER_FACTORY_H
-#define DALI_GRAPHICS_VULKAN_API_FRAMEBUFFER_FACTORY_H
-
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics-api/graphics-api-framebuffer-factory.h>
-#include <dali/graphics-api/graphics-api-texture-details.h>
-#include <vector>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-class Graphics;
-}
-namespace VulkanAPI
-{
-class Controller;
-
-/**
- * Implementation of the frame buffer factory
- */
-class FramebufferFactory : public Dali::Graphics::API::FramebufferFactory
-{
-public:
-
- /**
- * Constructor
- */
- explicit FramebufferFactory( Controller& controller );
-
- /**
- * Reset the factory to remove attachments and zero size
- */
- void Reset();
-
- /**
- * Set the size of the framebuffer
- */
- Graphics::API::FramebufferFactory& SetSize( const API::RectSize& size ) override;
-
- /**
- * Set a color attachment for the framebuffer
- */
- Graphics::API::FramebufferFactory& SetColorAttachment(
- Graphics::API::TextureDetails::AttachmentId attachmentIndex,
- const Graphics::API::Texture& texture,
- Graphics::API::TextureDetails::LayerId layer,
- Graphics::API::TextureDetails::LevelId level ) override;
-
- /**
- * Set a depth attachment for the framebuffer
- */
- Graphics::API::FramebufferFactory& SetDepthStencilAttachment(
- const Graphics::API::Texture& texture,
- Graphics::API::TextureDetails::LayerId layer,
- Graphics::API::TextureDetails::LevelId level,
- Graphics::API::TextureDetails::DepthStencilFlag depthStencilFlag ) override;
-
-
- // not copyable
- FramebufferFactory(const FramebufferFactory&) = delete;
- FramebufferFactory& operator=(const FramebufferFactory&) = delete;
-
- ~FramebufferFactory() override;
-
- std::unique_ptr<Graphics::API::Framebuffer> Create() const override;
-
-
-protected:
- /// @brief default constructor
- FramebufferFactory() = default;
-
- // derived types should not be moved direcly to prevent slicing
- FramebufferFactory(FramebufferFactory&&) = default;
- FramebufferFactory& operator=(FramebufferFactory&&) = default;
-
-public:
-
- struct ColorAttachment
- {
- const Graphics::API::Texture* texture;
- Graphics::API::TextureDetails::LayerId layer;
- Graphics::API::TextureDetails::LevelId mipmapLevel;
- };
-
- struct DepthAttachment
- {
- const Graphics::API::Texture* texture;
- Graphics::API::TextureDetails::LayerId layer;
- Graphics::API::TextureDetails::LevelId mipmapLevel;
- Graphics::API::TextureDetails::DepthStencilFlag depthStencilFlag;
- };
-
-private:
- Controller& mController;
-
- uint32_t mWidth;
- uint32_t mHeight;
-
- std::vector< ColorAttachment > mColorAttachments;
- DepthAttachment mDepthStencilAttachment;
-};
-
-}
-}
-}
-
-#endif //DALI_GRAPHICS_VULKAN_API_FRAMEBUFFER_FACTORY_H
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// CLASS INCLUDE
-#include <dali/graphics/vulkan/api/vulkan-api-framebuffer.h>
-#include <dali/graphics/vulkan/internal/vulkan-image-view.h>
-
-// INTERNAL INCLUDES
-#include <dali/graphics-api/graphics-api-framebuffer-factory.h>
-#include <dali/graphics-api/graphics-api-framebuffer.h>
-#include <dali/graphics/vulkan/api/vulkan-api-controller.h>
-#include <dali/graphics/vulkan/api/vulkan-api-texture.h>
-#include <dali/graphics/vulkan/internal/vulkan-types.h>
-#include <dali/graphics/vulkan/internal/vulkan-framebuffer.h>
-#include <dali/graphics/vulkan/vulkan-graphics.h>
-
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace VulkanAPI
-{
-
-Framebuffer::Framebuffer( Controller& controller, uint32_t width, uint32_t height )
-
-: mController( controller ),
- mWidth( width ),
- mHeight( height )
-{
-}
-
-Framebuffer::~Framebuffer()
-{
-}
-
-bool Framebuffer::Initialise( const std::vector<FramebufferFactory::ColorAttachment>& colorAttachments,
- const FramebufferFactory::DepthAttachment& depthAttachment )
-{
- std::vector< Vulkan::RefCountedFramebufferAttachment > colorAttachmentObjects;
- Vulkan::RefCountedFramebufferAttachment depthAttachmentObject;
-
- for( auto&& element : colorAttachments )
- {
- assert( element.texture != nullptr );
- auto texture = static_cast<const VulkanAPI::Texture*>( element.texture );
-
- // @todo handle mipmap level and cubemap
- auto imageView = texture->GetImageViewRef();
-
- // @todo Get a clear color from API.
- auto clearColor = vk::ClearColorValue{}.setFloat32( { 1.0f, 0.0f, 1.0f, 1.0f } );
- colorAttachmentObjects.push_back( Vulkan::FramebufferAttachment::NewColorAttachment( imageView, clearColor, false ) );
- }
-
- if( depthAttachment.texture != nullptr )
- {
- auto texture = dynamic_cast<const VulkanAPI::Texture *>( depthAttachment.texture );
- if( texture )
- {
- // @todo handle mipmap level and cubemap
- auto imageView = texture->GetImageViewRef();
-
- // @todo Get a clear color from API.
- auto depthClearValue = vk::ClearDepthStencilValue{}
- .setDepth( 0.0f )
- .setStencil( STENCIL_DEFAULT_CLEAR_VALUE );
- depthAttachmentObject = Vulkan::FramebufferAttachment::NewDepthAttachment( imageView, depthClearValue );
- }
- }
-
- mFramebufferRef = mController.GetGraphics().CreateFramebuffer( colorAttachmentObjects,
- depthAttachmentObject,
- mWidth,
- mHeight );
-
- return true;
-}
-
-Vulkan::RefCountedFramebuffer Framebuffer::GetFramebufferRef() const
-{
- return mFramebufferRef;
-}
-
-} // namespace VulkanAPI
-} // namespace Graphics
-} // namespace Dali
+++ /dev/null
-#ifndef DALI_GRAPHICS_VULKAN_API_FRAMEBUFFER_H
-#define DALI_GRAPHICS_VULKAN_API_FRAMEBUFFER_H
-
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// INTERNAL INCLUDES
-#include <dali/graphics-api/graphics-api-framebuffer-factory.h>
-#include <dali/graphics-api/graphics-api-framebuffer.h>
-#include <dali/graphics/vulkan/internal/vulkan-types.h>
-#include <dali/graphics/vulkan/api/vulkan-api-framebuffer-factory.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace VulkanAPI
-{
-class Controller;
-
-/**
- * Framebuffer implementation
- */
-class Framebuffer : public Dali::Graphics::API::Framebuffer
-{
-public:
-
- explicit Framebuffer( Controller& controller, uint32_t width, uint32_t height );
-
- ~Framebuffer() override;
-
- bool Initialise( const std::vector<FramebufferFactory::ColorAttachment>& colorAttachments,
- const FramebufferFactory::DepthAttachment& depthAttachment );
-
- Vulkan::RefCountedFramebuffer GetFramebufferRef() const;
-
-private:
- Controller& mController;
- uint32_t mWidth;
- uint32_t mHeight;
-
- Vulkan::RefCountedFramebuffer mFramebufferRef;
-};
-
-} // namespace VulkanAPI
-} // namespace Graphics
-} // namespace Dali
-#endif // DALI_GRAPHICS_VULKAN_API_FRAMEBUFFER_H
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics/vulkan/api/vulkan-api-pipeline-factory.h>
-#include <dali/graphics/vulkan/api/internal/vulkan-pipeline-cache.h>
-#include <dali/graphics/vulkan/api/vulkan-api-pipeline.h>
-#include <dali/graphics/vulkan/api/vulkan-api-controller.h>
-#include <dali/graphics/vulkan/internal/vulkan-framebuffer.h>
-#include <dali/graphics/vulkan/internal/vulkan-swapchain.h>
-#include <dali/graphics/vulkan/vulkan-graphics.h>
-#include <dali/graphics/vulkan/api/vulkan-api-framebuffer.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace VulkanAPI
-{
-
-namespace
-{
-/**
- * Hashing binary data, it may not be the best algorithm
- * @return
- */
-uint32_t HashBinary( const void* dataObj, uint32_t size )
-{
- const uint8_t* data = reinterpret_cast<const uint8_t*>(dataObj);
- uint32_t hash = 5381u;
- uint32_t c;
- for( uint32_t i = 0; i < size; ++i )
- {
- c = *data++;
- hash = ( ( hash << 5 ) + hash ) + c; /* hash * 33 + c */
- }
- return hash;
-}
-
-uint32_t HashPipeline( const VulkanAPI::PipelineFactory& factory )
-{
- const VulkanAPI::PipelineFactory::Info& info = factory.mInfo;
-
- // Obtain renderpass as it is a part of the hashed value
- const auto renderPass = info.framebufferState.framebuffer ? static_cast<const VulkanAPI::Framebuffer*>(info.framebufferState.framebuffer)->GetFramebufferRef()->GetRenderPass() :
- factory.mGraphics.GetSwapchainForFBID( 0u )->GetCurrentFramebuffer()->GetRenderPass();
-
- uint32_t dsHash = HashBinary( &info.depthStencilState, sizeof( info.depthStencilState ) );
- uint32_t cbHash = HashBinary( &info.colorBlendState, sizeof( info.colorBlendState ) );
- uint32_t shHash = HashBinary( &info.shaderState, sizeof( info.shaderState ) );
- uint32_t vpHash = HashBinary( &info.viewportState, sizeof( info.viewportState ) );
- uint32_t fbHash = HashBinary( &info.framebufferState, sizeof( info.framebufferState ) );
- uint32_t rsHash = HashBinary( &info.rasterizationState, sizeof( info.rasterizationState ) );
- uint32_t iaHash = HashBinary( &info.inputAssemblyState, sizeof( info.inputAssemblyState ) );
-
- // vertex input contains std containers so has to be hashed differently
- uint32_t viStateBindingsHash = HashBinary( info.vertexInputState.bufferBindings.data(), uint32_t(
- sizeof( API::VertexInputState::Binding ) * info.vertexInputState.bufferBindings.size() ) );
- uint32_t viStateAttributesHash = HashBinary( info.vertexInputState.attributes.data(), uint32_t(
- sizeof( API::VertexInputState::Attribute ) * info.vertexInputState.attributes.size() ) );
-
- // rehash all
- std::array< uint32_t, 11 > allHashes = {
- dsHash, cbHash, shHash, vpHash, fbHash, rsHash, iaHash, viStateBindingsHash, viStateAttributesHash, info.dynamicStateMask,
- uint32_t( uintptr_t( static_cast<const VkRenderPass>(renderPass) ) )
- };
-
- return HashBinary( allHashes.data(), uint32_t( allHashes.size() * sizeof( uint32_t ) ) );
-}
-
-}
-
-PipelineFactory::PipelineFactory( Controller& controller )
- : mController( controller ),
- mGraphics( controller.GetGraphics() ),
- mHashCode( 0u )
-{
-}
-
-API::PipelineFactory& PipelineFactory::SetPipelineCache( VulkanAPI::PipelineCache& pipelineCache )
-{
- mPipelineCache = dynamic_cast<VulkanAPI::PipelineCache*>(&pipelineCache);
- return *this;
-}
-
-
-API::PipelineFactory& PipelineFactory::SetColorBlendState( const API::ColorBlendState& state )
-{
- mInfo.colorBlendState = state;
- mHashCode = 0u;
- return *this;
-}
-
-
-API::PipelineFactory& PipelineFactory::SetShaderState( const API::ShaderState& state )
-{
- mInfo.shaderState = state;
- mHashCode = 0u;
- return *this;
-}
-
-API::PipelineFactory& PipelineFactory::SetViewportState( const API::ViewportState& state )
-{
- mInfo.viewportState = state;
- mHashCode = 0u;
- return *this;
-}
-
-API::PipelineFactory& PipelineFactory::SetFramebufferState( const API::FramebufferState& state )
-{
- mInfo.framebufferState = state;
- mHashCode = 0u;
- return *this;
-}
-
-API::PipelineFactory& PipelineFactory::SetBasePipeline( API::Pipeline& pipeline )
-{
- mBasePipeline = dynamic_cast<VulkanAPI::Pipeline*>(&pipeline);
- mHashCode = 0u;
- return *this;
-}
-
-API::PipelineFactory& PipelineFactory::SetDepthStencilState( API::DepthStencilState state )
-{
- mInfo.depthStencilState = state;
- mHashCode = 0u;
- return *this;
-}
-
-API::PipelineFactory& PipelineFactory::SetRasterizationState( const API::RasterizationState& state )
-{
- mInfo.rasterizationState = state;
- mHashCode = 0u;
- return *this;
-}
-
-API::PipelineFactory& PipelineFactory::SetVertexInputState( const API::VertexInputState& state )
-{
- mInfo.vertexInputState = state;
- mHashCode = 0u;
- return *this;
-}
-
-API::PipelineFactory& PipelineFactory::SetInputAssemblyState( const API::InputAssemblyState& state )
-{
- mInfo.inputAssemblyState = state;
- mHashCode = 0u;
- return *this;
-}
-
-API::PipelineFactory& PipelineFactory::SetDynamicStateMask( const API::PipelineDynamicStateMask mask )
-{
- mInfo.dynamicStateMask = mask;
- mHashCode = 0;
- return *this;
-}
-
-API::PipelineFactory& PipelineFactory::SetOldPipeline( std::unique_ptr<API::Pipeline> oldPipeline )
-{
- mOldPipeline = std::move( oldPipeline );
- mHashCode = 0;
- return *this;
-}
-
-std::unique_ptr< API::Pipeline > PipelineFactory::Create()
-{
- // check cache
- if( mPipelineCache )
- {
- auto ptr = mPipelineCache->GetPipeline( *this );
-
- if( mOldPipeline && static_cast<VulkanAPI::Pipeline*>(mOldPipeline.get())->GetImplementation() == ptr )
- {
- return std::move( mOldPipeline );
- }
-
- // if pipeline is already in cache, attach implementation and return unique ptr
- if( ptr )
- {
- return std::unique_ptr< API::Pipeline >( new VulkanAPI::Pipeline( ptr ) );
- }
- }
-
- return std::unique_ptr< API::Pipeline >( new VulkanAPI::Pipeline( mGraphics, mController, this ) );
-}
-
-void PipelineFactory::Reset()
-{
- mInfo.depthStencilState = {};
- mInfo.colorBlendState = {};
- mInfo.shaderState = {};
- mInfo.viewportState = {};
- mInfo.framebufferState = {};
- mInfo.rasterizationState = {};
- mInfo.vertexInputState = {};
- mInfo.inputAssemblyState = {};
- mInfo.dynamicStateMask = 0u;
- mPipelineCache = nullptr;
- mBasePipeline = nullptr;
- mHashCode = 0;
- if( mOldPipeline )
- {
- mOldPipeline.reset();
- }
-}
-
-uint32_t PipelineFactory::GetHashCode() const
-{
- if( !mHashCode )
- {
- mHashCode = HashPipeline( *this );
- }
- return mHashCode;
-}
-
-}
-}
-}
+++ /dev/null
-#ifndef DALI_GRAPHICS_VULKAN_API_PIPELINE_FACTORY_H
-#define DALI_GRAPHICS_VULKAN_API_PIPELINE_FACTORY_H
-
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics-api/graphics-api-pipeline-factory.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-
-namespace Vulkan
-{
-class Graphics;
-}
-
-namespace VulkanAPI
-{
-class Controller;
-
-class Pipeline;
-
-class PipelineCache;
-
-/**
- * @brief Interface class for ShaderFactory types in the graphics API.
- */
-class PipelineFactory : public API::PipelineFactory
-{
-public:
-
- PipelineFactory( Controller& controller );
-
- API::PipelineFactory& SetPipelineCache( VulkanAPI::PipelineCache& pipelineCache );
-
- API::PipelineFactory& SetColorBlendState( const API::ColorBlendState& state ) override;
-
- API::PipelineFactory& SetShaderState( const API::ShaderState& state ) override;
-
- API::PipelineFactory& SetViewportState( const API::ViewportState& state ) override;
-
- API::PipelineFactory& SetFramebufferState( const API::FramebufferState& state ) override;
-
- API::PipelineFactory& SetBasePipeline( API::Pipeline& pipeline ) override;
-
- API::PipelineFactory& SetDepthStencilState( API::DepthStencilState state ) override;
-
- API::PipelineFactory& SetRasterizationState( const API::RasterizationState& state ) override;
-
- API::PipelineFactory& SetVertexInputState( const API::VertexInputState& state ) override;
-
- API::PipelineFactory& SetInputAssemblyState( const API::InputAssemblyState& state ) override;
-
- API::PipelineFactory& SetDynamicStateMask( const API::PipelineDynamicStateMask mask ) override;
-
- API::PipelineFactory& SetOldPipeline( std::unique_ptr<API::Pipeline> oldPipeline ) override;
-
- // To be called when getting new factory
- void Reset();
-
- std::unique_ptr< API::Pipeline > Create() override;
-
- uint32_t GetHashCode() const;
-
- struct Info
- {
- API::DepthStencilState depthStencilState;
- API::ColorBlendState colorBlendState;
- API::ShaderState shaderState;
- API::ViewportState viewportState;
- API::FramebufferState framebufferState;
- API::RasterizationState rasterizationState;
- API::VertexInputState vertexInputState;
- API::InputAssemblyState inputAssemblyState;
- API::PipelineDynamicStateMask dynamicStateMask;
- };
-
- const Info& GetCreateInfo() const
- {
- return mInfo;
- }
-
-public:
-
- Info mInfo;
- Controller& mController;
- Vulkan::Graphics& mGraphics;
- VulkanAPI::PipelineCache* mPipelineCache;
- VulkanAPI::Pipeline* mBasePipeline;
- mutable uint32_t mHashCode;
- std::unique_ptr<API::Pipeline> mOldPipeline { nullptr };
-};
-
-} // namespace API
-} // namespace Graphics
-} // namespace Dali
-
-#endif // DALI_GRAPHICS_VULKAN_API_PIPELINE_FACTORY_H
-
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics/vulkan/internal/vulkan-types.h>
-#include <dali/graphics/vulkan/api/vulkan-api-pipeline.h>
-#include <dali/graphics/vulkan/api/internal/vulkan-api-pipeline-impl.h>
-#include <dali/graphics/vulkan/api/vulkan-api-pipeline-factory.h>
-#include <dali/graphics/vulkan/api/internal/vulkan-pipeline-cache.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace VulkanAPI
-{
-
-Pipeline::Pipeline( Vulkan::Graphics& graphics, Controller& controller, const PipelineFactory* factory )
-{
- mPipelineImpl = new Internal::Pipeline( graphics, controller, factory );
-
- // ownership on the implementation is given away to cache
- factory->mPipelineCache->SavePipeline( *factory, std::unique_ptr< Internal::Pipeline >( mPipelineImpl ) );
-
- mPipelineImpl->Reference();
-}
-
-Pipeline::~Pipeline()
-{
- mPipelineImpl->Dereference();
-}
-
-Pipeline::Pipeline( Internal::Pipeline* impl ) :
- mPipelineImpl( impl )
-{
- mPipelineImpl->Reference();
-}
-
-const vk::Pipeline& Pipeline::GetVkPipeline() const
-{
- return mPipelineImpl->GetVkPipeline();
-}
-
-const vk::PipelineLayout& Pipeline::GetVkPipelineLayout() const
-{
- return mPipelineImpl->GetVkPipelineLayout();
-}
-
-const std::vector< vk::DescriptorSetLayout >& Pipeline::GetVkDescriptorSetLayouts() const
-{
- return mPipelineImpl->GetVkDescriptorSetLayouts();
-}
-
-const std::vector< Vulkan::DescriptorSetLayoutSignature >& Pipeline::GetDescriptorSetLayoutSignatures() const
-{
- return mPipelineImpl->GetDescriptorSetLayoutSignatures();
-}
-
-API::PipelineDynamicStateMask Pipeline::GetDynamicStateMask() const
-{
- return mPipelineImpl->GetDynamicStateMask();
-}
-
-void Pipeline::Bind( Vulkan::RefCountedCommandBuffer& commandBuffer ) const
-{
- mPipelineImpl->Bind( commandBuffer );
-}
-
-bool Pipeline::HasDepthEnabled() const
-{
- return mPipelineImpl->HasDepthEnabled();
-}
-
-bool Pipeline::HasStencilEnabled() const
-{
- return mPipelineImpl->HasStencilEnabled();
-}
-
-
-}
-}
-}
+++ /dev/null
-#ifndef DALI_GRAPHICS_VULKAN_API_PIPELINE_H
-#define DALI_GRAPHICS_VULKAN_API_PIPELINE_H
-
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics/vulkan/internal/vulkan-types.h>
-#include <dali/graphics-api/graphics-api-pipeline.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-class Graphics;
-
-class PipelineCache;
-}
-
-namespace VulkanAPI
-{
-namespace Internal
-{
-class Pipeline;
-}
-
-class Controller;
-
-class PipelineFactory;
-
-/**
- * Pipeline due to its nature ( it's cached, single ownership ) is only an interface
- */
-class Pipeline : public API::Pipeline
-{
-public:
-
- Pipeline( Vulkan::Graphics& graphics, Controller& controller, const PipelineFactory* factory );
-
- ~Pipeline() override;
-
- // non-copyable
- Pipeline( const Pipeline& ) = delete;
-
- Pipeline& operator=( const Pipeline& ) = delete;
-
- // movable
- Pipeline( Pipeline&& ) = default;
-
- Pipeline& operator=( Pipeline&& ) = default;
-
- Pipeline( Internal::Pipeline* impl );
-
- const vk::Pipeline& GetVkPipeline() const;
-
- const vk::PipelineLayout& GetVkPipelineLayout() const;
-
- const std::vector< vk::DescriptorSetLayout >& GetVkDescriptorSetLayouts() const;
-
- const std::vector< Vulkan::DescriptorSetLayoutSignature>& GetDescriptorSetLayoutSignatures() const;
-
- API::PipelineDynamicStateMask GetDynamicStateMask() const;
-
- void Bind( Vulkan::RefCountedCommandBuffer& commandBuffer ) const;
-
- bool HasDepthEnabled() const;
-
- bool HasStencilEnabled() const;
-
-public:
-
- Internal::Pipeline* GetImplementation() const
- {
- return mPipelineImpl;
- }
-
-private:
- Internal::Pipeline* mPipelineImpl;
-};
-}
-}
-}
-
-#endif // DALI_GRAPHICS_VULKAN_API_PIPELINE_H
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics-api/utility/utility-memory-pool.h>
-
-#include <dali/graphics/vulkan/api/vulkan-api-render-command.h>
-
-#include <dali/graphics/vulkan/api/vulkan-api-shader.h>
-#include <dali/graphics/vulkan/api/vulkan-api-texture.h>
-#include <dali/graphics/vulkan/api/vulkan-api-pipeline.h>
-#include <dali/graphics/vulkan/api/vulkan-api-sampler.h>
-#include <dali/graphics/vulkan/api/vulkan-api-buffer.h>
-#include <dali/graphics/vulkan/internal/spirv/vulkan-spirv.h>
-#include <dali/graphics/vulkan/internal/vulkan-command-buffer.h>
-#include <dali/graphics/vulkan/internal/vulkan-command-pool.h>
-#include <dali/graphics/vulkan/vulkan-graphics.h>
-#include <dali/graphics/vulkan/internal/vulkan-buffer.h>
-#include <dali/graphics/vulkan/internal/vulkan-sampler.h>
-#include <dali/graphics/vulkan/internal/vulkan-image.h>
-#include <dali/graphics/vulkan/internal/vulkan-image-view.h>
-#include <dali/graphics/vulkan/internal/vulkan-framebuffer.h>
-
-#include <dali/graphics/vulkan/internal/vulkan-swapchain.h>
-
-#include <dali/graphics/vulkan/api/vulkan-api-controller.h>
-#include <dali/graphics/vulkan/internal/vulkan-debug.h>
-#include <dali/graphics/vulkan/api/internal/vulkan-api-descriptor-set-allocator.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-using Vulkan::VkAssert;
-
-namespace VulkanAPI
-{
-
-struct RenderCommand::DescriptorSetData
-{
- std::vector< Vulkan::DescriptorSetLayoutSignature > descriptorSetLayoutSignatures;
- std::vector< vk::DescriptorSetLayout > descriptorSetLayouts;
- std::vector< DescriptorSetRequirements > descriptorSetRequirements;
- DescriptorSetList vkDescriptorSets;
-};
-
-RenderCommand::~RenderCommand()
-{
- DiscardDescriptorSets();
-}
-
-void RenderCommand::DiscardDescriptorSets()
-{
- if( !mData->vkDescriptorSets.descriptorSets.empty() )
- {
- mController.FreeDescriptorSets( std::move( mData->vkDescriptorSets ) );
- }
-}
-
-bool RenderCommand::IsDescriptorPoolValid( VulkanAPI::Internal::DescriptorSetAllocator& dsAllocator )
-{
- bool valid = false;
- if( !mData->vkDescriptorSets.descriptorSets.empty() )
- {
- valid = dsAllocator.ValidateDescriptorSetList( mData->vkDescriptorSets );
- }
- return valid;
-}
-
-RenderCommand::RenderCommand( VulkanAPI::Controller& controller, Vulkan::Graphics& graphics )
-: mController( controller ),
- mGraphics( graphics ),
- mData( new DescriptorSetData() )
-{
-}
-
-void RenderCommand::PrepareResources()
-{
- if( mUpdateFlags )
- {
- if( mUpdateFlags & (API::RENDER_COMMAND_UPDATE_UNIFORM_BUFFER_BIT ))
- {
- BindUniformBuffers();
- }
-
- if( mUpdateFlags & ( API::RENDER_COMMAND_UPDATE_TEXTURE_BIT|API::RENDER_COMMAND_UPDATE_SAMPLER_BIT) )
- {
- BindTexturesAndSamplers();
- }
-
- mUpdateFlags = 0u;
- }
-}
-
-void RenderCommand::AllocateDescriptorSets( VulkanAPI::Internal::DescriptorSetAllocator& dsAllocator )
-{
- // allocate descriptor
- if( !IsDescriptorPoolValid( dsAllocator ) )
- {
- mData->vkDescriptorSets.descriptorSets.clear();
- dsAllocator.AllocateDescriptorSets( mData->descriptorSetLayoutSignatures, mData->descriptorSetLayouts, mData->vkDescriptorSets );
- mUpdateFlags |= API::RENDER_COMMAND_UPDATE_UNIFORM_BUFFER_BIT;
- mUpdateFlags |= API::RENDER_COMMAND_UPDATE_TEXTURE_BIT;
- }
-}
-
-void RenderCommand::UpdateDescriptorSetAllocationRequirements( std::vector<DescriptorSetRequirements>& requirements, VulkanAPI::Internal::DescriptorSetAllocator& dsAllocator )
-{
- //@ todo: only when pipeline has changed!
- BuildDescriptorSetRequirements();
- if( mData->descriptorSetRequirements.empty() ) // shouldn't be empty
- {
- return;
- }
- // If pipeline changed we need to free descriptor sets and allocate new ones.
- // Destroying old descriptors must happen before allocating new ones
- if( mUpdateFlags & API::RENDER_COMMAND_UPDATE_PIPELINE_BIT )
- {
- auto pipeline = static_cast<const VulkanAPI::Pipeline *>( mPipeline );
- if( !pipeline )
- {
- return;
- }
- mVulkanPipeline = pipeline->GetVkPipeline();
- mData->descriptorSetLayoutSignatures = pipeline->GetDescriptorSetLayoutSignatures();
- mData->descriptorSetLayouts = pipeline->GetVkDescriptorSetLayouts();
-
- // free descriptor sets for that pool
- if( !mData->vkDescriptorSets.descriptorSets.empty() )
- {
- mController.FreeDescriptorSets( std::move( mData->vkDescriptorSets ) );
- mData->vkDescriptorSets = {};
- }
- }
-
- // remove expired descriptor sets before building new requirements
- if(!IsDescriptorPoolValid( dsAllocator ))
- {
- mData->vkDescriptorSets.descriptorSets.clear();
- }
-
- for( auto& requirement : mData->descriptorSetRequirements )
- {
- auto it = std::find_if( requirements.begin(),
- requirements.end(),
- [&]( DescriptorSetRequirements& item )->bool {
- if( item.layoutSignature == requirement.layoutSignature )
- {
- for( auto i = 0u; i < uint32_t(Vulkan::DescriptorType::DESCRIPTOR_TYPE_COUNT); ++i )
- {
- item.requirements[i] += requirement.requirements[i];
- }
- item.maxSets += requirement.maxSets;
- return true;
- }
- return false;
- } );
- if( it == requirements.end() )
- {
- requirements.emplace_back( requirement );
- it = requirements.end()-1;
- }
- }
-
-}
-
-void RenderCommand::BuildDescriptorSetRequirements()
-{
- if( !(mUpdateFlags & API::RENDER_COMMAND_UPDATE_PIPELINE_BIT) )
- {
- return;
- }
-
- // For new pipeline build descriptor set requirements array
- auto pipeline = static_cast<const VulkanAPI::Pipeline *>( mPipeline );
- if( !pipeline )
- {
- return;
- }
-
- mData->descriptorSetLayoutSignatures = pipeline->GetDescriptorSetLayoutSignatures();
- mData->descriptorSetLayouts = pipeline->GetVkDescriptorSetLayouts();
- mData->descriptorSetRequirements = {};
-
- for( auto& signature : mData->descriptorSetLayoutSignatures )
- {
- // See whether we have this signature in
- auto it = std::find_if( mData->descriptorSetRequirements.begin(),
- mData->descriptorSetRequirements.end(),
- [&]( auto& item )->bool { return item.layoutSignature == signature; } );
-
- if( it == mData->descriptorSetRequirements.end() )
- {
- mData->descriptorSetRequirements.emplace_back();
- it = mData->descriptorSetRequirements.end()-1;
- }
-
- it->layoutSignature = signature;
- auto decoded = signature.Decode();
- for( auto& descriptorSet : decoded )
- {
- auto requirementIndex = uint32_t(std::get<0>(descriptorSet));
- auto descriptorCount = uint32_t(std::get<1>(descriptorSet));
- it->requirements[ requirementIndex ] += descriptorCount;
- }
-
- // increments maximum number of sets
- it->maxSets++;
- }
-
-}
-
-void RenderCommand::BindUniformBuffers()
-{
- if( !mUniformBufferBindings )
- {
- return;
- }
-
- for( auto i = 0u; i < mUniformBufferBindings->size(); ++i )
- {
- mController.mStats.uniformBufferBindings++;
- const auto& binding = (*mUniformBufferBindings)[i];
-
- auto bufferInfo = vk::DescriptorBufferInfo{}
- .setOffset( uint32_t( binding.offset ) )
- .setRange( uint32_t( binding.dataSize ) )
- .setBuffer( static_cast<const VulkanAPI::Buffer*>(binding.buffer)->GetBufferRef()->GetVkHandle() );
-
- mController.PushDescriptorWrite(
- vk::WriteDescriptorSet{}.setPBufferInfo( &bufferInfo )
- .setDescriptorType( vk::DescriptorType::eUniformBuffer )
- .setDescriptorCount( 1 )
- .setDstSet( mData->vkDescriptorSets.descriptorSets[0] )
- .setDstBinding( binding.binding )
- .setDstArrayElement( 0 ) );
- }
-}
-
-
-void RenderCommand::BindPipeline( Vulkan::RefCountedCommandBuffer& commandBuffer )
-{
- if( mPipeline )
- {
- auto pipeline = static_cast<const VulkanAPI::Pipeline *>( mPipeline );
- pipeline->Bind( commandBuffer );
- }
-}
-
-void RenderCommand::BindTexturesAndSamplers()
-{
- // only if textures/samplers changed, rewrite
- if( !mTextureBindings )
- {
- return;
- }
-
- for( const auto& texture : *mTextureBindings )
- {
- auto image = static_cast<const VulkanAPI::Texture*>(texture.texture);
-
- // test if image is valid, skip invalid image
- // @todo: possibly use builtin 'broken' image
- if( !image || !image->GetImageRef() )
- {
- continue;
- }
- mController.mStats.samplerTextureBindings++;
- DALI_LOG_STREAM( gVulkanFilter, Debug::General,
- "[RenderCommand] BindingTextureSampler: binding = " << texture.binding );
-
-
- auto imageViewInfo = vk::DescriptorImageInfo{}
- .setImageLayout( vk::ImageLayout::eShaderReadOnlyOptimal )
- .setImageView( image->GetImageViewRef()->GetVkHandle() )
- .setSampler(!texture.sampler ?
- image->GetSamplerRef()->GetVkHandle() :
- static_cast<const VulkanAPI::Sampler*>( texture.sampler )->GetSampler()->GetVkHandle() );
-
- mController.PushDescriptorWrite(
- vk::WriteDescriptorSet{}.setPImageInfo( &imageViewInfo )
- .setDescriptorType( vk::DescriptorType::eCombinedImageSampler )
- .setDescriptorCount( 1 )
- .setDstSet( mData->vkDescriptorSets.descriptorSets[0] )
- .setDstBinding( texture.binding )
- .setDstArrayElement( 0 ) );
- }
-}
-
-const std::vector< vk::DescriptorSet >& RenderCommand::GetDescriptorSets()
-{
- return mData->vkDescriptorSets.descriptorSets;
-}
-
-const vk::Pipeline& RenderCommand::GetVulkanPipeline() const
-{
- return mVulkanPipeline;
-}
-
-} // namespace VulkanAPI
-} // namespace Graphics
-} // namespace Dali
+++ /dev/null
-#ifndef DALI_GRAPHICS_VULKAN_API_RENDER_COMMAND_H
-#define DALI_GRAPHICS_VULKAN_API_RENDER_COMMAND_H
-
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics-api/graphics-api-render-command.h>
-#include <dali/graphics-api/graphics-api-shader-details.h>
-#include <dali/graphics/vulkan/internal/vulkan-types.h>
-#include <dali/graphics/vulkan/internal/vulkan-debug.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-class PipelineCache;
-}
-
-namespace VulkanAPI
-{
-class Controller;
-class Ubo;
-class Pipeline;
-class DescriptorSetList;
-class DescriptorSetRequirements;
-
-namespace Internal
-{
-class DescriptorSetAllocator;
-}
-
-/**
- * Render command stores internal command buffer per draw call
- *
- * For Vulkan:
- *
- * - RenderCommand stores all the relevant data
- * - Changing pipeline determines recreating certain resources
- * - Currently each RC has own DescriptorSetPool
- * - Currently each RC has a handle to UBOs
- * - UBOs are assigned upon pipeline creation/assignment
- * - Descriptor sets are allocated upon pipeline creation
- * - Note: need resource "versioning"
- */
-class RenderCommand : public Graphics::API::RenderCommand
-{
-public:
-
- RenderCommand( VulkanAPI::Controller& controller,
- Vulkan::Graphics& graphics );
-
- ~RenderCommand() override;
-
- /**
- * Forces pipeline compilation whenever something changed and
- * updates cache
- * @return
- */
- void PrepareResources();
-
- /**
- * Writes uniform buffers into descriptor set
- */
- void BindUniformBuffers();
-
- /**
- * Writes texture/sample combo into descriptor set
- */
- void BindTexturesAndSamplers();
-
- /**
- * Returns an array of updated descriptor sets
- * @return
- */
- const std::vector< vk::DescriptorSet >& GetDescriptorSets();
-
- /**
- * Returns Vulkan backed pipeline
- * @return
- */
- const vk::Pipeline& GetVulkanPipeline() const;
-
- /**
- * Binds pipeline in the given command buffer
- * @param commandBuffer
- */
- void BindPipeline( Vulkan::RefCountedCommandBuffer& commandBuffer );
-
- /**
- * Updates descriptor set requirements
- *
- * @param[out] requirements A list of requirements to write to
- */
- void UpdateDescriptorSetAllocationRequirements( std::vector<DescriptorSetRequirements>& requirements, VulkanAPI::Internal::DescriptorSetAllocator& dsAllocator );
-
- /**
- * Allocates descriptor sets
- *
- * @note this function may reuse descriptor sets if it's not necessary to reallocate
- *
- * @param[in] dsAllocator Descriptor set allocator
- */
- void AllocateDescriptorSets( Internal::DescriptorSetAllocator& dsAllocator );
-
-private:
-
- /**
- * Retrieves array of requirements of used descriptor sets
- */
- void BuildDescriptorSetRequirements();
-
- /**
- * Discards existing descriptor sets
- */
- void DiscardDescriptorSets();
-
- /**
- * Tests whether the descriptor pool used by the render command is
- * still valid or new descriptors have to be allocated
- * @param[in] dsAllocator descriptor set allocator
- * @return True if pool is still valid
- */
- bool IsDescriptorPoolValid( VulkanAPI::Internal::DescriptorSetAllocator& dsAllocator );
-
-private:
-
- VulkanAPI::Controller& mController;
- Vulkan::Graphics& mGraphics;
- vk::Pipeline mVulkanPipeline;
-
- /**
- * Internal descriptor set data
- */
- struct DescriptorSetData;
- std::unique_ptr<DescriptorSetData> mData;
-};
-
-}
-}
-}
-#endif //DALI_GRAPHICS_VULKAN_API_RENDER_COMMAND_H
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics/vulkan/api/vulkan-api-sampler-factory.h>
-#include <dali/graphics/vulkan/api/vulkan-api-sampler.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace VulkanAPI
-{
-
-API::SamplerFactory& SamplerFactory::SetAddressModeU( API::SamplerAddressMode mode )
-{
- mAddressModeU = mode;
- return *this;
-}
-
-API::SamplerFactory& SamplerFactory::SetAddressModeV( API::SamplerAddressMode mode )
-{
- mAddressModeV = mode;
- return *this;
-}
-
-API::SamplerFactory& SamplerFactory::SetAddressModeW( API::SamplerAddressMode mode )
-{
- mAddressModeW = mode;
- return *this;
-}
-
-API::SamplerFactory& SamplerFactory::SetMinFilter( API::SamplerFilter filter )
-{
- mMinFilter = filter;
- return *this;
-}
-
-API::SamplerFactory& SamplerFactory::SetMagFilter( API::SamplerFilter filter )
-{
- mMagFilter = filter;
- return *this;
-}
-
-API::SamplerFactory& SamplerFactory::SetMipmapMode( API::SamplerMipmapMode mipmapMode )
-{
- mMipmapMode = mipmapMode;
- return *this;
-}
-
-API::SamplerFactory& SamplerFactory::SetAnisotropyEnable( bool anisotropyEnable )
-{
- mAnisotropyEnable = anisotropyEnable;
- return *this;
-}
-
-API::SamplerFactory& SamplerFactory::SetMaxAnisotropy( float maxAnisotropy )
-{
- mMaxAnisotropy = maxAnisotropy;
- return *this;
-}
-
-API::SamplerFactory& SamplerFactory::SetMinLod( float minLod )
-{
- mMinLod = minLod;
- return *this;
-}
-
-API::SamplerFactory& SamplerFactory::SetMaxLod( float maxLod )
-{
- mMaxLod = maxLod;
- return *this;
-}
-
-API::SamplerFactory& SamplerFactory::SetUnnormalizeCoordinates( bool unnormalizedCoordinates )
-{
- mUnnormalizedCoordinates = unnormalizedCoordinates;
- return *this;
-}
-
-API::SamplerFactory& SamplerFactory::SetCompareEnable( bool compareEnable )
-{
- mCompareEnable = compareEnable;
- return *this;
-}
-
-API::SamplerFactory& SamplerFactory::SetCompareOp( API::CompareOp compareOp )
-{
- mCompareOp = compareOp;
- return *this;
-}
-
-SamplerFactory& SamplerFactory::Reset()
-{
- mAddressModeU = API::SamplerAddressMode{};
- mAddressModeV = API::SamplerAddressMode{};
- mAddressModeW = API::SamplerAddressMode{};
- mMinFilter = API::SamplerFilter{};
- mMagFilter = API::SamplerFilter{};
- mMipmapMode = API::SamplerMipmapMode{};
- mCompareOp = API::CompareOp{};
- mMaxAnisotropy = 1.0f; // value must be 1.0f as default if anisotropy feature isn't enabled
- mMinLod = 0.0f;
- mMaxLod = 0.0f;
- mCompareEnable = false;
- mAnisotropyEnable = false;
- mUnnormalizedCoordinates = false;
- return *this;
-}
-
-std::unique_ptr< Graphics::API::Sampler > SamplerFactory::Create() const
-{
- return std::unique_ptr<VulkanAPI::Sampler>( new VulkanAPI::Sampler( mController, *this ) );
-}
-
-} // namespace API
-} // namespace Graphics
-} // namespace Dali
+++ /dev/null
-#ifndef DALI_VULKAN_API_SAMPLER_FACTORY_H
-#define DALI_VULKAN_API_SAMPLER_FACTORY_H
-
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics-api/graphics-api-sampler-factory.h>
-#include "vulkan-api-controller.h"
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace VulkanAPI
-{
-
-/**
- * @brief Interface class for ShaderFactory types in the graphics API.
- */
-class SamplerFactory : public API::SamplerFactory
-{
-public:
-
- SamplerFactory( Controller& controller )
- : mController( controller )
- {
-
- }
-
- API::SamplerFactory& SetAddressModeU( API::SamplerAddressMode mode ) override;
-
- API::SamplerFactory& SetAddressModeV( API::SamplerAddressMode mode ) override;
-
- API::SamplerFactory& SetAddressModeW( API::SamplerAddressMode mode ) override;
-
- API::SamplerFactory& SetMinFilter( API::SamplerFilter filter ) override;
-
- API::SamplerFactory& SetMagFilter( API::SamplerFilter filter ) override;
-
- API::SamplerFactory& SetMipmapMode( API::SamplerMipmapMode mipmapMode ) override;
-
- API::SamplerFactory& SetAnisotropyEnable( bool anisotropyEnable ) override;
-
- API::SamplerFactory& SetMaxAnisotropy( float maxAnisotropy ) override;
-
- API::SamplerFactory& SetMinLod( float minLod ) override;
-
- API::SamplerFactory& SetMaxLod( float maxLod ) override;
-
- API::SamplerFactory& SetUnnormalizeCoordinates( bool unnormalizedCoordinates ) override;
-
- API::SamplerFactory& SetCompareEnable( bool compareEnable ) override;
-
- API::SamplerFactory& SetCompareOp( API::CompareOp compareOp ) override;
-
- // not copyable
- SamplerFactory(const API::SamplerFactory&) = delete;
- SamplerFactory& operator=(const SamplerFactory&) = delete;
-
- ~SamplerFactory() = default;
-
- PointerType Create() const override;
-
-protected:
-
- /// @brief default constructor
- SamplerFactory() = default;
-
- // derived types should not be moved directly to prevent slicing
- SamplerFactory(SamplerFactory&&) = default;
- SamplerFactory& operator=(SamplerFactory&&) = default;
-
-public:
-
- SamplerFactory& Reset();
-
- VulkanAPI::Controller& mController;
-
- API::SamplerAddressMode mAddressModeU {};
- API::SamplerAddressMode mAddressModeW {};
- API::SamplerAddressMode mAddressModeV {};
- API::SamplerFilter mMinFilter {};
- API::SamplerFilter mMagFilter {};
- API::SamplerMipmapMode mMipmapMode {};
- API::CompareOp mCompareOp {};
- float mMaxAnisotropy { 0.0f };
- float mMinLod { 0.0f };
- float mMaxLod { 0.0f };
- bool mCompareEnable {};
- bool mAnisotropyEnable { false };
- bool mUnnormalizedCoordinates { false };
-
-
-};
-
-} // namespace API
-} // namespace Graphics
-} // namespace Dali
-
-#endif // DALI_VULKAN_API_SAMPLER_FACTORY_H
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics/vulkan/api/vulkan-api-sampler.h>
-#include <dali/graphics/vulkan/api/vulkan-api-sampler-factory.h>
-#include <dali/graphics/vulkan/api/vulkan-api-controller.h>
-#include <dali/graphics/vulkan/vulkan-graphics.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace VulkanAPI
-{
-namespace
-{
-constexpr vk::Filter ConvertFilter( API::SamplerFilter filter )
-{
- switch(filter)
- {
- case API::SamplerFilter::LINEAR: return vk::Filter::eLinear;
- case API::SamplerFilter::NEAREST: return vk::Filter::eNearest;
- }
- return vk::Filter{};
-}
-
-constexpr vk::SamplerAddressMode ConvertAddressMode( API::SamplerAddressMode mode )
-{
- switch(mode)
- {
- case API::SamplerAddressMode::CLAMP_TO_EDGE: return vk::SamplerAddressMode::eClampToEdge;
- case API::SamplerAddressMode::CLAMP_TO_BORDER: return vk::SamplerAddressMode::eClampToBorder;
- case API::SamplerAddressMode::MIRROR_CLAMP_TO_EDGE: return vk::SamplerAddressMode::eMirrorClampToEdge;
- case API::SamplerAddressMode::MIRRORED_REPEAT: return vk::SamplerAddressMode::eMirroredRepeat;
- case API::SamplerAddressMode::REPEAT: return vk::SamplerAddressMode::eRepeat;
- }
- return vk::SamplerAddressMode{};
-}
-
-constexpr vk::SamplerMipmapMode ConvertMipmapMode( API::SamplerMipmapMode mode )
-{
- switch(mode)
- {
- case API::SamplerMipmapMode::LINEAR: return vk::SamplerMipmapMode::eLinear;
- case API::SamplerMipmapMode::NEAREST: return vk::SamplerMipmapMode::eNearest;
- }
- return vk::SamplerMipmapMode{};
-}
-
-}
-
-Sampler::Sampler( Controller& controller, const SamplerFactory& factory )
-: mController( controller )
-{
- mSampler = controller.GetGraphics().CreateSampler(
- vk::SamplerCreateInfo()
- .setMinFilter( ConvertFilter( factory.mMinFilter ) )
- .setMagFilter( ConvertFilter( factory.mMagFilter ) )
- .setAddressModeU( ConvertAddressMode( factory.mAddressModeU ) )
- .setAddressModeV( ConvertAddressMode( factory.mAddressModeV ) )
- .setAddressModeW( ConvertAddressMode( factory.mAddressModeW ) )
- .setMipmapMode( ConvertMipmapMode( factory.mMipmapMode ) )
- .setCompareEnable( vk::Bool32(factory.mCompareEnable) )
- .setUnnormalizedCoordinates( vk::Bool32(factory.mUnnormalizedCoordinates) )
- .setBorderColor( vk::BorderColor::eFloatOpaqueBlack )
- .setAnisotropyEnable( vk::Bool32(factory.mAnisotropyEnable) )
- .setMaxAnisotropy( factory.mMaxAnisotropy )
- .setMinLod( factory.mMinLod )
- .setMaxLod( factory.mMaxLod )
- );
-}
-
-} // namespace VulkanAPI
-} // namespace Graphics
-} // namespace Dali
+++ /dev/null
-#ifndef DALI_VULKAN_API_SAMPLER_H
-#define DALI_VULKAN_API_SAMPLER_H
-
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics-api/graphics-api-sampler.h>
-#include <dali/graphics/vulkan/internal/vulkan-sampler.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace VulkanAPI
-{
-class SamplerFactory;
-class Controller;
-/**
- * @brief Interface class for Sampler types in the graphics API.
- */
-class Sampler : public API::Sampler
-{
-public:
-
- Sampler( Controller& controller, const SamplerFactory& factory );
-
- const Vulkan::RefCountedSampler& GetSampler() const
- {
- return mSampler;
- }
-
-protected:
-
- Controller& mController;
- Vulkan::RefCountedSampler mSampler;
-};
-
-} // namespace VulkanAPI
-} // namespace Graphics
-} // namespace Dali
-
-#endif // DALI_VULKAN_API_SAMPLER_H
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics/vulkan/api/vulkan-api-shader-factory.h>
-#include <dali/graphics/vulkan/api/vulkan-api-shader.h>
-#include <dali/graphics/vulkan/vulkan-graphics.h>
-#include <dali/graphics/vulkan/internal/vulkan-shader.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace VulkanAPI
-{
-
-ShaderFactory::ShaderFactory( Vulkan::Graphics& graphics ) :
- mGraphics( graphics )
-{
-}
-
-ShaderFactory::~ShaderFactory() = default;
-
-ShaderFactory& ShaderFactory::SetShaderModule( Graphics::API::ShaderDetails::PipelineStage pipelineStage,
- Graphics::API::ShaderDetails::Language language,
- const Graphics::API::ShaderDetails::ShaderSource& source )
-{
- using PipelineStage = Graphics::API::ShaderDetails::PipelineStage;
- if( pipelineStage == PipelineStage::VERTEX )
- {
- mVertexShader = ShaderModuleInfo( pipelineStage, language, source );
- }
- else if( pipelineStage == PipelineStage::FRAGMENT )
- {
- mFragmentShader = ShaderModuleInfo( pipelineStage, language, source );
- }
- return *this;
-}
-
-std::unique_ptr< Graphics::API::Shader > ShaderFactory::Create() const
-{
- if( !mVertexShader.source.IsSet() || !mFragmentShader.source.IsSet() )
- {
- return nullptr;
- }
-
- auto retval = std::make_unique< VulkanAPI::Shader >( mGraphics );
-
- // add vertex shader
- retval->AddShaderModule( mVertexShader.pipelineStage, mVertexShader.language, mVertexShader.source );
-
- // add fragment shader
- retval->AddShaderModule( mFragmentShader.pipelineStage, mFragmentShader.language, mFragmentShader.source );
-
- return std::move( retval );
-}
-
-} // namespace VulkanAPI
-} // namespace Graphics
-} // namespace Dali
+++ /dev/null
-#ifndef DALI_GRAPHICS_VULKAN_API_SHADER_FACTORY_H
-#define DALI_GRAPHICS_VULKAN_API_SHADER_FACTORY_H
-
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#include <dali/graphics-api/graphics-api-shader-factory.h>
-#include <dali/graphics-api/graphics-api-shader-details.h>
-#include <dali/graphics-api/graphics-api-shader.h>
-
-#include <vector>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-class Graphics;
-}
-namespace VulkanAPI
-{
-
-class ShaderFactory : public Dali::Graphics::API::ShaderFactory
-{
-public:
- explicit ShaderFactory( Vulkan::Graphics& graphics );
-
- ShaderFactory& SetShaderModule( Graphics::API::ShaderDetails::PipelineStage pipelineStage,
- Graphics::API::ShaderDetails::Language language,
- const Graphics::API::ShaderDetails::ShaderSource& source ) override;
-
- PointerType Create() const override;
-
- ~ShaderFactory() override;
-
-private:
-
- struct ShaderModuleInfo
- {
- using PipelineStage = Graphics::API::ShaderDetails::PipelineStage;
- using Language = Graphics::API::ShaderDetails::Language;
- using ShaderSource = Graphics::API::ShaderDetails::ShaderSource;
-
- PipelineStage pipelineStage;
- Language language;
- ShaderSource source;
-
- ShaderModuleInfo( PipelineStage stage, Language shaderLanguage, const ShaderSource& shaderSource )
- : pipelineStage( stage ),
- language( shaderLanguage ),
- source( shaderSource )
- {
- }
-
- ShaderModuleInfo()
- : pipelineStage( PipelineStage::VERTEX ),
- language( Language::SPIRV_1_0 ),
- source( ShaderSource( std::vector< char >() ) )
- {
- }
-
- ShaderModuleInfo( const ShaderModuleInfo& info ) = default;
-
- ~ShaderModuleInfo() = default;
- };
-
- Vulkan::Graphics& mGraphics;
- ShaderModuleInfo mVertexShader;
- ShaderModuleInfo mFragmentShader;
-};
-
-
-}
-}
-}
-
-#endif // DALI_GRAPHICS_VULKAN_API_SHADER_FACTORY_H
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics/vulkan/api/vulkan-api-shader.h>
-#include <dali/graphics-api/graphics-api-shader-details.h>
-#include <dali/graphics/vulkan/internal/vulkan-shader.h>
-#include <dali/graphics/vulkan/vulkan-graphics.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace VulkanAPI
-{
-using namespace Dali::Graphics::API;
-using namespace Dali::Graphics::Vulkan;
-
-using ShaderLanguage = Dali::Graphics::API::ShaderDetails::Language;
-using ShaderPipelineStage = Dali::Graphics::API::ShaderDetails::PipelineStage;
-using ShaderSource = Dali::Graphics::API::ShaderDetails::ShaderSource;
-
-Shader::Shader( Vulkan::Graphics& graphics ) :
- mGraphics( graphics )
-{
-
-}
-
-RefCountedShader Shader::GetShader( vk::ShaderStageFlagBits shaderStage ) const
-{
- switch( shaderStage )
- {
- case vk::ShaderStageFlagBits::eVertex:
- {
- return mVertexShader;
- }
- case vk::ShaderStageFlagBits::eFragment:
- {
- return mFragmentShader;
- }
- case vk::ShaderStageFlagBits::eTessellationControl:
- case vk::ShaderStageFlagBits::eTessellationEvaluation:
- case vk::ShaderStageFlagBits::eGeometry:
- case vk::ShaderStageFlagBits::eCompute:
- case vk::ShaderStageFlagBits::eAllGraphics:
- case vk::ShaderStageFlagBits::eAll:
- {
- }
- }
- return RefCountedShader();
-}
-
-Shader& Shader::DownCast( Dali::Graphics::API::Shader& shader )
-{
- return *( dynamic_cast<Shader*>( &shader ) );
-}
-
-Vulkan::RefCountedShader Shader::GetShaderRef( vk::ShaderStageFlagBits shaderStage ) const
-{
- if( shaderStage == vk::ShaderStageFlagBits::eVertex )
- {
- return mVertexShader;
- }
- else if( shaderStage == vk::ShaderStageFlagBits::eFragment )
- {
- return mFragmentShader;
- }
- else
- {
- return Vulkan::RefCountedShader();
- }
-}
-
-bool Shader::AddShaderModule( Dali::Graphics::API::ShaderDetails::PipelineStage pipelineStage,
- Dali::Graphics::API::ShaderDetails::Language language,
- Dali::Graphics::API::ShaderDetails::ShaderSource shaderSource )
-{
- // TODO: AB: only supported language is SPIRV for now
- if( language != ShaderLanguage::SPIRV_1_0 && language != ShaderLanguage::SPIRV_1_1 )
- {
- // unsupported language
- return false;
- }
-
- // TODO: AB: only binary shader supported for now
- if( shaderSource.type != ShaderDetails::ShaderSourceType::BINARY )
- {
- return false;
- }
-
- auto shaderRef = Vulkan::Shader::New( mGraphics, &shaderSource.code[0], shaderSource.code.size() );
-
- if( !shaderRef )
- {
- return false;
- }
-
- if( pipelineStage == ShaderPipelineStage::VERTEX )
- {
- mVertexShader = shaderRef;
- mVertexShader->SetExplicitShaderStage( vk::ShaderStageFlagBits::eVertex );
- // update input attributes
- mVertexShader->GetSPIRVReflection().GetVertexInputAttributes( mVertexInputAttributes );
- }
- else if( pipelineStage == ShaderPipelineStage::FRAGMENT )
- {
- mFragmentShader = shaderRef;
- mVertexShader->SetExplicitShaderStage( vk::ShaderStageFlagBits::eFragment );
- }
-
- mUniformBlocks.clear();
- mUniformOpaques.clear();
-
- // recreate reflection
- if( mVertexShader )
- {
- auto& ubo = mVertexShader->GetSPIRVReflection().GetUniformBlocks();
- mUniformBlocks.insert( mUniformBlocks.end(), ubo.begin(), ubo.end() );
-
- auto& uniforms = mVertexShader->GetSPIRVReflection().GetOpaqueUniforms();
- mUniformOpaques.insert( mUniformOpaques.end(), uniforms.begin(), uniforms.end() );
- }
- if( mFragmentShader )
- {
- auto& ubo = mFragmentShader->GetSPIRVReflection().GetUniformBlocks();
- mUniformBlocks.insert( mUniformBlocks.end(), ubo.begin(), ubo.end() );
-
- auto& uniforms = mFragmentShader->GetSPIRVReflection().GetOpaqueUniforms();
- mUniformOpaques.insert( mUniformOpaques.end(), uniforms.begin(), uniforms.end() );
- }
-
- // verify bindings and descriptor sets ( must be no overlaps, or if there are, only one binding will be used )
- return true;
-}
-
-bool Shader::IsReflectionSupported() const
-{
- return true;
-}
-
-uint32_t Shader::GetVertexAttributeLocation( const std::string& name ) const
-{
- if( !mVertexShader )
- {
- return API::ShaderDetails::ERROR_VERTEX_INPUT_ATTRIBUTE_NOT_FOUND;
- }
-
- for( auto&& attr : mVertexInputAttributes )
- {
- if( attr.name == name )
- {
- return attr.location;
- }
- }
- return API::ShaderDetails::ERROR_VERTEX_INPUT_ATTRIBUTE_NOT_FOUND;
-}
-
-API::ShaderDetails::VertexInputAttributeFormat Shader::GetVertexAttributeFormat( uint32_t location ) const
-{
- if( !mVertexShader || mVertexInputAttributes.size() <= location )
- {
- return API::ShaderDetails::VertexInputAttributeFormat::UNDEFINED;
- }
-
- const auto& attr = mVertexInputAttributes[location];
-
- if( attr.format == vk::Format::eR32Sfloat )
- {
- return API::ShaderDetails::VertexInputAttributeFormat::FLOAT;
- }
- if( attr.format == vk::Format::eR32Sint )
- {
- return API::ShaderDetails::VertexInputAttributeFormat::INTEGER;
- }
- if( attr.format == vk::Format::eR32G32Sfloat )
- {
- return API::ShaderDetails::VertexInputAttributeFormat::VEC2;
- }
- if( attr.format == vk::Format::eR32G32B32Sfloat )
- {
- return API::ShaderDetails::VertexInputAttributeFormat::VEC3;
- }
- if( attr.format == vk::Format::eR32G32B32A32Sfloat )
- {
- return API::ShaderDetails::VertexInputAttributeFormat::VEC4;
- }
- return API::ShaderDetails::VertexInputAttributeFormat::UNDEFINED;
-}
-
-std::string Shader::GetVertexAttributeName( uint32_t location ) const
-{
- if( !mVertexShader || mVertexInputAttributes.size() <= location )
- {
- return "";
- }
-
- return mVertexInputAttributes[location].name;
-}
-
-std::vector< uint32_t > Shader::GetVertexAttributeLocations() const
-{
- std::vector< uint32_t > locations;
- for( auto&& attr : mVertexInputAttributes )
- {
- if( attr.format != vk::Format::eUndefined )
- {
- locations.push_back( attr.location );
- }
- }
-
- return locations;
-}
-
-std::vector< uint32_t > Shader::GetUniformBlockLocations() const
-{
- std::vector< uint32_t > retval{};
- for( auto&& ubo : mUniformBlocks )
- {
- retval.emplace_back( ubo.binding );
- }
- return retval;
-}
-
-std::string Shader::GetUniformBlockName( uint32_t blockIndex ) const
-{
- return mUniformBlocks[blockIndex].name;
-}
-
-uint32_t Shader::GetUniformBlockMemberCount( uint32_t blockIndex ) const
-{
- return U32( mUniformBlocks[blockIndex].members.size() );
-}
-
-std::string Shader::GetUniformBlockMemberName( uint32_t blockIndex, uint32_t memberLocation ) const
-{
- return mUniformBlocks[blockIndex].members[memberLocation].name;
-}
-
-uint32_t Shader::GetUniformBlockMemberOffset( uint32_t blockIndex, uint32_t memberLocation ) const
-{
- return mUniformBlocks[blockIndex].members[memberLocation].offset;
-}
-
-bool Shader::GetNamedUniform( const std::string& name, API::ShaderDetails::UniformInfo& out ) const
-{
- // check uniform blocks first
- auto index = 0u;
- for( auto&& ubo : mUniformBlocks )
- {
- for( auto&& member : ubo.members )
- {
- if( name == member.name || name == ( ubo.name + "." + member.name ) )
- {
- out.name = name;
- out.location = member.location;
- out.binding = ubo.binding;
- out.bufferIndex = index;
- out.offset = member.offset;
- out.uniformClass = ShaderDetails::UniformClass::UNIFORM_BUFFER;
- return true;
- }
- }
- index++;
- }
-
- // check samplers
- for( auto&& uniform : mUniformOpaques )
- {
- if( uniform.name == name )
- {
- out.uniformClass = ShaderDetails::UniformClass::COMBINED_IMAGE_SAMPLER;
- out.binding = uniform.binding;
- out.name = name;
- out.offset = 0;
- out.location = 0;
- return true;
- }
- }
- return false;
-}
-
-std::vector< API::ShaderDetails::UniformInfo > Shader::GetSamplers() const
-{
- std::vector< API::ShaderDetails::UniformInfo > retval;
- for( auto&& uniform : mUniformOpaques )
- {
- if( uniform.type == vk::DescriptorType::eCombinedImageSampler )
- {
- API::ShaderDetails::UniformInfo info;
- info.location = 0u;
- info.binding = uniform.binding;
- info.offset = 0;
- info.name = uniform.name;
- info.uniformClass = API::ShaderDetails::UniformClass::COMBINED_IMAGE_SAMPLER;
- retval.emplace_back( info );
- }
- }
- std::sort( retval.begin(), retval.end(),
- []( const API::ShaderDetails::UniformInfo& a, const API::ShaderDetails::UniformInfo& b ) {
- return a.binding < b.binding;
- } );
-
- return retval;
-}
-
-uint32_t Shader::GetUniformBlockCount() const
-{
- return U32( mUniformBlocks.size() );
-}
-
-uint32_t Shader::GetUniformBlockSize( uint32_t index ) const
-{
- return U32( mUniformBlocks[index].size );
-}
-
-uint32_t Shader::GetUniformBlockBinding( uint32_t index ) const
-{
- return U32( mUniformBlocks[index].binding );
-}
-
-bool Shader::GetUniformBlock( uint32_t index, API::ShaderDetails::UniformBlockInfo& out ) const
-{
- if( index >= mUniformBlocks.size() )
- {
- return false;
- }
-
- const auto& block = mUniformBlocks[index];
-
- out.name = block.name;
- out.binding = block.binding;
- out.descriptorSet = block.descriptorSet;
- auto membersSize = block.members.size();
- out.members.resize( membersSize );
- out.size = block.size;
- for( auto i = 0u; i < out.members.size(); ++i )
- {
- const auto& memberUniform = block.members[i];
- out.members[i].name = memberUniform.name;
- out.members[i].binding = block.binding;
- out.members[i].uniformClass = API::ShaderDetails::UniformClass::UNIFORM_BUFFER;
- out.members[i].offset = memberUniform.offset;
- out.members[i].location = memberUniform.location;
- }
-
- return true;
-}
-
-
-} // namespace VulkanAPI
-} // namespace Graphics
-} // namespace Dali
+++ /dev/null
-#ifndef DALI_GRAPHICS_VULKAN_API_SHADER_H
-#define DALI_GRAPHICS_VULKAN_API_SHADER_H
-
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics-api/graphics-api-shader.h>
-#include <dali/graphics-api/graphics-api-shader-details.h>
-#include <dali/graphics/vulkan/internal/vulkan-types.h>
-#include <dali/graphics/vulkan/internal/spirv/vulkan-spirv.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace VulkanAPI
-{
-/**
- * @brief API::Shader represents program conceptually
- */
-class Shader : public Dali::Graphics::API::Shader
-{
-public:
- // not copyable
- Shader( const Shader& ) = delete;
-
- Shader& operator=( const Shader& ) = delete;
-
- ~Shader() override = default;
-
- explicit Shader( Vulkan::Graphics& graphics );
-
- bool AddShaderModule( Dali::Graphics::API::ShaderDetails::PipelineStage pipelineStage,
- Dali::Graphics::API::ShaderDetails::Language language,
- Dali::Graphics::API::ShaderDetails::ShaderSource shaderSource );
-
- Vulkan::RefCountedShader GetShader( vk::ShaderStageFlagBits shaderStage ) const;
-
- static Shader& DownCast( Dali::Graphics::API::Shader& shader );
-
- Vulkan::RefCountedShader GetShaderRef( vk::ShaderStageFlagBits shaderStage ) const;
-
-
- // REFLECTION
-
- // Vertex attributes
- bool IsReflectionSupported() const override;
-
- uint32_t GetVertexAttributeLocation( const std::string& name ) const override;
-
- API::ShaderDetails::VertexInputAttributeFormat GetVertexAttributeFormat( uint32_t location ) const override;
-
- std::string GetVertexAttributeName( uint32_t location ) const override;
-
- std::vector< uint32_t > GetVertexAttributeLocations() const override;
-
- /**
- * Uniforms
- */
-
- std::vector< uint32_t > GetUniformBlockLocations() const;
-
- std::string GetUniformBlockName( uint32_t blockIndex ) const;
-
- uint32_t GetUniformBlockMemberCount( uint32_t blockIndex ) const;
-
- std::string GetUniformBlockMemberName( uint32_t blockIndex, uint32_t memberLocation ) const;
-
- uint32_t GetUniformBlockMemberOffset( uint32_t blockIndex, uint32_t memberLocation ) const;
-
- bool GetNamedUniform( const std::string& name, API::ShaderDetails::UniformInfo& out ) const override;
-
- std::vector< API::ShaderDetails::UniformInfo > GetSamplers() const override;
-
- uint32_t GetUniformBlockCount() const override;
-
- uint32_t GetUniformBlockSize( uint32_t index ) const override;
-
- uint32_t GetUniformBlockBinding( uint32_t index ) const override;
-
- bool GetUniformBlock( uint32_t index, API::ShaderDetails::UniformBlockInfo& out ) const override;
-
-protected:
- // derived types should not be moved direcly to prevent slicing
- Shader( Shader&& ) = default;
-
- Shader& operator=( Shader&& ) = default;
-
- Shader() = default;
-
-private:
-
- Vulkan::Graphics& mGraphics;
- Vulkan::RefCountedShader mVertexShader;
- Vulkan::RefCountedShader mFragmentShader;
-
- std::vector< Vulkan::SpirV::SPIRVVertexInputAttribute > mVertexInputAttributes;
- std::vector< Vulkan::SpirV::SPIRVUniformBlock > mUniformBlocks;
- std::vector< Vulkan::SpirV::SPIRVUniformOpaque > mUniformOpaques;
-};
-
-} // namespace Vulkan
-} // namespace Graphics
-} // namespace Dali
-#endif //DALI_GRAPHICS_VULKAN_API_SHADER_H
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics/vulkan/api/vulkan-api-texture-factory.h>
-#include <dali/graphics/vulkan/api/vulkan-api-texture.h>
-#include <dali/graphics/vulkan/api/vulkan-api-controller.h>
-#include <dali/graphics/vulkan/vulkan-graphics.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace VulkanAPI
-{
-
-struct TextureFactory::Impl
-{
- Impl( TextureFactory& api, VulkanAPI::Controller& controller )
- : mApi( api ),
- mController( controller ),
- mGraphics( controller.GetGraphics() )
- {
-
- }
-
- ~Impl() = default;
-
- std::unique_ptr< Graphics::API::Texture > Create()
- {
- auto retval = std::make_unique< VulkanAPI::Texture >( static_cast<Graphics::API::TextureFactory&>(mApi) );
-
- if( retval->Initialise() )
- {
- return std::move( retval );
- }
-
- return nullptr;
- }
-
- TextureFactory& mApi;
- VulkanAPI::Controller& mController;
- Vulkan::Graphics& mGraphics;
-
- API::TextureDetails::Type mType;
- API::TextureDetails::Usage mUsage;
- API::RectSize mSize;
- API::Format mFormat;
- API::TextureDetails::MipMapFlag mMipmapFlags;
- void* mData;
- uint32_t mDataSizeInBytes;
-
-};
-
-TextureFactory::TextureFactory( VulkanAPI::Controller& controller )
-{
- mImpl = std::make_unique< Impl >( *this, controller );
-}
-
-TextureFactory::~TextureFactory() = default;
-
-Graphics::API::TextureFactory& TextureFactory::SetType( API::TextureDetails::Type type )
-{
- mImpl->mType = type;
- return *this;
-}
-
-Graphics::API::TextureFactory& TextureFactory::SetSize( const API::RectSize& size )
-{
- mImpl->mSize = size;
- return *this;
-}
-
-Graphics::API::TextureFactory& TextureFactory::SetUsage( API::TextureDetails::Usage usage )
-{
- mImpl->mUsage = usage;
- return *this;
-}
-
-Graphics::API::TextureFactory& TextureFactory::SetFormat( API::TextureDetails::Format format )
-{
- mImpl->mFormat = format;
- return *this;
-}
-
-Graphics::API::TextureFactory& TextureFactory::SetMipMapFlag( API::TextureDetails::MipMapFlag mipMSapFlag )
-{
- mImpl->mMipmapFlags = mipMSapFlag;
- return *this;
-}
-
-Graphics::API::TextureFactory& TextureFactory::SetData( void* pData )
-{
- mImpl->mData = pData;
- return *this;
-}
-
-Graphics::API::TextureFactory& TextureFactory::SetDataSize( uint32_t dataSizeInBytes )
-{
- mImpl->mDataSizeInBytes = dataSizeInBytes;
- return *this;
-}
-
-std::unique_ptr< Graphics::API::Texture > TextureFactory::Create() const
-{
- return mImpl->Create();
-}
-
-const API::TextureDetails::Type& TextureFactory::GetType() const
-{
- return mImpl->mType;
-}
-
-const API::TextureDetails::Usage& TextureFactory::GetUsage() const
-{
- return mImpl->mUsage;
-}
-
-const API::RectSize& TextureFactory::GetSize() const
-{
- return mImpl->mSize;
-}
-
-const API::TextureDetails::Format& TextureFactory::GetFormat() const
-{
- return mImpl->mFormat;
-}
-
-const API::TextureDetails::MipMapFlag& TextureFactory::GetMipMapFlag() const
-{
- return mImpl->mMipmapFlags;
-}
-
-const void* TextureFactory::GetData() const
-{
- return mImpl->mData;
-}
-
-uint32_t TextureFactory::GetDataSize() const
-{
- return mImpl->mDataSizeInBytes;
-}
-
-Vulkan::Graphics& TextureFactory::GetGraphics() const
-{
- return mImpl->mGraphics;
-}
-
-VulkanAPI::Controller& TextureFactory::GetController() const
-{
- return mImpl->mController;
-}
-
-
-}
-}
-}
+++ /dev/null
-#ifndef DALI_GRAPHICS_VULKAN_API_TEXTURE_FACTORY_H
-#define DALI_GRAPHICS_VULKAN_API_TEXTURE_FACTORY_H
-
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics-api/graphics-api-texture-factory.h>
-#include <dali/graphics-api/graphics-api-texture-details.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-class Graphics;
-}
-namespace VulkanAPI
-{
-class Controller;
-class TextureFactory : public Dali::Graphics::API::TextureFactory
-{
-public:
-
- explicit TextureFactory( VulkanAPI::Controller& controller );
-
- Graphics::API::TextureFactory& SetType( API::TextureDetails::Type type ) override;
-
- Graphics::API::TextureFactory& SetSize( const API::RectSize& size ) override;
-
- Graphics::API::TextureFactory& SetFormat( API::TextureDetails::Format format ) override;
-
- Graphics::API::TextureFactory& SetMipMapFlag( API::TextureDetails::MipMapFlag mipMSapFlag ) override;
-
- Graphics::API::TextureFactory& SetUsage( API::TextureDetails::Usage usage ) override;
-
- Graphics::API::TextureFactory& SetData( void* pData ) override;
-
- Graphics::API::TextureFactory& SetDataSize( uint32_t dataSizeInBytes ) override;
-
- // not copyable
- TextureFactory( const TextureFactory& ) = delete;
-
- TextureFactory& operator=( const TextureFactory& ) = delete;
-
- ~TextureFactory() override;
-
- std::unique_ptr< Graphics::API::Texture > Create() const override;
-
- /** Internal interface */
- const API::TextureDetails::Type& GetType() const;
-
- const API::RectSize& GetSize() const;
-
- const API::TextureDetails::Format& GetFormat() const;
-
- const API::TextureDetails::Usage& GetUsage() const;
-
- const API::TextureDetails::MipMapFlag& GetMipMapFlag() const;
-
- const void* GetData() const;
-
- uint32_t GetDataSize() const;
-
- Vulkan::Graphics& GetGraphics() const;
-
- VulkanAPI::Controller& GetController() const;
-
-protected:
- /// @brief default constructor
- TextureFactory() = default;
-
- // derived types should not be moved direcly to prevent slicing
- TextureFactory( TextureFactory&& ) = default;
-
- TextureFactory& operator=( TextureFactory&& ) = default;
-
-private:
-
- struct Impl;
- std::unique_ptr< Impl > mImpl;
-};
-
-}
-}
-}
-
-#endif //DALI_GRAPHICS_VULKAN_API_TEXTURE_FACTORY_H
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// CLASS HEADER
-#include <dali/graphics/vulkan/api/vulkan-api-texture.h>
-
-// INTERNAL INCLUDES
-#include <dali/graphics/vulkan/vulkan-graphics.h>
-#include <dali/graphics/vulkan/internal/vulkan-buffer.h>
-#include <dali/graphics/vulkan/internal/vulkan-command-buffer.h>
-#include <dali/graphics/vulkan/internal/vulkan-command-pool.h>
-#include <dali/graphics/vulkan/internal/vulkan-image.h>
-#include <dali/graphics/vulkan/internal/vulkan-image-view.h>
-#include <dali/graphics/vulkan/internal/vulkan-fence.h>
-#include <dali/graphics/vulkan/internal/vulkan-sampler.h>
-#include <dali/graphics/vulkan/internal/vulkan-utils.h>
-#include <dali/graphics/vulkan/api/vulkan-api-controller.h>
-#include <dali/graphics/vulkan/api/vulkan-api-buffer.h>
-#include <dali/graphics/vulkan/api/vulkan-api-texture-factory.h>
-
-#include <algorithm>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace VulkanAPI
-{
-using namespace Dali::Graphics::Vulkan;
-
-
-/**
- * Remaps components
- */
-inline vk::ComponentMapping GetVkComponentMapping( API::Format format )
-{
- switch( format )
- {
- case API::Format::L8:
- {
- return vk::ComponentMapping{
- vk::ComponentSwizzle::eR,
- vk::ComponentSwizzle::eR,
- vk::ComponentSwizzle::eR,
- vk::ComponentSwizzle::eOne
- };
- }
- case API::Format::L8A8:
- {
- return vk::ComponentMapping{
- vk::ComponentSwizzle::eR,
- vk::ComponentSwizzle::eR,
- vk::ComponentSwizzle::eR,
- vk::ComponentSwizzle::eG,
- };
- }
- default:
- {
- return vk::ComponentMapping{
- vk::ComponentSwizzle::eR,
- vk::ComponentSwizzle::eG,
- vk::ComponentSwizzle::eB,
- vk::ComponentSwizzle::eA
- };
- }
- }
-}
-
-/**
- * Converts API pixel format to Vulkan
- */
-constexpr vk::Format ConvertApiToVk( API::Format format )
-{
- switch( format )
- {
- case API::Format::L8:
- {
- return vk::Format::eR8Unorm;
- }
- case API::Format::L8A8:
- {
- return vk::Format::eR8G8Unorm;
- }
- case API::Format::UNDEFINED:
- {
- return vk::Format::eUndefined;
- }
- case API::Format::R4G4_UNORM_PACK8:
- {
- return vk::Format::eR4G4UnormPack8;
- }
- case API::Format::R4G4B4A4_UNORM_PACK16:
- {
- return vk::Format::eR4G4B4A4UnormPack16;
- }
- case API::Format::B4G4R4A4_UNORM_PACK16:
- {
- return vk::Format::eB4G4R4A4UnormPack16;
- }
- case API::Format::R5G6B5_UNORM_PACK16:
- {
- return vk::Format::eR5G6B5UnormPack16;
- }
- case API::Format::B5G6R5_UNORM_PACK16:
- {
- return vk::Format::eB5G6R5UnormPack16;
- }
- case API::Format::R5G5B5A1_UNORM_PACK16:
- {
- return vk::Format::eR5G5B5A1UnormPack16;
- }
- case API::Format::B5G5R5A1_UNORM_PACK16:
- {
- return vk::Format::eB5G5R5A1UnormPack16;
- }
- case API::Format::A1R5G5B5_UNORM_PACK16:
- {
- return vk::Format::eA1R5G5B5UnormPack16;
- }
- case API::Format::R8_UNORM:
- {
- return vk::Format::eR8Unorm;
- }
- case API::Format::R8_SNORM:
- {
- return vk::Format::eR8Snorm;
- }
- case API::Format::R8_USCALED:
- {
- return vk::Format::eR8Uscaled;
- }
- case API::Format::R8_SSCALED:
- {
- return vk::Format::eR8Sscaled;
- }
- case API::Format::R8_UINT:
- {
- return vk::Format::eR8Uint;
- }
- case API::Format::R8_SINT:
- {
- return vk::Format::eR8Sint;
- }
- case API::Format::R8_SRGB:
- {
- return vk::Format::eR8Srgb;
- }
- case API::Format::R8G8_UNORM:
- {
- return vk::Format::eR8G8Unorm;
- }
- case API::Format::R8G8_SNORM:
- {
- return vk::Format::eR8G8Snorm;
- }
- case API::Format::R8G8_USCALED:
- {
- return vk::Format::eR8G8Uscaled;
- }
- case API::Format::R8G8_SSCALED:
- {
- return vk::Format::eR8G8Sscaled;
- }
- case API::Format::R8G8_UINT:
- {
- return vk::Format::eR8G8Uint;
- }
- case API::Format::R8G8_SINT:
- {
- return vk::Format::eR8G8Sint;
- }
- case API::Format::R8G8_SRGB:
- {
- return vk::Format::eR8G8Srgb;
- }
- case API::Format::R8G8B8_UNORM:
- {
- return vk::Format::eR8G8B8Unorm;
- }
- case API::Format::R8G8B8_SNORM:
- {
- return vk::Format::eR8G8B8Snorm;
- }
- case API::Format::R8G8B8_USCALED:
- {
- return vk::Format::eR8G8B8Uscaled;
- }
- case API::Format::R8G8B8_SSCALED:
- {
- return vk::Format::eR8G8B8Sscaled;
- }
- case API::Format::R8G8B8_UINT:
- {
- return vk::Format::eR8G8B8Uint;
- }
- case API::Format::R8G8B8_SINT:
- {
- return vk::Format::eR8G8B8Sint;
- }
- case API::Format::R8G8B8_SRGB:
- {
- return vk::Format::eR8G8B8Srgb;
- }
- case API::Format::B8G8R8_UNORM:
- {
- return vk::Format::eB8G8R8Unorm;
- }
- case API::Format::B8G8R8_SNORM:
- {
- return vk::Format::eB8G8R8Snorm;
- }
- case API::Format::B8G8R8_USCALED:
- {
- return vk::Format::eB8G8R8Uscaled;
- }
- case API::Format::B8G8R8_SSCALED:
- {
- return vk::Format::eB8G8R8Sscaled;
- }
- case API::Format::B8G8R8_UINT:
- {
- return vk::Format::eB8G8R8Uint;
- }
- case API::Format::B8G8R8_SINT:
- {
- return vk::Format::eB8G8R8Sint;
- }
- case API::Format::B8G8R8_SRGB:
- {
- return vk::Format::eB8G8R8Srgb;
- }
- case API::Format::R8G8B8A8_UNORM:
- {
- return vk::Format::eR8G8B8A8Unorm;
- }
- case API::Format::R8G8B8A8_SNORM:
- {
- return vk::Format::eR8G8B8A8Snorm;
- }
- case API::Format::R8G8B8A8_USCALED:
- {
- return vk::Format::eR8G8B8A8Uscaled;
- }
- case API::Format::R8G8B8A8_SSCALED:
- {
- return vk::Format::eR8G8B8A8Sscaled;
- }
- case API::Format::R8G8B8A8_UINT:
- {
- return vk::Format::eR8G8B8A8Uint;
- }
- case API::Format::R8G8B8A8_SINT:
- {
- return vk::Format::eR8G8B8A8Sint;
- }
- case API::Format::R8G8B8A8_SRGB:
- {
- return vk::Format::eR8G8B8A8Srgb;
- }
- case API::Format::B8G8R8A8_UNORM:
- {
- return vk::Format::eB8G8R8A8Unorm;
- }
- case API::Format::B8G8R8A8_SNORM:
- {
- return vk::Format::eB8G8R8A8Snorm;
- }
- case API::Format::B8G8R8A8_USCALED:
- {
- return vk::Format::eB8G8R8A8Uscaled;
- }
- case API::Format::B8G8R8A8_SSCALED:
- {
- return vk::Format::eB8G8R8A8Sscaled;
- }
- case API::Format::B8G8R8A8_UINT:
- {
- return vk::Format::eB8G8R8A8Uint;
- }
- case API::Format::B8G8R8A8_SINT:
- {
- return vk::Format::eB8G8R8A8Sint;
- }
- case API::Format::B8G8R8A8_SRGB:
- {
- return vk::Format::eB8G8R8A8Srgb;
- }
- case API::Format::A8B8G8R8_UNORM_PACK32:
- {
- return vk::Format::eA8B8G8R8UnormPack32;
- }
- case API::Format::A8B8G8R8_SNORM_PACK32:
- {
- return vk::Format::eA8B8G8R8SnormPack32;
- }
- case API::Format::A8B8G8R8_USCALED_PACK32:
- {
- return vk::Format::eA8B8G8R8UscaledPack32;
- }
- case API::Format::A8B8G8R8_SSCALED_PACK32:
- {
- return vk::Format::eA8B8G8R8SscaledPack32;
- }
- case API::Format::A8B8G8R8_UINT_PACK32:
- {
- return vk::Format::eA8B8G8R8UintPack32;
- }
- case API::Format::A8B8G8R8_SINT_PACK32:
- {
- return vk::Format::eA8B8G8R8SintPack32;
- }
- case API::Format::A8B8G8R8_SRGB_PACK32:
- {
- return vk::Format::eA8B8G8R8SrgbPack32;
- }
- case API::Format::A2R10G10B10_UNORM_PACK32:
- {
- return vk::Format::eA2R10G10B10UnormPack32;
- }
- case API::Format::A2R10G10B10_SNORM_PACK32:
- {
- return vk::Format::eA2R10G10B10SnormPack32;
- }
- case API::Format::A2R10G10B10_USCALED_PACK32:
- {
- return vk::Format::eA2R10G10B10UscaledPack32;
- }
- case API::Format::A2R10G10B10_SSCALED_PACK32:
- {
- return vk::Format::eA2R10G10B10SscaledPack32;
- }
- case API::Format::A2R10G10B10_UINT_PACK32:
- {
- return vk::Format::eA2R10G10B10UintPack32;
- }
- case API::Format::A2R10G10B10_SINT_PACK32:
- {
- return vk::Format::eA2R10G10B10SintPack32;
- }
- case API::Format::A2B10G10R10_UNORM_PACK32:
- {
- return vk::Format::eA2B10G10R10UnormPack32;
- }
- case API::Format::A2B10G10R10_SNORM_PACK32:
- {
- return vk::Format::eA2B10G10R10SnormPack32;
- }
- case API::Format::A2B10G10R10_USCALED_PACK32:
- {
- return vk::Format::eA2B10G10R10UscaledPack32;
- }
- case API::Format::A2B10G10R10_SSCALED_PACK32:
- {
- return vk::Format::eA2B10G10R10SscaledPack32;
- }
- case API::Format::A2B10G10R10_UINT_PACK32:
- {
- return vk::Format::eA2B10G10R10UintPack32;
- }
- case API::Format::A2B10G10R10_SINT_PACK32:
- {
- return vk::Format::eA2B10G10R10SintPack32;
- }
- case API::Format::R16_UNORM:
- {
- return vk::Format::eR16Unorm;
- }
- case API::Format::R16_SNORM:
- {
- return vk::Format::eR16Snorm;
- }
- case API::Format::R16_USCALED:
- {
- return vk::Format::eR16Uscaled;
- }
- case API::Format::R16_SSCALED:
- {
- return vk::Format::eR16Sscaled;
- }
- case API::Format::R16_UINT:
- {
- return vk::Format::eR16Uint;
- }
- case API::Format::R16_SINT:
- {
- return vk::Format::eR16Sint;
- }
- case API::Format::R16_SFLOAT:
- {
- return vk::Format::eR16Sfloat;
- }
- case API::Format::R16G16_UNORM:
- {
- return vk::Format::eR16G16Unorm;
- }
- case API::Format::R16G16_SNORM:
- {
- return vk::Format::eR16G16Snorm;
- }
- case API::Format::R16G16_USCALED:
- {
- return vk::Format::eR16G16Uscaled;
- }
- case API::Format::R16G16_SSCALED:
- {
- return vk::Format::eR16G16Sscaled;
- }
- case API::Format::R16G16_UINT:
- {
- return vk::Format::eR16G16Uint;
- }
- case API::Format::R16G16_SINT:
- {
- return vk::Format::eR16G16Sint;
- }
- case API::Format::R16G16_SFLOAT:
- {
- return vk::Format::eR16G16Sfloat;
- }
- case API::Format::R16G16B16_UNORM:
- {
- return vk::Format::eR16G16B16Unorm;
- }
- case API::Format::R16G16B16_SNORM:
- {
- return vk::Format::eR16G16B16Snorm;
- }
- case API::Format::R16G16B16_USCALED:
- {
- return vk::Format::eR16G16B16Uscaled;
- }
- case API::Format::R16G16B16_SSCALED:
- {
- return vk::Format::eR16G16B16Sscaled;
- }
- case API::Format::R16G16B16_UINT:
- {
- return vk::Format::eR16G16B16Uint;
- }
- case API::Format::R16G16B16_SINT:
- {
- return vk::Format::eR16G16B16Sint;
- }
- case API::Format::R16G16B16_SFLOAT:
- {
- return vk::Format::eR16G16B16Sfloat;
- }
- case API::Format::R16G16B16A16_UNORM:
- {
- return vk::Format::eR16G16B16A16Unorm;
- }
- case API::Format::R16G16B16A16_SNORM:
- {
- return vk::Format::eR16G16B16A16Snorm;
- }
- case API::Format::R16G16B16A16_USCALED:
- {
- return vk::Format::eR16G16B16A16Uscaled;
- }
- case API::Format::R16G16B16A16_SSCALED:
- {
- return vk::Format::eR16G16B16A16Sscaled;
- }
- case API::Format::R16G16B16A16_UINT:
- {
- return vk::Format::eR16G16B16A16Uint;
- }
- case API::Format::R16G16B16A16_SINT:
- {
- return vk::Format::eR16G16B16A16Sint;
- }
- case API::Format::R16G16B16A16_SFLOAT:
- {
- return vk::Format::eR16G16B16A16Sfloat;
- }
- case API::Format::R32_UINT:
- {
- return vk::Format::eR32Uint;
- }
- case API::Format::R32_SINT:
- {
- return vk::Format::eR32Sint;
- }
- case API::Format::R32_SFLOAT:
- {
- return vk::Format::eR32Sfloat;
- }
- case API::Format::R32G32_UINT:
- {
- return vk::Format::eR32G32Uint;
- }
- case API::Format::R32G32_SINT:
- {
- return vk::Format::eR32G32Sint;
- }
- case API::Format::R32G32_SFLOAT:
- {
- return vk::Format::eR32G32Sfloat;
- }
- case API::Format::R32G32B32_UINT:
- {
- return vk::Format::eR32G32B32Uint;
- }
- case API::Format::R32G32B32_SINT:
- {
- return vk::Format::eR32G32B32Sint;
- }
- case API::Format::R32G32B32_SFLOAT:
- {
- return vk::Format::eR32G32B32Sfloat;
- }
- case API::Format::R32G32B32A32_UINT:
- {
- return vk::Format::eR32G32B32A32Uint;
- }
- case API::Format::R32G32B32A32_SINT:
- {
- return vk::Format::eR32G32B32A32Sint;
- }
- case API::Format::R32G32B32A32_SFLOAT:
- {
- return vk::Format::eR32G32B32A32Sfloat;
- }
- case API::Format::R64_UINT:
- {
- return vk::Format::eR64Uint;
- }
- case API::Format::R64_SINT:
- {
- return vk::Format::eR64Sint;
- }
- case API::Format::R64_SFLOAT:
- {
- return vk::Format::eR64Sfloat;
- }
- case API::Format::R64G64_UINT:
- {
- return vk::Format::eR64G64Uint;
- }
- case API::Format::R64G64_SINT:
- {
- return vk::Format::eR64G64Sint;
- }
- case API::Format::R64G64_SFLOAT:
- {
- return vk::Format::eR64G64Sfloat;
- }
- case API::Format::R64G64B64_UINT:
- {
- return vk::Format::eR64G64B64Uint;
- }
- case API::Format::R64G64B64_SINT:
- {
- return vk::Format::eR64G64B64Sint;
- }
- case API::Format::R64G64B64_SFLOAT:
- {
- return vk::Format::eR64G64B64Sfloat;
- }
- case API::Format::R64G64B64A64_UINT:
- {
- return vk::Format::eR64G64B64A64Uint;
- }
- case API::Format::R64G64B64A64_SINT:
- {
- return vk::Format::eR64G64B64A64Sint;
- }
- case API::Format::R64G64B64A64_SFLOAT:
- {
- return vk::Format::eR64G64B64A64Sfloat;
- }
- case API::Format::B10G11R11_UFLOAT_PACK32:
- {
- return vk::Format::eB10G11R11UfloatPack32;
- }
- case API::Format::E5B9G9R9_UFLOAT_PACK32:
- {
- return vk::Format::eE5B9G9R9UfloatPack32;
- }
- case API::Format::D16_UNORM:
- {
- return vk::Format::eD16Unorm;
- }
- case API::Format::X8_D24_UNORM_PACK32:
- {
- return vk::Format::eX8D24UnormPack32;
- }
- case API::Format::D32_SFLOAT:
- {
- return vk::Format::eD32Sfloat;
- }
- case API::Format::S8_UINT:
- {
- return vk::Format::eS8Uint;
- }
- case API::Format::D16_UNORM_S8_UINT:
- {
- return vk::Format::eD16UnormS8Uint;
- }
- case API::Format::D24_UNORM_S8_UINT:
- {
- return vk::Format::eD24UnormS8Uint;
- }
- case API::Format::D32_SFLOAT_S8_UINT:
- {
- return vk::Format::eD32SfloatS8Uint;
- }
- case API::Format::BC1_RGB_UNORM_BLOCK:
- {
- return vk::Format::eBc1RgbUnormBlock;
- }
- case API::Format::BC1_RGB_SRGB_BLOCK:
- {
- return vk::Format::eBc1RgbSrgbBlock;
- }
- case API::Format::BC1_RGBA_UNORM_BLOCK:
- {
- return vk::Format::eBc1RgbaUnormBlock;
- }
- case API::Format::BC1_RGBA_SRGB_BLOCK:
- {
- return vk::Format::eBc1RgbaSrgbBlock;
- }
- case API::Format::BC2_UNORM_BLOCK:
- {
- return vk::Format::eBc2UnormBlock;
- }
- case API::Format::BC2_SRGB_BLOCK:
- {
- return vk::Format::eBc2SrgbBlock;
- }
- case API::Format::BC3_UNORM_BLOCK:
- {
- return vk::Format::eBc3UnormBlock;
- }
- case API::Format::BC3_SRGB_BLOCK:
- {
- return vk::Format::eBc3SrgbBlock;
- }
- case API::Format::BC4_UNORM_BLOCK:
- {
- return vk::Format::eBc4UnormBlock;
- }
- case API::Format::BC4_SNORM_BLOCK:
- {
- return vk::Format::eBc4SnormBlock;
- }
- case API::Format::BC5_UNORM_BLOCK:
- {
- return vk::Format::eBc5UnormBlock;
- }
- case API::Format::BC5_SNORM_BLOCK:
- {
- return vk::Format::eBc5SnormBlock;
- }
- case API::Format::BC6H_UFLOAT_BLOCK:
- {
- return vk::Format::eBc6HUfloatBlock;
- }
- case API::Format::BC6H_SFLOAT_BLOCK:
- {
- return vk::Format::eBc6HSfloatBlock;
- }
- case API::Format::BC7_UNORM_BLOCK:
- {
- return vk::Format::eBc7UnormBlock;
- }
- case API::Format::BC7_SRGB_BLOCK:
- {
- return vk::Format::eBc7SrgbBlock;
- }
- case API::Format::ETC2_R8G8B8_UNORM_BLOCK:
- {
- return vk::Format::eEtc2R8G8B8UnormBlock;
- }
- case API::Format::ETC2_R8G8B8_SRGB_BLOCK:
- {
- return vk::Format::eEtc2R8G8B8SrgbBlock;
- }
- case API::Format::ETC2_R8G8B8A1_UNORM_BLOCK:
- {
- return vk::Format::eEtc2R8G8B8A1UnormBlock;
- }
- case API::Format::ETC2_R8G8B8A1_SRGB_BLOCK:
- {
- return vk::Format::eEtc2R8G8B8A1SrgbBlock;
- }
- case API::Format::ETC2_R8G8B8A8_UNORM_BLOCK:
- {
- return vk::Format::eEtc2R8G8B8A8UnormBlock;
- }
- case API::Format::ETC2_R8G8B8A8_SRGB_BLOCK:
- {
- return vk::Format::eEtc2R8G8B8A8SrgbBlock;
- }
- case API::Format::EAC_R11_UNORM_BLOCK:
- {
- return vk::Format::eEacR11UnormBlock;
- }
- case API::Format::EAC_R11_SNORM_BLOCK:
- {
- return vk::Format::eEacR11SnormBlock;
- }
- case API::Format::EAC_R11G11_UNORM_BLOCK:
- {
- return vk::Format::eEacR11G11UnormBlock;
- }
- case API::Format::EAC_R11G11_SNORM_BLOCK:
- {
- return vk::Format::eEacR11G11SnormBlock;
- }
- case API::Format::ASTC_4x4_UNORM_BLOCK:
- {
- return vk::Format::eAstc4x4UnormBlock;
- }
- case API::Format::ASTC_4x4_SRGB_BLOCK:
- {
- return vk::Format::eAstc4x4SrgbBlock;
- }
- case API::Format::ASTC_5x4_UNORM_BLOCK:
- {
- return vk::Format::eAstc5x4UnormBlock;
- }
- case API::Format::ASTC_5x4_SRGB_BLOCK:
- {
- return vk::Format::eAstc5x4SrgbBlock;
- }
- case API::Format::ASTC_5x5_UNORM_BLOCK:
- {
- return vk::Format::eAstc5x5UnormBlock;
- }
- case API::Format::ASTC_5x5_SRGB_BLOCK:
- {
- return vk::Format::eAstc5x5SrgbBlock;
- }
- case API::Format::ASTC_6x5_UNORM_BLOCK:
- {
- return vk::Format::eAstc6x5UnormBlock;
- }
- case API::Format::ASTC_6x5_SRGB_BLOCK:
- {
- return vk::Format::eAstc6x5SrgbBlock;
- }
- case API::Format::ASTC_6x6_UNORM_BLOCK:
- {
- return vk::Format::eAstc6x6UnormBlock;
- }
- case API::Format::ASTC_6x6_SRGB_BLOCK:
- {
- return vk::Format::eAstc6x6SrgbBlock;
- }
- case API::Format::ASTC_8x5_UNORM_BLOCK:
- {
- return vk::Format::eAstc8x5UnormBlock;
- }
- case API::Format::ASTC_8x5_SRGB_BLOCK:
- {
- return vk::Format::eAstc8x5SrgbBlock;
- }
- case API::Format::ASTC_8x6_UNORM_BLOCK:
- {
- return vk::Format::eAstc8x6UnormBlock;
- }
- case API::Format::ASTC_8x6_SRGB_BLOCK:
- {
- return vk::Format::eAstc8x6SrgbBlock;
- }
- case API::Format::ASTC_8x8_UNORM_BLOCK:
- {
- return vk::Format::eAstc8x8UnormBlock;
- }
- case API::Format::ASTC_8x8_SRGB_BLOCK:
- {
- return vk::Format::eAstc8x8SrgbBlock;
- }
- case API::Format::ASTC_10x5_UNORM_BLOCK:
- {
- return vk::Format::eAstc10x5UnormBlock;
- }
- case API::Format::ASTC_10x5_SRGB_BLOCK:
- {
- return vk::Format::eAstc10x5SrgbBlock;
- }
- case API::Format::ASTC_10x6_UNORM_BLOCK:
- {
- return vk::Format::eAstc10x6UnormBlock;
- }
- case API::Format::ASTC_10x6_SRGB_BLOCK:
- {
- return vk::Format::eAstc10x6SrgbBlock;
- }
- case API::Format::ASTC_10x8_UNORM_BLOCK:
- {
- return vk::Format::eAstc10x8UnormBlock;
- }
- case API::Format::ASTC_10x8_SRGB_BLOCK:
- {
- return vk::Format::eAstc10x8SrgbBlock;
- }
- case API::Format::ASTC_10x10_UNORM_BLOCK:
- {
- return vk::Format::eAstc10x10UnormBlock;
- }
- case API::Format::ASTC_10x10_SRGB_BLOCK:
- {
- return vk::Format::eAstc10x10SrgbBlock;
- }
- case API::Format::ASTC_12x10_UNORM_BLOCK:
- {
- return vk::Format::eAstc12x10UnormBlock;
- }
- case API::Format::ASTC_12x10_SRGB_BLOCK:
- {
- return vk::Format::eAstc12x10SrgbBlock;
- }
- case API::Format::ASTC_12x12_UNORM_BLOCK:
- {
- return vk::Format::eAstc12x12UnormBlock;
- }
- case API::Format::ASTC_12x12_SRGB_BLOCK:
- {
- return vk::Format::eAstc12x12SrgbBlock;
- }
- case API::Format::PVRTC1_2BPP_UNORM_BLOCK_IMG:
- {
- return vk::Format::ePvrtc12BppUnormBlockIMG;
- }
- case API::Format::PVRTC1_4BPP_UNORM_BLOCK_IMG:
- {
- return vk::Format::ePvrtc14BppUnormBlockIMG;
- }
- case API::Format::PVRTC2_2BPP_UNORM_BLOCK_IMG:
- {
- return vk::Format::ePvrtc22BppUnormBlockIMG;
- }
- case API::Format::PVRTC2_4BPP_UNORM_BLOCK_IMG:
- {
- return vk::Format::ePvrtc24BppUnormBlockIMG;
- }
- case API::Format::PVRTC1_2BPP_SRGB_BLOCK_IMG:
- {
- return vk::Format::ePvrtc12BppSrgbBlockIMG;
- }
- case API::Format::PVRTC1_4BPP_SRGB_BLOCK_IMG:
- {
- return vk::Format::ePvrtc14BppSrgbBlockIMG;
- }
- case API::Format::PVRTC2_2BPP_SRGB_BLOCK_IMG:
- {
- return vk::Format::ePvrtc22BppSrgbBlockIMG;
- }
- case API::Format::PVRTC2_4BPP_SRGB_BLOCK_IMG:
- {
- return vk::Format::ePvrtc24BppSrgbBlockIMG;
- }
- }
- return {};
-}
-
-Texture::Texture( Dali::Graphics::API::TextureFactory& factory )
- : mTextureFactory( dynamic_cast<VulkanAPI::TextureFactory&>( factory ) ),
- mController( mTextureFactory.GetController() ),
- mGraphics( mTextureFactory.GetGraphics() ),
- mImage(),
- mImageView(),
- mSampler(),
- mWidth( 0u ),
- mHeight( 0u ),
- mFormat( vk::Format::eUndefined ),
- mUsage( vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eTransferDst ),
- mLayout( vk::ImageLayout::eUndefined ),
- mComponentMapping()
-{
-}
-
-Texture::~Texture()
-{
-
-}
-
-bool Texture::Initialise()
-{
- auto size = mTextureFactory.GetSize();
- mWidth = uint32_t( size.width );
- mHeight = uint32_t( size.height );
- auto sizeInBytes = mTextureFactory.GetDataSize();
- auto data = mTextureFactory.GetData();
- mLayout = vk::ImageLayout::eUndefined;
- switch( mTextureFactory.GetUsage())
- {
- case API::TextureDetails::Usage::COLOR_ATTACHMENT:
- {
- mUsage = vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eSampled;
- break;
- }
- case API::TextureDetails::Usage::DEPTH_ATTACHMENT:
- {
- mUsage = vk::ImageUsageFlagBits::eDepthStencilAttachment | vk::ImageUsageFlagBits::eSampled;
- break;
- }
- case API::TextureDetails::Usage::SAMPLE:
- {
- mUsage = vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eTransferDst;
- break;
- }
- }
-
- mFormat = ConvertApiToVk( mTextureFactory.GetFormat() );
- mComponentMapping = GetVkComponentMapping( mTextureFactory.GetFormat() );
-
- /**
- * Lots of Vulkan drivers DO NOT SUPPORT R8G8B8 format therefore we are forced
- * to implement a fallback as lots of textures comes as RGB ( ie. jpg ). In case
- * the valid format is supported we're going to use it as it is.
- */
- std::vector<uint8_t> rgbaBuffer{};
- if(mTextureFactory.GetFormat() == API::Format::R8G8B8_UNORM )
- {
- auto formatProperties = mGraphics.GetPhysicalDevice().getFormatProperties( mFormat );
- if( !formatProperties.optimalTilingFeatures )
- {
- if( data && sizeInBytes > 0 )
- {
- assert( (sizeInBytes == mWidth*mHeight*3) && "Corrupted RGB image data!" );
-
- auto inData = reinterpret_cast<const uint8_t*>(data);
-
- rgbaBuffer.reserve( mWidth * mHeight * 4 );
- auto outData = rgbaBuffer.data();
-
- auto outIdx = 0u;
- for( auto i = 0u; i < sizeInBytes; i += 3 )
- {
- outData[outIdx] = inData[i];
- outData[outIdx + 1] = inData[i + 1];
- outData[outIdx + 2] = inData[i + 2];
- outData[outIdx + 3] = 0xff;
- outIdx += 4;
- }
-
- data = outData;
- sizeInBytes = mWidth * mHeight * 4;
- mFormat = vk::Format::eR8G8B8A8Unorm;
- }
- }
- }
-
- if( InitialiseTexture() )
- {
- // copy data to the image
- if( data )
- {
- CopyMemory(data, sizeInBytes, {mWidth, mHeight}, {0, 0}, 0, 0, API::TextureDetails::UpdateMode::UNDEFINED );
- }
- return true;
- }
-
- return false;
-}
-
-void Texture::CopyMemory(const void *srcMemory, uint32_t srcMemorySize, API::Extent2D srcExtent, API::Offset2D dstOffset, uint32_t layer, uint32_t level, API::TextureDetails::UpdateMode updateMode )
-{
- // @todo transient buffer memory could be persistently mapped and aliased ( work like a per-frame stack )
- uint32_t allocationSize = 0u;
-
- auto requirements = mGraphics.GetDevice().getImageMemoryRequirements( mImage->GetVkHandle() );
- allocationSize = uint32_t( requirements.size );
-
- // allocate transient buffer
- auto buffer = mGraphics.CreateBuffer( vk::BufferCreateInfo{}
- .setSize( allocationSize )
- .setSharingMode( vk::SharingMode::eExclusive )
- .setUsage( vk::BufferUsageFlagBits::eTransferSrc));
-
- // bind memory
- mGraphics.BindBufferMemory( buffer,
- mGraphics.AllocateMemory( buffer, vk::MemoryPropertyFlagBits::eHostVisible|vk::MemoryPropertyFlagBits::eHostCoherent ),
- 0u );
-
- // write into the buffer
- auto ptr = buffer->GetMemory()->MapTyped<char>();
- std::copy( reinterpret_cast<const char*>(srcMemory), reinterpret_cast<const char*>(srcMemory)+srcMemorySize, ptr );
- buffer->GetMemory()->Unmap();
-
- ResourceTransferRequest transferRequest( TransferRequestType::BUFFER_TO_IMAGE );
-
- transferRequest.bufferToImageInfo.copyInfo
- .setImageSubresource( vk::ImageSubresourceLayers{}
- .setBaseArrayLayer( layer )
- .setLayerCount( 1 )
- .setAspectMask( vk::ImageAspectFlagBits::eColor )
- .setMipLevel( level ) )
- .setImageOffset({ dstOffset.x, dstOffset.y, 0 } )
- .setImageExtent({ srcExtent.width, srcExtent.height, 1 } )
- .setBufferRowLength({ 0u })
- .setBufferOffset({ 0u })
- .setBufferImageHeight( 0u );
-
- transferRequest.bufferToImageInfo.dstImage = mImage;
- transferRequest.bufferToImageInfo.srcBuffer = std::move(buffer);
- transferRequest.deferredTransferMode = !( updateMode == API::TextureDetails::UpdateMode::IMMEDIATE );
-
- assert( transferRequest.bufferToImageInfo.srcBuffer.GetRefCount() == 1 && "Too many transient buffer owners, buffer will be released automatically!" );
-
- // schedule transfer
- mController.ScheduleResourceTransfer( std::move(transferRequest) );
-}
-
-void Texture::CopyTexture(const API::Texture &srcTexture, API::Rect2D srcRegion, API::Offset2D dstOffset, uint32_t layer, uint32_t level, API::TextureDetails::UpdateMode updateMode )
-{
- ResourceTransferRequest transferRequest( TransferRequestType::IMAGE_TO_IMAGE );
-
- auto imageSubresourceLayers = vk::ImageSubresourceLayers{}
- .setAspectMask( vk::ImageAspectFlagBits::eColor )
- .setBaseArrayLayer( layer )
- .setLayerCount( 1 )
- .setMipLevel( level );
-
- transferRequest.imageToImageInfo.srcImage = static_cast<const VulkanAPI::Texture&>( srcTexture ).GetImageRef();
- transferRequest.imageToImageInfo.dstImage = mImage;
- transferRequest.imageToImageInfo.copyInfo
- .setSrcOffset( { srcRegion.x, srcRegion.y, 0 } )
- .setDstOffset( { dstOffset.x, dstOffset.y, 0 } )
- .setExtent( { srcRegion.width, srcRegion.height } )
- .setSrcSubresource( imageSubresourceLayers )
- .setDstSubresource( imageSubresourceLayers );
-
- transferRequest.deferredTransferMode = !( updateMode == API::TextureDetails::UpdateMode::IMMEDIATE );
-
- // schedule transfer
- mController.ScheduleResourceTransfer( std::move(transferRequest) );
-}
-
-void Texture::CopyBuffer(const API::Buffer &srcBuffer, API::Extent2D srcExtent, API::Offset2D dstOffset, uint32_t layer, uint32_t level, API::TextureDetails::UpdateMode updateMode )
-{
- ResourceTransferRequest transferRequest( TransferRequestType::BUFFER_TO_IMAGE );
-
- transferRequest.bufferToImageInfo.copyInfo
- .setImageSubresource( vk::ImageSubresourceLayers{}
- .setBaseArrayLayer( layer )
- .setLayerCount( 1 )
- .setAspectMask( vk::ImageAspectFlagBits::eColor )
- .setMipLevel( level ) )
- .setImageOffset({ dstOffset.x, dstOffset.y, 0 } )
- .setImageExtent({ srcExtent.width, srcExtent.height, 1 } )
- .setBufferRowLength({ 0u })
- .setBufferOffset({ 0u })
- .setBufferImageHeight({ srcExtent.height });
-
- transferRequest.bufferToImageInfo.dstImage = mImage;
- transferRequest.bufferToImageInfo.srcBuffer = static_cast<const VulkanAPI::Buffer&>(srcBuffer).GetBufferRef();
- transferRequest.deferredTransferMode = !( updateMode == API::TextureDetails::UpdateMode::IMMEDIATE );
-
- // schedule transfer
- mController.ScheduleResourceTransfer( std::move(transferRequest) );
-}
-
-// creates image with pre-allocated memory and default sampler, no data
-// uploaded at this point
-bool Texture::InitialiseTexture()
-{
- // Check whether format is supported by the platform
- auto properties = mGraphics.GetPhysicalDevice().getFormatProperties( mFormat );
-
- if( !properties.optimalTilingFeatures )
- {
- // terminate if not supported
- return false;
- }
-
- // create image
- auto imageCreateInfo = vk::ImageCreateInfo{}
- .setFormat( mFormat )
- .setInitialLayout( mLayout )
- .setSamples( vk::SampleCountFlagBits::e1 )
- .setSharingMode( vk::SharingMode::eExclusive )
- .setUsage( mUsage )
- .setExtent( { mWidth, mHeight, 1 } )
- .setArrayLayers( 1 )
- .setImageType( vk::ImageType::e2D )
- .setTiling( vk::ImageTiling::eOptimal )
- .setMipLevels( 1 );
-
- // Create the image handle
- mImage = mGraphics.CreateImage( imageCreateInfo );
-
- // allocate memory for the image
- auto memory = mGraphics.AllocateMemory( mImage, vk::MemoryPropertyFlagBits::eDeviceLocal );
-
- // bind the allocated memory to the image
- mGraphics.BindImageMemory( mImage, std::move(memory), 0 );
-
- // create default image view
- CreateImageView();
-
- // create basic sampler
- CreateSampler();
-
- return true;
-}
-
-void Texture::CreateImageView()
-{
- mImageView = mGraphics.CreateImageView(
- {}, mImage, vk::ImageViewType::e2D, mImage->GetFormat(), mComponentMapping,
- vk::ImageSubresourceRange{}
- .setAspectMask( mImage->GetAspectFlags() )
- .setBaseArrayLayer( 0 )
- .setBaseMipLevel( 0 )
- .setLevelCount( mImage->GetMipLevelCount() )
- .setLayerCount( mImage->GetLayerCount() )
- );
-}
-
-void Texture::CreateSampler()
-{
- auto samplerCreateInfo = vk::SamplerCreateInfo()
- .setAddressModeU( vk::SamplerAddressMode::eClampToEdge )
- .setAddressModeV( vk::SamplerAddressMode::eClampToEdge )
- .setAddressModeW( vk::SamplerAddressMode::eClampToEdge )
- .setBorderColor( vk::BorderColor::eFloatOpaqueBlack )
- .setCompareOp( vk::CompareOp::eNever )
- .setMinFilter( vk::Filter::eLinear )
- .setMagFilter( vk::Filter::eLinear )
- .setMipmapMode( vk::SamplerMipmapMode::eLinear )
- .setMaxAnisotropy( 1.0f ); // must be 1.0f when anisotropy feature isn't enabled
-
- mSampler = mGraphics.CreateSampler( samplerCreateInfo );
-}
-
-Vulkan::RefCountedImage Texture::GetImageRef() const
-{
- return mImage;
-}
-
-Vulkan::RefCountedImageView Texture::GetImageViewRef() const
-{
- return mImageView;
-}
-
-Vulkan::RefCountedSampler Texture::GetSamplerRef() const
-{
- return mSampler;
-}
-
-} // namespace VulkanAPI
-} // namespace Graphics
-} // namespace Dali
+++ /dev/null
-#ifndef DALI_GRAPHICS_VULKAN_API_TEXTURE_H
-#define DALI_GRAPHICS_VULKAN_API_TEXTURE_H
-
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// INTERNAL INCLUDES
-#include <dali/graphics-api/graphics-api-texture-factory.h>
-#include <dali/graphics-api/graphics-api-texture.h>
-#include <dali/graphics/vulkan/internal/vulkan-types.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-class Graphics;
-}
-namespace VulkanAPI
-{
-class TextureFactory;
-class Controller;
-
-/**
- * This is temporary implementation. It should be using graphics-texture as base
- * interface.
- */
-class Texture : public Dali::Graphics::API::Texture
-{
-public:
-
- explicit Texture( Dali::Graphics::API::TextureFactory& factory );
-
- ~Texture() override;
-
- bool Initialise();
-
- Vulkan::RefCountedImage GetImageRef() const;
-
- Vulkan::RefCountedImageView GetImageViewRef() const;
-
- Vulkan::RefCountedSampler GetSamplerRef() const;
-
- void CopyMemory( const void *srcMemory, uint32_t maxDataSize, API::Extent2D srcExtent, API::Offset2D dstOffset, uint32_t layer, uint32_t level, API::TextureDetails::UpdateMode updateMode ) override;
-
- void CopyTexture( const API::Texture &srcTexture, API::Rect2D srcRegion, API::Offset2D dstOffset, uint32_t layer, uint32_t level, API::TextureDetails::UpdateMode updateMode ) override;
-
- void CopyBuffer( const API::Buffer &srcBuffer, API::Extent2D srcExtent, API::Offset2D dstOffset, uint32_t layer, uint32_t level, API::TextureDetails::UpdateMode updateMode) override;
-
-private:
-
- void CreateSampler();
- void CreateImageView();
- bool InitialiseTexture();
-
-private:
-
- VulkanAPI::TextureFactory& mTextureFactory;
- VulkanAPI::Controller& mController;
- Vulkan::Graphics& mGraphics;
-
- Vulkan::RefCountedImage mImage;
- Vulkan::RefCountedImageView mImageView;
- Vulkan::RefCountedSampler mSampler;
-
- uint32_t mWidth;
- uint32_t mHeight;
- vk::Format mFormat;
- vk::ImageUsageFlags mUsage;
- vk::ImageLayout mLayout;
- vk::ComponentMapping mComponentMapping{};
-};
-
-} // namespace VulkanAPI
-} // namespace Graphics
-} // namespace Dali
-#endif // DALI_GRAPHICS_VULKAN_API_TEXTURE_H
+++ /dev/null
-/*
-** Copyright (c) 2014-2018 The Khronos Group Inc.
-**
-** Permission is hereby granted, free of charge, to any person obtaining a copy
-** of this software and/or associated documentation files (the "Materials"),
-** to deal in the Materials without restriction, including without limitation
-** the rights to use, copy, modify, merge, publish, distribute, sublicense,
-** and/or sell copies of the Materials, and to permit persons to whom the
-** Materials are furnished to do so, subject to the following conditions:
-**
-** The above copyright notice and this permission notice shall be included in
-** all copies or substantial portions of the Materials.
-**
-** MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS KHRONOS
-** STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS SPECIFICATIONS AND
-** HEADER INFORMATION ARE LOCATED AT https://www.khronos.org/registry/
-**
-** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-** OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
-** THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-** FROM,OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS
-** IN THE MATERIALS.
-*/
-
-/*
-** This header is automatically generated by the same tool that creates
-** the Binary Section of the SPIR-V specification.
-*/
-
-/*
-** Enumeration tokens for SPIR-V, in various styles:
-** C, C++, C++11, JSON, Lua, Python
-**
-** - C will have tokens with a "Spv" prefix, e.g.: SpvSourceLanguageGLSL
-** - C++ will have tokens in the "spv" name space, e.g.: spv::SourceLanguageGLSL
-** - C++11 will use enum classes in the spv namespace, e.g.: spv::SourceLanguage::GLSL
-** - Lua will use tables, e.g.: spv.SourceLanguage.GLSL
-** - Python will use dictionaries, e.g.: spv['SourceLanguage']['GLSL']
-**
-** Some tokens act like mask values, which can be OR'd together,
-** while others are mutually exclusive. The mask-like ones have
-** "Mask" in their name, and a parallel enum that has the shift
-** amount (1 << x) for each corresponding enumerant.
-*/
-
-#ifndef spirv_H
-#define spirv_H
-
-typedef unsigned int SpvId;
-
-#define SPV_VERSION 0x10200
-#define SPV_REVISION 3
-
-static const unsigned int SpvMagicNumber = 0x07230203;
-static const unsigned int SpvVersion = 0x00010200;
-static const unsigned int SpvRevision = 3;
-static const unsigned int SpvOpCodeMask = 0xffff;
-static const unsigned int SpvWordCountShift = 16;
-
-typedef enum SpvSourceLanguage_
-{
- SpvSourceLanguageUnknown = 0,
- SpvSourceLanguageESSL = 1,
- SpvSourceLanguageGLSL = 2,
- SpvSourceLanguageOpenCL_C = 3,
- SpvSourceLanguageOpenCL_CPP = 4,
- SpvSourceLanguageHLSL = 5,
- SpvSourceLanguageMax = 0x7fffffff,
-} SpvSourceLanguage;
-
-typedef enum SpvExecutionModel_
-{
- SpvExecutionModelVertex = 0,
- SpvExecutionModelTessellationControl = 1,
- SpvExecutionModelTessellationEvaluation = 2,
- SpvExecutionModelGeometry = 3,
- SpvExecutionModelFragment = 4,
- SpvExecutionModelGLCompute = 5,
- SpvExecutionModelKernel = 6,
- SpvExecutionModelMax = 0x7fffffff,
-} SpvExecutionModel;
-
-typedef enum SpvAddressingModel_
-{
- SpvAddressingModelLogical = 0,
- SpvAddressingModelPhysical32 = 1,
- SpvAddressingModelPhysical64 = 2,
- SpvAddressingModelMax = 0x7fffffff,
-} SpvAddressingModel;
-
-typedef enum SpvMemoryModel_
-{
- SpvMemoryModelSimple = 0,
- SpvMemoryModelGLSL450 = 1,
- SpvMemoryModelOpenCL = 2,
- SpvMemoryModelMax = 0x7fffffff,
-} SpvMemoryModel;
-
-typedef enum SpvExecutionMode_
-{
- SpvExecutionModeInvocations = 0,
- SpvExecutionModeSpacingEqual = 1,
- SpvExecutionModeSpacingFractionalEven = 2,
- SpvExecutionModeSpacingFractionalOdd = 3,
- SpvExecutionModeVertexOrderCw = 4,
- SpvExecutionModeVertexOrderCcw = 5,
- SpvExecutionModePixelCenterInteger = 6,
- SpvExecutionModeOriginUpperLeft = 7,
- SpvExecutionModeOriginLowerLeft = 8,
- SpvExecutionModeEarlyFragmentTests = 9,
- SpvExecutionModePointMode = 10,
- SpvExecutionModeXfb = 11,
- SpvExecutionModeDepthReplacing = 12,
- SpvExecutionModeDepthGreater = 14,
- SpvExecutionModeDepthLess = 15,
- SpvExecutionModeDepthUnchanged = 16,
- SpvExecutionModeLocalSize = 17,
- SpvExecutionModeLocalSizeHint = 18,
- SpvExecutionModeInputPoints = 19,
- SpvExecutionModeInputLines = 20,
- SpvExecutionModeInputLinesAdjacency = 21,
- SpvExecutionModeTriangles = 22,
- SpvExecutionModeInputTrianglesAdjacency = 23,
- SpvExecutionModeQuads = 24,
- SpvExecutionModeIsolines = 25,
- SpvExecutionModeOutputVertices = 26,
- SpvExecutionModeOutputPoints = 27,
- SpvExecutionModeOutputLineStrip = 28,
- SpvExecutionModeOutputTriangleStrip = 29,
- SpvExecutionModeVecTypeHint = 30,
- SpvExecutionModeContractionOff = 31,
- SpvExecutionModeInitializer = 33,
- SpvExecutionModeFinalizer = 34,
- SpvExecutionModeSubgroupSize = 35,
- SpvExecutionModeSubgroupsPerWorkgroup = 36,
- SpvExecutionModeSubgroupsPerWorkgroupId = 37,
- SpvExecutionModeLocalSizeId = 38,
- SpvExecutionModeLocalSizeHintId = 39,
- SpvExecutionModePostDepthCoverage = 4446,
- SpvExecutionModeStencilRefReplacingEXT = 5027,
- SpvExecutionModeMax = 0x7fffffff,
-} SpvExecutionMode;
-
-typedef enum SpvStorageClass_
-{
- SpvStorageClassUniformConstant = 0,
- SpvStorageClassInput = 1,
- SpvStorageClassUniform = 2,
- SpvStorageClassOutput = 3,
- SpvStorageClassWorkgroup = 4,
- SpvStorageClassCrossWorkgroup = 5,
- SpvStorageClassPrivate = 6,
- SpvStorageClassFunction = 7,
- SpvStorageClassGeneric = 8,
- SpvStorageClassPushConstant = 9,
- SpvStorageClassAtomicCounter = 10,
- SpvStorageClassImage = 11,
- SpvStorageClassStorageBuffer = 12,
- SpvStorageClassMax = 0x7fffffff,
-} SpvStorageClass;
-
-typedef enum SpvDim_
-{
- SpvDim1D = 0,
- SpvDim2D = 1,
- SpvDim3D = 2,
- SpvDimCube = 3,
- SpvDimRect = 4,
- SpvDimBuffer = 5,
- SpvDimSubpassData = 6,
- SpvDimMax = 0x7fffffff,
-} SpvDim;
-
-typedef enum SpvSamplerAddressingMode_
-{
- SpvSamplerAddressingModeNone = 0,
- SpvSamplerAddressingModeClampToEdge = 1,
- SpvSamplerAddressingModeClamp = 2,
- SpvSamplerAddressingModeRepeat = 3,
- SpvSamplerAddressingModeRepeatMirrored = 4,
- SpvSamplerAddressingModeMax = 0x7fffffff,
-} SpvSamplerAddressingMode;
-
-typedef enum SpvSamplerFilterMode_
-{
- SpvSamplerFilterModeNearest = 0,
- SpvSamplerFilterModeLinear = 1,
- SpvSamplerFilterModeMax = 0x7fffffff,
-} SpvSamplerFilterMode;
-
-typedef enum SpvImageFormat_
-{
- SpvImageFormatUnknown = 0,
- SpvImageFormatRgba32f = 1,
- SpvImageFormatRgba16f = 2,
- SpvImageFormatR32f = 3,
- SpvImageFormatRgba8 = 4,
- SpvImageFormatRgba8Snorm = 5,
- SpvImageFormatRg32f = 6,
- SpvImageFormatRg16f = 7,
- SpvImageFormatR11fG11fB10f = 8,
- SpvImageFormatR16f = 9,
- SpvImageFormatRgba16 = 10,
- SpvImageFormatRgb10A2 = 11,
- SpvImageFormatRg16 = 12,
- SpvImageFormatRg8 = 13,
- SpvImageFormatR16 = 14,
- SpvImageFormatR8 = 15,
- SpvImageFormatRgba16Snorm = 16,
- SpvImageFormatRg16Snorm = 17,
- SpvImageFormatRg8Snorm = 18,
- SpvImageFormatR16Snorm = 19,
- SpvImageFormatR8Snorm = 20,
- SpvImageFormatRgba32i = 21,
- SpvImageFormatRgba16i = 22,
- SpvImageFormatRgba8i = 23,
- SpvImageFormatR32i = 24,
- SpvImageFormatRg32i = 25,
- SpvImageFormatRg16i = 26,
- SpvImageFormatRg8i = 27,
- SpvImageFormatR16i = 28,
- SpvImageFormatR8i = 29,
- SpvImageFormatRgba32ui = 30,
- SpvImageFormatRgba16ui = 31,
- SpvImageFormatRgba8ui = 32,
- SpvImageFormatR32ui = 33,
- SpvImageFormatRgb10a2ui = 34,
- SpvImageFormatRg32ui = 35,
- SpvImageFormatRg16ui = 36,
- SpvImageFormatRg8ui = 37,
- SpvImageFormatR16ui = 38,
- SpvImageFormatR8ui = 39,
- SpvImageFormatMax = 0x7fffffff,
-} SpvImageFormat;
-
-typedef enum SpvImageChannelOrder_
-{
- SpvImageChannelOrderR = 0,
- SpvImageChannelOrderA = 1,
- SpvImageChannelOrderRG = 2,
- SpvImageChannelOrderRA = 3,
- SpvImageChannelOrderRGB = 4,
- SpvImageChannelOrderRGBA = 5,
- SpvImageChannelOrderBGRA = 6,
- SpvImageChannelOrderARGB = 7,
- SpvImageChannelOrderIntensity = 8,
- SpvImageChannelOrderLuminance = 9,
- SpvImageChannelOrderRx = 10,
- SpvImageChannelOrderRGx = 11,
- SpvImageChannelOrderRGBx = 12,
- SpvImageChannelOrderDepth = 13,
- SpvImageChannelOrderDepthStencil = 14,
- SpvImageChannelOrdersRGB = 15,
- SpvImageChannelOrdersRGBx = 16,
- SpvImageChannelOrdersRGBA = 17,
- SpvImageChannelOrdersBGRA = 18,
- SpvImageChannelOrderABGR = 19,
- SpvImageChannelOrderMax = 0x7fffffff,
-} SpvImageChannelOrder;
-
-typedef enum SpvImageChannelDataType_
-{
- SpvImageChannelDataTypeSnormInt8 = 0,
- SpvImageChannelDataTypeSnormInt16 = 1,
- SpvImageChannelDataTypeUnormInt8 = 2,
- SpvImageChannelDataTypeUnormInt16 = 3,
- SpvImageChannelDataTypeUnormShort565 = 4,
- SpvImageChannelDataTypeUnormShort555 = 5,
- SpvImageChannelDataTypeUnormInt101010 = 6,
- SpvImageChannelDataTypeSignedInt8 = 7,
- SpvImageChannelDataTypeSignedInt16 = 8,
- SpvImageChannelDataTypeSignedInt32 = 9,
- SpvImageChannelDataTypeUnsignedInt8 = 10,
- SpvImageChannelDataTypeUnsignedInt16 = 11,
- SpvImageChannelDataTypeUnsignedInt32 = 12,
- SpvImageChannelDataTypeHalfFloat = 13,
- SpvImageChannelDataTypeFloat = 14,
- SpvImageChannelDataTypeUnormInt24 = 15,
- SpvImageChannelDataTypeUnormInt101010_2 = 16,
- SpvImageChannelDataTypeMax = 0x7fffffff,
-} SpvImageChannelDataType;
-
-typedef enum SpvImageOperandsShift_
-{
- SpvImageOperandsBiasShift = 0,
- SpvImageOperandsLodShift = 1,
- SpvImageOperandsGradShift = 2,
- SpvImageOperandsConstOffsetShift = 3,
- SpvImageOperandsOffsetShift = 4,
- SpvImageOperandsConstOffsetsShift = 5,
- SpvImageOperandsSampleShift = 6,
- SpvImageOperandsMinLodShift = 7,
- SpvImageOperandsMax = 0x7fffffff,
-} SpvImageOperandsShift;
-
-typedef enum SpvImageOperandsMask_
-{
- SpvImageOperandsMaskNone = 0,
- SpvImageOperandsBiasMask = 0x00000001,
- SpvImageOperandsLodMask = 0x00000002,
- SpvImageOperandsGradMask = 0x00000004,
- SpvImageOperandsConstOffsetMask = 0x00000008,
- SpvImageOperandsOffsetMask = 0x00000010,
- SpvImageOperandsConstOffsetsMask = 0x00000020,
- SpvImageOperandsSampleMask = 0x00000040,
- SpvImageOperandsMinLodMask = 0x00000080,
-} SpvImageOperandsMask;
-
-typedef enum SpvFPFastMathModeShift_
-{
- SpvFPFastMathModeNotNaNShift = 0,
- SpvFPFastMathModeNotInfShift = 1,
- SpvFPFastMathModeNSZShift = 2,
- SpvFPFastMathModeAllowRecipShift = 3,
- SpvFPFastMathModeFastShift = 4,
- SpvFPFastMathModeMax = 0x7fffffff,
-} SpvFPFastMathModeShift;
-
-typedef enum SpvFPFastMathModeMask_
-{
- SpvFPFastMathModeMaskNone = 0,
- SpvFPFastMathModeNotNaNMask = 0x00000001,
- SpvFPFastMathModeNotInfMask = 0x00000002,
- SpvFPFastMathModeNSZMask = 0x00000004,
- SpvFPFastMathModeAllowRecipMask = 0x00000008,
- SpvFPFastMathModeFastMask = 0x00000010,
-} SpvFPFastMathModeMask;
-
-typedef enum SpvFPRoundingMode_
-{
- SpvFPRoundingModeRTE = 0,
- SpvFPRoundingModeRTZ = 1,
- SpvFPRoundingModeRTP = 2,
- SpvFPRoundingModeRTN = 3,
- SpvFPRoundingModeMax = 0x7fffffff,
-} SpvFPRoundingMode;
-
-typedef enum SpvLinkageType_
-{
- SpvLinkageTypeExport = 0,
- SpvLinkageTypeImport = 1,
- SpvLinkageTypeMax = 0x7fffffff,
-} SpvLinkageType;
-
-typedef enum SpvAccessQualifier_
-{
- SpvAccessQualifierReadOnly = 0,
- SpvAccessQualifierWriteOnly = 1,
- SpvAccessQualifierReadWrite = 2,
- SpvAccessQualifierMax = 0x7fffffff,
-} SpvAccessQualifier;
-
-typedef enum SpvFunctionParameterAttribute_
-{
- SpvFunctionParameterAttributeZext = 0,
- SpvFunctionParameterAttributeSext = 1,
- SpvFunctionParameterAttributeByVal = 2,
- SpvFunctionParameterAttributeSret = 3,
- SpvFunctionParameterAttributeNoAlias = 4,
- SpvFunctionParameterAttributeNoCapture = 5,
- SpvFunctionParameterAttributeNoWrite = 6,
- SpvFunctionParameterAttributeNoReadWrite = 7,
- SpvFunctionParameterAttributeMax = 0x7fffffff,
-} SpvFunctionParameterAttribute;
-
-typedef enum SpvDecoration_
-{
- SpvDecorationRelaxedPrecision = 0,
- SpvDecorationSpecId = 1,
- SpvDecorationBlock = 2,
- SpvDecorationBufferBlock = 3,
- SpvDecorationRowMajor = 4,
- SpvDecorationColMajor = 5,
- SpvDecorationArrayStride = 6,
- SpvDecorationMatrixStride = 7,
- SpvDecorationGLSLShared = 8,
- SpvDecorationGLSLPacked = 9,
- SpvDecorationCPacked = 10,
- SpvDecorationBuiltIn = 11,
- SpvDecorationNoPerspective = 13,
- SpvDecorationFlat = 14,
- SpvDecorationPatch = 15,
- SpvDecorationCentroid = 16,
- SpvDecorationSample = 17,
- SpvDecorationInvariant = 18,
- SpvDecorationRestrict = 19,
- SpvDecorationAliased = 20,
- SpvDecorationVolatile = 21,
- SpvDecorationConstant = 22,
- SpvDecorationCoherent = 23,
- SpvDecorationNonWritable = 24,
- SpvDecorationNonReadable = 25,
- SpvDecorationUniform = 26,
- SpvDecorationSaturatedConversion = 28,
- SpvDecorationStream = 29,
- SpvDecorationLocation = 30,
- SpvDecorationComponent = 31,
- SpvDecorationIndex = 32,
- SpvDecorationBinding = 33,
- SpvDecorationDescriptorSet = 34,
- SpvDecorationOffset = 35,
- SpvDecorationXfbBuffer = 36,
- SpvDecorationXfbStride = 37,
- SpvDecorationFuncParamAttr = 38,
- SpvDecorationFPRoundingMode = 39,
- SpvDecorationFPFastMathMode = 40,
- SpvDecorationLinkageAttributes = 41,
- SpvDecorationNoContraction = 42,
- SpvDecorationInputAttachmentIndex = 43,
- SpvDecorationAlignment = 44,
- SpvDecorationMaxByteOffset = 45,
- SpvDecorationAlignmentId = 46,
- SpvDecorationMaxByteOffsetId = 47,
- SpvDecorationExplicitInterpAMD = 4999,
- SpvDecorationOverrideCoverageNV = 5248,
- SpvDecorationPassthroughNV = 5250,
- SpvDecorationViewportRelativeNV = 5252,
- SpvDecorationSecondaryViewportRelativeNV = 5256,
- SpvDecorationMax = 0x7fffffff,
-} SpvDecoration;
-
-typedef enum SpvBuiltIn_
-{
- SpvBuiltInPosition = 0,
- SpvBuiltInPointSize = 1,
- SpvBuiltInClipDistance = 3,
- SpvBuiltInCullDistance = 4,
- SpvBuiltInVertexId = 5,
- SpvBuiltInInstanceId = 6,
- SpvBuiltInPrimitiveId = 7,
- SpvBuiltInInvocationId = 8,
- SpvBuiltInLayer = 9,
- SpvBuiltInViewportIndex = 10,
- SpvBuiltInTessLevelOuter = 11,
- SpvBuiltInTessLevelInner = 12,
- SpvBuiltInTessCoord = 13,
- SpvBuiltInPatchVertices = 14,
- SpvBuiltInFragCoord = 15,
- SpvBuiltInPointCoord = 16,
- SpvBuiltInFrontFacing = 17,
- SpvBuiltInSampleId = 18,
- SpvBuiltInSamplePosition = 19,
- SpvBuiltInSampleMask = 20,
- SpvBuiltInFragDepth = 22,
- SpvBuiltInHelperInvocation = 23,
- SpvBuiltInNumWorkgroups = 24,
- SpvBuiltInWorkgroupSize = 25,
- SpvBuiltInWorkgroupId = 26,
- SpvBuiltInLocalInvocationId = 27,
- SpvBuiltInGlobalInvocationId = 28,
- SpvBuiltInLocalInvocationIndex = 29,
- SpvBuiltInWorkDim = 30,
- SpvBuiltInGlobalSize = 31,
- SpvBuiltInEnqueuedWorkgroupSize = 32,
- SpvBuiltInGlobalOffset = 33,
- SpvBuiltInGlobalLinearId = 34,
- SpvBuiltInSubgroupSize = 36,
- SpvBuiltInSubgroupMaxSize = 37,
- SpvBuiltInNumSubgroups = 38,
- SpvBuiltInNumEnqueuedSubgroups = 39,
- SpvBuiltInSubgroupId = 40,
- SpvBuiltInSubgroupLocalInvocationId = 41,
- SpvBuiltInVertexIndex = 42,
- SpvBuiltInInstanceIndex = 43,
- SpvBuiltInSubgroupEqMaskKHR = 4416,
- SpvBuiltInSubgroupGeMaskKHR = 4417,
- SpvBuiltInSubgroupGtMaskKHR = 4418,
- SpvBuiltInSubgroupLeMaskKHR = 4419,
- SpvBuiltInSubgroupLtMaskKHR = 4420,
- SpvBuiltInBaseVertex = 4424,
- SpvBuiltInBaseInstance = 4425,
- SpvBuiltInDrawIndex = 4426,
- SpvBuiltInDeviceIndex = 4438,
- SpvBuiltInViewIndex = 4440,
- SpvBuiltInBaryCoordNoPerspAMD = 4992,
- SpvBuiltInBaryCoordNoPerspCentroidAMD = 4993,
- SpvBuiltInBaryCoordNoPerspSampleAMD = 4994,
- SpvBuiltInBaryCoordSmoothAMD = 4995,
- SpvBuiltInBaryCoordSmoothCentroidAMD = 4996,
- SpvBuiltInBaryCoordSmoothSampleAMD = 4997,
- SpvBuiltInBaryCoordPullModelAMD = 4998,
- SpvBuiltInFragStencilRefEXT = 5014,
- SpvBuiltInViewportMaskNV = 5253,
- SpvBuiltInSecondaryPositionNV = 5257,
- SpvBuiltInSecondaryViewportMaskNV = 5258,
- SpvBuiltInPositionPerViewNV = 5261,
- SpvBuiltInViewportMaskPerViewNV = 5262,
- SpvBuiltInFullyCoveredEXT = 5264,
- SpvBuiltInMax = 0x7fffffff,
-} SpvBuiltIn;
-
-typedef enum SpvSelectionControlShift_
-{
- SpvSelectionControlFlattenShift = 0,
- SpvSelectionControlDontFlattenShift = 1,
- SpvSelectionControlMax = 0x7fffffff,
-} SpvSelectionControlShift;
-
-typedef enum SpvSelectionControlMask_
-{
- SpvSelectionControlMaskNone = 0,
- SpvSelectionControlFlattenMask = 0x00000001,
- SpvSelectionControlDontFlattenMask = 0x00000002,
-} SpvSelectionControlMask;
-
-typedef enum SpvLoopControlShift_
-{
- SpvLoopControlUnrollShift = 0,
- SpvLoopControlDontUnrollShift = 1,
- SpvLoopControlDependencyInfiniteShift = 2,
- SpvLoopControlDependencyLengthShift = 3,
- SpvLoopControlMax = 0x7fffffff,
-} SpvLoopControlShift;
-
-typedef enum SpvLoopControlMask_
-{
- SpvLoopControlMaskNone = 0,
- SpvLoopControlUnrollMask = 0x00000001,
- SpvLoopControlDontUnrollMask = 0x00000002,
- SpvLoopControlDependencyInfiniteMask = 0x00000004,
- SpvLoopControlDependencyLengthMask = 0x00000008,
-} SpvLoopControlMask;
-
-typedef enum SpvFunctionControlShift_
-{
- SpvFunctionControlInlineShift = 0,
- SpvFunctionControlDontInlineShift = 1,
- SpvFunctionControlPureShift = 2,
- SpvFunctionControlConstShift = 3,
- SpvFunctionControlMax = 0x7fffffff,
-} SpvFunctionControlShift;
-
-typedef enum SpvFunctionControlMask_
-{
- SpvFunctionControlMaskNone = 0,
- SpvFunctionControlInlineMask = 0x00000001,
- SpvFunctionControlDontInlineMask = 0x00000002,
- SpvFunctionControlPureMask = 0x00000004,
- SpvFunctionControlConstMask = 0x00000008,
-} SpvFunctionControlMask;
-
-typedef enum SpvMemorySemanticsShift_
-{
- SpvMemorySemanticsAcquireShift = 1,
- SpvMemorySemanticsReleaseShift = 2,
- SpvMemorySemanticsAcquireReleaseShift = 3,
- SpvMemorySemanticsSequentiallyConsistentShift = 4,
- SpvMemorySemanticsUniformMemoryShift = 6,
- SpvMemorySemanticsSubgroupMemoryShift = 7,
- SpvMemorySemanticsWorkgroupMemoryShift = 8,
- SpvMemorySemanticsCrossWorkgroupMemoryShift = 9,
- SpvMemorySemanticsAtomicCounterMemoryShift = 10,
- SpvMemorySemanticsImageMemoryShift = 11,
- SpvMemorySemanticsMax = 0x7fffffff,
-} SpvMemorySemanticsShift;
-
-typedef enum SpvMemorySemanticsMask_
-{
- SpvMemorySemanticsMaskNone = 0,
- SpvMemorySemanticsAcquireMask = 0x00000002,
- SpvMemorySemanticsReleaseMask = 0x00000004,
- SpvMemorySemanticsAcquireReleaseMask = 0x00000008,
- SpvMemorySemanticsSequentiallyConsistentMask = 0x00000010,
- SpvMemorySemanticsUniformMemoryMask = 0x00000040,
- SpvMemorySemanticsSubgroupMemoryMask = 0x00000080,
- SpvMemorySemanticsWorkgroupMemoryMask = 0x00000100,
- SpvMemorySemanticsCrossWorkgroupMemoryMask = 0x00000200,
- SpvMemorySemanticsAtomicCounterMemoryMask = 0x00000400,
- SpvMemorySemanticsImageMemoryMask = 0x00000800,
-} SpvMemorySemanticsMask;
-
-typedef enum SpvMemoryAccessShift_
-{
- SpvMemoryAccessVolatileShift = 0,
- SpvMemoryAccessAlignedShift = 1,
- SpvMemoryAccessNontemporalShift = 2,
- SpvMemoryAccessMax = 0x7fffffff,
-} SpvMemoryAccessShift;
-
-typedef enum SpvMemoryAccessMask_
-{
- SpvMemoryAccessMaskNone = 0,
- SpvMemoryAccessVolatileMask = 0x00000001,
- SpvMemoryAccessAlignedMask = 0x00000002,
- SpvMemoryAccessNontemporalMask = 0x00000004,
-} SpvMemoryAccessMask;
-
-typedef enum SpvScope_
-{
- SpvScopeCrossDevice = 0,
- SpvScopeDevice = 1,
- SpvScopeWorkgroup = 2,
- SpvScopeSubgroup = 3,
- SpvScopeInvocation = 4,
- SpvScopeMax = 0x7fffffff,
-} SpvScope;
-
-typedef enum SpvGroupOperation_
-{
- SpvGroupOperationReduce = 0,
- SpvGroupOperationInclusiveScan = 1,
- SpvGroupOperationExclusiveScan = 2,
- SpvGroupOperationMax = 0x7fffffff,
-} SpvGroupOperation;
-
-typedef enum SpvKernelEnqueueFlags_
-{
- SpvKernelEnqueueFlagsNoWait = 0,
- SpvKernelEnqueueFlagsWaitKernel = 1,
- SpvKernelEnqueueFlagsWaitWorkGroup = 2,
- SpvKernelEnqueueFlagsMax = 0x7fffffff,
-} SpvKernelEnqueueFlags;
-
-typedef enum SpvKernelProfilingInfoShift_
-{
- SpvKernelProfilingInfoCmdExecTimeShift = 0,
- SpvKernelProfilingInfoMax = 0x7fffffff,
-} SpvKernelProfilingInfoShift;
-
-typedef enum SpvKernelProfilingInfoMask_
-{
- SpvKernelProfilingInfoMaskNone = 0,
- SpvKernelProfilingInfoCmdExecTimeMask = 0x00000001,
-} SpvKernelProfilingInfoMask;
-
-typedef enum SpvCapability_
-{
- SpvCapabilityMatrix = 0,
- SpvCapabilityShader = 1,
- SpvCapabilityGeometry = 2,
- SpvCapabilityTessellation = 3,
- SpvCapabilityAddresses = 4,
- SpvCapabilityLinkage = 5,
- SpvCapabilityKernel = 6,
- SpvCapabilityVector16 = 7,
- SpvCapabilityFloat16Buffer = 8,
- SpvCapabilityFloat16 = 9,
- SpvCapabilityFloat64 = 10,
- SpvCapabilityInt64 = 11,
- SpvCapabilityInt64Atomics = 12,
- SpvCapabilityImageBasic = 13,
- SpvCapabilityImageReadWrite = 14,
- SpvCapabilityImageMipmap = 15,
- SpvCapabilityPipes = 17,
- SpvCapabilityGroups = 18,
- SpvCapabilityDeviceEnqueue = 19,
- SpvCapabilityLiteralSampler = 20,
- SpvCapabilityAtomicStorage = 21,
- SpvCapabilityInt16 = 22,
- SpvCapabilityTessellationPointSize = 23,
- SpvCapabilityGeometryPointSize = 24,
- SpvCapabilityImageGatherExtended = 25,
- SpvCapabilityStorageImageMultisample = 27,
- SpvCapabilityUniformBufferArrayDynamicIndexing = 28,
- SpvCapabilitySampledImageArrayDynamicIndexing = 29,
- SpvCapabilityStorageBufferArrayDynamicIndexing = 30,
- SpvCapabilityStorageImageArrayDynamicIndexing = 31,
- SpvCapabilityClipDistance = 32,
- SpvCapabilityCullDistance = 33,
- SpvCapabilityImageCubeArray = 34,
- SpvCapabilitySampleRateShading = 35,
- SpvCapabilityImageRect = 36,
- SpvCapabilitySampledRect = 37,
- SpvCapabilityGenericPointer = 38,
- SpvCapabilityInt8 = 39,
- SpvCapabilityInputAttachment = 40,
- SpvCapabilitySparseResidency = 41,
- SpvCapabilityMinLod = 42,
- SpvCapabilitySampled1D = 43,
- SpvCapabilityImage1D = 44,
- SpvCapabilitySampledCubeArray = 45,
- SpvCapabilitySampledBuffer = 46,
- SpvCapabilityImageBuffer = 47,
- SpvCapabilityImageMSArray = 48,
- SpvCapabilityStorageImageExtendedFormats = 49,
- SpvCapabilityImageQuery = 50,
- SpvCapabilityDerivativeControl = 51,
- SpvCapabilityInterpolationFunction = 52,
- SpvCapabilityTransformFeedback = 53,
- SpvCapabilityGeometryStreams = 54,
- SpvCapabilityStorageImageReadWithoutFormat = 55,
- SpvCapabilityStorageImageWriteWithoutFormat = 56,
- SpvCapabilityMultiViewport = 57,
- SpvCapabilitySubgroupDispatch = 58,
- SpvCapabilityNamedBarrier = 59,
- SpvCapabilityPipeStorage = 60,
- SpvCapabilitySubgroupBallotKHR = 4423,
- SpvCapabilityDrawParameters = 4427,
- SpvCapabilitySubgroupVoteKHR = 4431,
- SpvCapabilityStorageBuffer16BitAccess = 4433,
- SpvCapabilityStorageUniformBufferBlock16 = 4433,
- SpvCapabilityStorageUniform16 = 4434,
- SpvCapabilityUniformAndStorageBuffer16BitAccess = 4434,
- SpvCapabilityStoragePushConstant16 = 4435,
- SpvCapabilityStorageInputOutput16 = 4436,
- SpvCapabilityDeviceGroup = 4437,
- SpvCapabilityMultiView = 4439,
- SpvCapabilityVariablePointersStorageBuffer = 4441,
- SpvCapabilityVariablePointers = 4442,
- SpvCapabilityAtomicStorageOps = 4445,
- SpvCapabilitySampleMaskPostDepthCoverage = 4447,
- SpvCapabilityImageGatherBiasLodAMD = 5009,
- SpvCapabilityFragmentMaskAMD = 5010,
- SpvCapabilityStencilExportEXT = 5013,
- SpvCapabilityImageReadWriteLodAMD = 5015,
- SpvCapabilitySampleMaskOverrideCoverageNV = 5249,
- SpvCapabilityGeometryShaderPassthroughNV = 5251,
- SpvCapabilityShaderViewportIndexLayerEXT = 5254,
- SpvCapabilityShaderViewportIndexLayerNV = 5254,
- SpvCapabilityShaderViewportMaskNV = 5255,
- SpvCapabilityShaderStereoViewNV = 5259,
- SpvCapabilityPerViewAttributesNV = 5260,
- SpvCapabilityFragmentFullyCoveredEXT = 5265,
- SpvCapabilitySubgroupShuffleINTEL = 5568,
- SpvCapabilitySubgroupBufferBlockIOINTEL = 5569,
- SpvCapabilitySubgroupImageBlockIOINTEL = 5570,
- SpvCapabilityMax = 0x7fffffff,
-} SpvCapability;
-
-typedef enum SpvOp_
-{
- SpvOpNop = 0,
- SpvOpUndef = 1,
- SpvOpSourceContinued = 2,
- SpvOpSource = 3,
- SpvOpSourceExtension = 4,
- SpvOpName = 5,
- SpvOpMemberName = 6,
- SpvOpString = 7,
- SpvOpLine = 8,
- SpvOpExtension = 10,
- SpvOpExtInstImport = 11,
- SpvOpExtInst = 12,
- SpvOpMemoryModel = 14,
- SpvOpEntryPoint = 15,
- SpvOpExecutionMode = 16,
- SpvOpCapability = 17,
- SpvOpTypeVoid = 19,
- SpvOpTypeBool = 20,
- SpvOpTypeInt = 21,
- SpvOpTypeFloat = 22,
- SpvOpTypeVector = 23,
- SpvOpTypeMatrix = 24,
- SpvOpTypeImage = 25,
- SpvOpTypeSampler = 26,
- SpvOpTypeSampledImage = 27,
- SpvOpTypeArray = 28,
- SpvOpTypeRuntimeArray = 29,
- SpvOpTypeStruct = 30,
- SpvOpTypeOpaque = 31,
- SpvOpTypePointer = 32,
- SpvOpTypeFunction = 33,
- SpvOpTypeEvent = 34,
- SpvOpTypeDeviceEvent = 35,
- SpvOpTypeReserveId = 36,
- SpvOpTypeQueue = 37,
- SpvOpTypePipe = 38,
- SpvOpTypeForwardPointer = 39,
- SpvOpConstantTrue = 41,
- SpvOpConstantFalse = 42,
- SpvOpConstant = 43,
- SpvOpConstantComposite = 44,
- SpvOpConstantSampler = 45,
- SpvOpConstantNull = 46,
- SpvOpSpecConstantTrue = 48,
- SpvOpSpecConstantFalse = 49,
- SpvOpSpecConstant = 50,
- SpvOpSpecConstantComposite = 51,
- SpvOpSpecConstantOp = 52,
- SpvOpFunction = 54,
- SpvOpFunctionParameter = 55,
- SpvOpFunctionEnd = 56,
- SpvOpFunctionCall = 57,
- SpvOpVariable = 59,
- SpvOpImageTexelPointer = 60,
- SpvOpLoad = 61,
- SpvOpStore = 62,
- SpvOpCopyMemory = 63,
- SpvOpCopyMemorySized = 64,
- SpvOpAccessChain = 65,
- SpvOpInBoundsAccessChain = 66,
- SpvOpPtrAccessChain = 67,
- SpvOpArrayLength = 68,
- SpvOpGenericPtrMemSemantics = 69,
- SpvOpInBoundsPtrAccessChain = 70,
- SpvOpDecorate = 71,
- SpvOpMemberDecorate = 72,
- SpvOpDecorationGroup = 73,
- SpvOpGroupDecorate = 74,
- SpvOpGroupMemberDecorate = 75,
- SpvOpVectorExtractDynamic = 77,
- SpvOpVectorInsertDynamic = 78,
- SpvOpVectorShuffle = 79,
- SpvOpCompositeConstruct = 80,
- SpvOpCompositeExtract = 81,
- SpvOpCompositeInsert = 82,
- SpvOpCopyObject = 83,
- SpvOpTranspose = 84,
- SpvOpSampledImage = 86,
- SpvOpImageSampleImplicitLod = 87,
- SpvOpImageSampleExplicitLod = 88,
- SpvOpImageSampleDrefImplicitLod = 89,
- SpvOpImageSampleDrefExplicitLod = 90,
- SpvOpImageSampleProjImplicitLod = 91,
- SpvOpImageSampleProjExplicitLod = 92,
- SpvOpImageSampleProjDrefImplicitLod = 93,
- SpvOpImageSampleProjDrefExplicitLod = 94,
- SpvOpImageFetch = 95,
- SpvOpImageGather = 96,
- SpvOpImageDrefGather = 97,
- SpvOpImageRead = 98,
- SpvOpImageWrite = 99,
- SpvOpImage = 100,
- SpvOpImageQueryFormat = 101,
- SpvOpImageQueryOrder = 102,
- SpvOpImageQuerySizeLod = 103,
- SpvOpImageQuerySize = 104,
- SpvOpImageQueryLod = 105,
- SpvOpImageQueryLevels = 106,
- SpvOpImageQuerySamples = 107,
- SpvOpConvertFToU = 109,
- SpvOpConvertFToS = 110,
- SpvOpConvertSToF = 111,
- SpvOpConvertUToF = 112,
- SpvOpUConvert = 113,
- SpvOpSConvert = 114,
- SpvOpFConvert = 115,
- SpvOpQuantizeToF16 = 116,
- SpvOpConvertPtrToU = 117,
- SpvOpSatConvertSToU = 118,
- SpvOpSatConvertUToS = 119,
- SpvOpConvertUToPtr = 120,
- SpvOpPtrCastToGeneric = 121,
- SpvOpGenericCastToPtr = 122,
- SpvOpGenericCastToPtrExplicit = 123,
- SpvOpBitcast = 124,
- SpvOpSNegate = 126,
- SpvOpFNegate = 127,
- SpvOpIAdd = 128,
- SpvOpFAdd = 129,
- SpvOpISub = 130,
- SpvOpFSub = 131,
- SpvOpIMul = 132,
- SpvOpFMul = 133,
- SpvOpUDiv = 134,
- SpvOpSDiv = 135,
- SpvOpFDiv = 136,
- SpvOpUMod = 137,
- SpvOpSRem = 138,
- SpvOpSMod = 139,
- SpvOpFRem = 140,
- SpvOpFMod = 141,
- SpvOpVectorTimesScalar = 142,
- SpvOpMatrixTimesScalar = 143,
- SpvOpVectorTimesMatrix = 144,
- SpvOpMatrixTimesVector = 145,
- SpvOpMatrixTimesMatrix = 146,
- SpvOpOuterProduct = 147,
- SpvOpDot = 148,
- SpvOpIAddCarry = 149,
- SpvOpISubBorrow = 150,
- SpvOpUMulExtended = 151,
- SpvOpSMulExtended = 152,
- SpvOpAny = 154,
- SpvOpAll = 155,
- SpvOpIsNan = 156,
- SpvOpIsInf = 157,
- SpvOpIsFinite = 158,
- SpvOpIsNormal = 159,
- SpvOpSignBitSet = 160,
- SpvOpLessOrGreater = 161,
- SpvOpOrdered = 162,
- SpvOpUnordered = 163,
- SpvOpLogicalEqual = 164,
- SpvOpLogicalNotEqual = 165,
- SpvOpLogicalOr = 166,
- SpvOpLogicalAnd = 167,
- SpvOpLogicalNot = 168,
- SpvOpSelect = 169,
- SpvOpIEqual = 170,
- SpvOpINotEqual = 171,
- SpvOpUGreaterThan = 172,
- SpvOpSGreaterThan = 173,
- SpvOpUGreaterThanEqual = 174,
- SpvOpSGreaterThanEqual = 175,
- SpvOpULessThan = 176,
- SpvOpSLessThan = 177,
- SpvOpULessThanEqual = 178,
- SpvOpSLessThanEqual = 179,
- SpvOpFOrdEqual = 180,
- SpvOpFUnordEqual = 181,
- SpvOpFOrdNotEqual = 182,
- SpvOpFUnordNotEqual = 183,
- SpvOpFOrdLessThan = 184,
- SpvOpFUnordLessThan = 185,
- SpvOpFOrdGreaterThan = 186,
- SpvOpFUnordGreaterThan = 187,
- SpvOpFOrdLessThanEqual = 188,
- SpvOpFUnordLessThanEqual = 189,
- SpvOpFOrdGreaterThanEqual = 190,
- SpvOpFUnordGreaterThanEqual = 191,
- SpvOpShiftRightLogical = 194,
- SpvOpShiftRightArithmetic = 195,
- SpvOpShiftLeftLogical = 196,
- SpvOpBitwiseOr = 197,
- SpvOpBitwiseXor = 198,
- SpvOpBitwiseAnd = 199,
- SpvOpNot = 200,
- SpvOpBitFieldInsert = 201,
- SpvOpBitFieldSExtract = 202,
- SpvOpBitFieldUExtract = 203,
- SpvOpBitReverse = 204,
- SpvOpBitCount = 205,
- SpvOpDPdx = 207,
- SpvOpDPdy = 208,
- SpvOpFwidth = 209,
- SpvOpDPdxFine = 210,
- SpvOpDPdyFine = 211,
- SpvOpFwidthFine = 212,
- SpvOpDPdxCoarse = 213,
- SpvOpDPdyCoarse = 214,
- SpvOpFwidthCoarse = 215,
- SpvOpEmitVertex = 218,
- SpvOpEndPrimitive = 219,
- SpvOpEmitStreamVertex = 220,
- SpvOpEndStreamPrimitive = 221,
- SpvOpControlBarrier = 224,
- SpvOpMemoryBarrier = 225,
- SpvOpAtomicLoad = 227,
- SpvOpAtomicStore = 228,
- SpvOpAtomicExchange = 229,
- SpvOpAtomicCompareExchange = 230,
- SpvOpAtomicCompareExchangeWeak = 231,
- SpvOpAtomicIIncrement = 232,
- SpvOpAtomicIDecrement = 233,
- SpvOpAtomicIAdd = 234,
- SpvOpAtomicISub = 235,
- SpvOpAtomicSMin = 236,
- SpvOpAtomicUMin = 237,
- SpvOpAtomicSMax = 238,
- SpvOpAtomicUMax = 239,
- SpvOpAtomicAnd = 240,
- SpvOpAtomicOr = 241,
- SpvOpAtomicXor = 242,
- SpvOpPhi = 245,
- SpvOpLoopMerge = 246,
- SpvOpSelectionMerge = 247,
- SpvOpLabel = 248,
- SpvOpBranch = 249,
- SpvOpBranchConditional = 250,
- SpvOpSwitch = 251,
- SpvOpKill = 252,
- SpvOpReturn = 253,
- SpvOpReturnValue = 254,
- SpvOpUnreachable = 255,
- SpvOpLifetimeStart = 256,
- SpvOpLifetimeStop = 257,
- SpvOpGroupAsyncCopy = 259,
- SpvOpGroupWaitEvents = 260,
- SpvOpGroupAll = 261,
- SpvOpGroupAny = 262,
- SpvOpGroupBroadcast = 263,
- SpvOpGroupIAdd = 264,
- SpvOpGroupFAdd = 265,
- SpvOpGroupFMin = 266,
- SpvOpGroupUMin = 267,
- SpvOpGroupSMin = 268,
- SpvOpGroupFMax = 269,
- SpvOpGroupUMax = 270,
- SpvOpGroupSMax = 271,
- SpvOpReadPipe = 274,
- SpvOpWritePipe = 275,
- SpvOpReservedReadPipe = 276,
- SpvOpReservedWritePipe = 277,
- SpvOpReserveReadPipePackets = 278,
- SpvOpReserveWritePipePackets = 279,
- SpvOpCommitReadPipe = 280,
- SpvOpCommitWritePipe = 281,
- SpvOpIsValidReserveId = 282,
- SpvOpGetNumPipePackets = 283,
- SpvOpGetMaxPipePackets = 284,
- SpvOpGroupReserveReadPipePackets = 285,
- SpvOpGroupReserveWritePipePackets = 286,
- SpvOpGroupCommitReadPipe = 287,
- SpvOpGroupCommitWritePipe = 288,
- SpvOpEnqueueMarker = 291,
- SpvOpEnqueueKernel = 292,
- SpvOpGetKernelNDrangeSubGroupCount = 293,
- SpvOpGetKernelNDrangeMaxSubGroupSize = 294,
- SpvOpGetKernelWorkGroupSize = 295,
- SpvOpGetKernelPreferredWorkGroupSizeMultiple = 296,
- SpvOpRetainEvent = 297,
- SpvOpReleaseEvent = 298,
- SpvOpCreateUserEvent = 299,
- SpvOpIsValidEvent = 300,
- SpvOpSetUserEventStatus = 301,
- SpvOpCaptureEventProfilingInfo = 302,
- SpvOpGetDefaultQueue = 303,
- SpvOpBuildNDRange = 304,
- SpvOpImageSparseSampleImplicitLod = 305,
- SpvOpImageSparseSampleExplicitLod = 306,
- SpvOpImageSparseSampleDrefImplicitLod = 307,
- SpvOpImageSparseSampleDrefExplicitLod = 308,
- SpvOpImageSparseSampleProjImplicitLod = 309,
- SpvOpImageSparseSampleProjExplicitLod = 310,
- SpvOpImageSparseSampleProjDrefImplicitLod = 311,
- SpvOpImageSparseSampleProjDrefExplicitLod = 312,
- SpvOpImageSparseFetch = 313,
- SpvOpImageSparseGather = 314,
- SpvOpImageSparseDrefGather = 315,
- SpvOpImageSparseTexelsResident = 316,
- SpvOpNoLine = 317,
- SpvOpAtomicFlagTestAndSet = 318,
- SpvOpAtomicFlagClear = 319,
- SpvOpImageSparseRead = 320,
- SpvOpSizeOf = 321,
- SpvOpTypePipeStorage = 322,
- SpvOpConstantPipeStorage = 323,
- SpvOpCreatePipeFromPipeStorage = 324,
- SpvOpGetKernelLocalSizeForSubgroupCount = 325,
- SpvOpGetKernelMaxNumSubgroups = 326,
- SpvOpTypeNamedBarrier = 327,
- SpvOpNamedBarrierInitialize = 328,
- SpvOpMemoryNamedBarrier = 329,
- SpvOpModuleProcessed = 330,
- SpvOpExecutionModeId = 331,
- SpvOpDecorateId = 332,
- SpvOpSubgroupBallotKHR = 4421,
- SpvOpSubgroupFirstInvocationKHR = 4422,
- SpvOpSubgroupAllKHR = 4428,
- SpvOpSubgroupAnyKHR = 4429,
- SpvOpSubgroupAllEqualKHR = 4430,
- SpvOpSubgroupReadInvocationKHR = 4432,
- SpvOpGroupIAddNonUniformAMD = 5000,
- SpvOpGroupFAddNonUniformAMD = 5001,
- SpvOpGroupFMinNonUniformAMD = 5002,
- SpvOpGroupUMinNonUniformAMD = 5003,
- SpvOpGroupSMinNonUniformAMD = 5004,
- SpvOpGroupFMaxNonUniformAMD = 5005,
- SpvOpGroupUMaxNonUniformAMD = 5006,
- SpvOpGroupSMaxNonUniformAMD = 5007,
- SpvOpFragmentMaskFetchAMD = 5011,
- SpvOpFragmentFetchAMD = 5012,
- SpvOpSubgroupShuffleINTEL = 5571,
- SpvOpSubgroupShuffleDownINTEL = 5572,
- SpvOpSubgroupShuffleUpINTEL = 5573,
- SpvOpSubgroupShuffleXorINTEL = 5574,
- SpvOpSubgroupBlockReadINTEL = 5575,
- SpvOpSubgroupBlockWriteINTEL = 5576,
- SpvOpSubgroupImageBlockReadINTEL = 5577,
- SpvOpSubgroupImageBlockWriteINTEL = 5578,
- SpvOpMax = 0x7fffffff,
-} SpvOp;
-
-#endif // #ifndef spirv_H
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef DALI_GRAPHICS_VULKAN_SPIRV_SPIRV_OPCODES_H
-#define DALI_GRAPHICS_VULKAN_SPIRV_SPIRV_OPCODES_H
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-namespace SpirV
-{
-struct SPIRVOpCode
-{
- std::string name{ "OpNull" };
- uint32_t code{ static_cast<uint32_t>( -1u ) };
- bool hasResult{ false };
- bool hasResultType{ false };
- bool isType{ false };
- bool isTrivial{ false }; // trivial types do not reference to any other result
-
- /** Defines local data */
- struct LocalData
- {
- uint32_t* start{ nullptr };
- uint32_t count{ 0u };
- uint32_t resultId{ 0u };
- int32_t resultType{ -1 };
- };
-
- LocalData localData{};
-
- bool operator!=( const SPIRVOpCode& opcode ) const
- {
- return opcode.code != code;
- }
-
- bool operator==( const SPIRVOpCode& opcode ) const
- {
- return opcode.code == code;
- }
-
- bool operator==( SpvOp op ) const
- {
- return ( code == static_cast<uint32_t>(op) );
- }
-
- template< class T >
- T GetParameter( uint32_t index ) const
- {
- return static_cast<T>( *( localData.start + index + 1 ));
- }
-
- uint32_t GetParameterU32( uint32_t index ) const
- {
- return GetParameter< uint32_t >( index );
- }
-
- std::string GetParameterAsString( uint32_t index ) const
- {
- return reinterpret_cast<const char*>( localData.start + index + 1 );
- }
-
- template< class T >
- T operator[]( uint32_t index ) const
- {
- return GetParameter< T >( index );
- }
-
- SPIRVOpCode() = default;
-
- ~SPIRVOpCode() = default;
-};
-
-namespace
-{
-
-/**
- * List of all the SPIR-V opcodes
- * OpCodes describing types: 19-39
- */
-static const SPIRVOpCode OP_CODE_ARRAY[] = { { "OpNop", 0, false, false, false },
- { "OpUndef", 1, true, true, false },
- { "OpSourceContinued", 2, false, false, false },
- { "OpSource", 3, false, false, false },
- { "OpSourceExtension", 4, false, false, false },
- { "OpName", 5, false, false, false },
- { "OpMemberName", 6, false, false, false },
- { "OpString", 7, true, false, false },
- { "OpLine", 8, false, false, false },
- { "OpExtension", 10, false, false, false },
- { "OpExtInstImport", 11, true, false, false },
- { "OpExtInst", 12, true, true, false },
- { "OpMemoryModel", 14, false, false, false },
- { "OpEntryPoint", 15, false, false, false },
- { "OpExecutionMode", 16, false, false, false },
- { "OpCapability", 17, false, false, false },
- { "OpTypeVoid", 19, true, false, true, true },
- { "OpTypeBool", 20, true, false, true, true },
- { "OpTypeInt", 21, true, false, true, true },
- { "OpTypeFloat", 22, true, false, true, true },
- { "OpTypeVector", 23, true, false, true },
- { "OpTypeMatrix", 24, true, false, true },
- { "OpTypeImage", 25, true, false, true },
- { "OpTypeSampler", 26, true, false, true },
- { "OpTypeSampledImage", 27, true, false, true },
- { "OpTypeArray", 28, true, false, true },
- { "OpTypeRuntimeArray", 29, true, false, true },
- { "OpTypeStruct", 30, true, false, true },
- { "OpTypeOpaque", 31, true, false, true },
- { "OpTypePointer", 32, true, false, true },
- { "OpTypeFunction", 33, true, false, true },
- { "OpTypeEvent", 34, true, false, true },
- { "OpTypeDeviceEvent", 35, true, false, true },
- { "OpTypeReserveId", 36, true, false, true },
- { "OpTypeQueue", 37, true, false, true },
- { "OpTypePipe", 38, true, false, true },
- { "OpTypeForwardPointer", 39, false, false, true },
- { "OpConstantTrue", 41, true, true, false },
- { "OpConstantFalse", 42, true, true, false },
- { "OpConstant", 43, true, true, false },
- { "OpConstantComposite", 44, true, true, false },
- { "OpConstantSampler", 45, true, true, false },
- { "OpConstantNull", 46, true, true, false },
- { "OpSpecConstantTrue", 48, true, true, false },
- { "OpSpecConstantFalse", 49, true, true, false },
- { "OpSpecConstant", 50, true, true, false },
- { "OpSpecConstantComposite", 51, true, true, false },
- { "OpSpecConstantOp", 52, true, true, false },
- { "OpFunction", 54, true, true, false },
- { "OpFunctionParameter", 55, true, true, false },
- { "OpFunctionEnd", 56, false, false, false },
- { "OpFunctionCall", 57, true, true, false },
- { "OpVariable", 59, true, true, false },
- { "OpImageTexelPointer", 60, true, true, false },
- { "OpLoad", 61, true, true, false },
- { "OpStore", 62, false, false, false },
- { "OpCopyMemory", 63, false, false, false },
- { "OpCopyMemorySized", 64, false, false, false },
- { "OpAccessChain", 65, true, true, false },
- { "OpInBoundsAccessChain", 66, true, true, false },
- { "OpPtrAccessChain", 67, true, true, false },
- { "OpArrayLength", 68, true, true, false },
- { "OpGenericPtrMemSemantics", 69, true, true, false },
- { "OpInBoundsPtrAccessChain", 70, true, true, false },
- { "OpDecorate", 71, false, false, false },
- { "OpMemberDecorate", 72, false, false, false },
- { "OpDecorationGroup", 73, true, false, false },
- { "OpGroupDecorate", 74, false, false, false },
- { "OpGroupMemberDecorate", 75, false, false, false },
- { "OpVectorExtractDynamic", 77, true, true, false },
- { "OpVectorInsertDynamic", 78, true, true, false },
- { "OpVectorShuffle", 79, true, true, false },
- { "OpCompositeConstruct", 80, true, true, false },
- { "OpCompositeExtract", 81, true, true, false },
- { "OpCompositeInsert", 82, true, true, false },
- { "OpCopyObject", 83, true, true, false },
- { "OpTranspose", 84, true, true, false },
- { "OpSampledImage", 86, true, true, false },
- { "OpImageSampleImplicitLod", 87, true, true, false },
- { "OpImageSampleExplicitLod", 88, true, true, false },
- { "OpImageSampleDrefImplicitLod", 89, true, true, false },
- { "OpImageSampleDrefExplicitLod", 90, true, true, false },
- { "OpImageSampleProjImplicitLod", 91, true, true, false },
- { "OpImageSampleProjExplicitLod", 92, true, true, false },
- { "OpImageSampleProjDrefImplicitLod", 93, true, true, false },
- { "OpImageSampleProjDrefExplicitLod", 94, true, true, false },
- { "OpImageFetch", 95, true, true, false },
- { "OpImageGather", 96, true, true, false },
- { "OpImageDrefGather", 97, true, true, false },
- { "OpImageRead", 98, true, true, false },
- { "OpImageWrite", 99, false, false, false },
- { "OpImage", 100, true, true, false },
- { "OpImageQueryFormat", 101, true, true, false },
- { "OpImageQueryOrder", 102, true, true, false },
- { "OpImageQuerySizeLod", 103, true, true, false },
- { "OpImageQuerySize", 104, true, true, false },
- { "OpImageQueryLod", 105, true, true, false },
- { "OpImageQueryLevels", 106, true, true, false },
- { "OpImageQuerySamples", 107, true, true, false },
- { "OpConvertFToU", 109, true, true, false },
- { "OpConvertFToS", 110, true, true, false },
- { "OpConvertSToF", 111, true, true, false },
- { "OpConvertUToF", 112, true, true, false },
- { "OpUConvert", 113, true, true, false },
- { "OpSConvert", 114, true, true, false },
- { "OpFConvert", 115, true, true, false },
- { "OpQuantizeToF16", 116, true, true, false },
- { "OpConvertPtrToU", 117, true, true, false },
- { "OpSatConvertSToU", 118, true, true, false },
- { "OpSatConvertUToS", 119, true, true, false },
- { "OpConvertUToPtr", 120, true, true, false },
- { "OpPtrCastToGeneric", 121, true, true, false },
- { "OpGenericCastToPtr", 122, true, true, false },
- { "OpGenericCastToPtrExplicit", 123, true, true, false },
- { "OpBitcast", 124, true, true, false },
- { "OpSNegate", 126, true, true, false },
- { "OpFNegate", 127, true, true, false },
- { "OpIAdd", 128, true, true, false },
- { "OpFAdd", 129, true, true, false },
- { "OpISub", 130, true, true, false },
- { "OpFSub", 131, true, true, false },
- { "OpIMul", 132, true, true, false },
- { "OpFMul", 133, true, true, false },
- { "OpUDiv", 134, true, true, false },
- { "OpSDiv", 135, true, true, false },
- { "OpFDiv", 136, true, true, false },
- { "OpUMod", 137, true, true, false },
- { "OpSRem", 138, true, true, false },
- { "OpSMod", 139, true, true, false },
- { "OpFRem", 140, true, true, false },
- { "OpFMod", 141, true, true, false },
- { "OpVectorTimesScalar", 142, true, true, false },
- { "OpMatrixTimesScalar", 143, true, true, false },
- { "OpVectorTimesMatrix", 144, true, true, false },
- { "OpMatrixTimesVector", 145, true, true, false },
- { "OpMatrixTimesMatrix", 146, true, true, false },
- { "OpOuterProduct", 147, true, true, false },
- { "OpDot", 148, true, true, false },
- { "OpIAddCarry", 149, true, true, false },
- { "OpISubBorrow", 150, true, true, false },
- { "OpUMulExtended", 151, true, true, false },
- { "OpSMulExtended", 152, true, true, false },
- { "OpAny", 154, true, true, false },
- { "OpAll", 155, true, true, false },
- { "OpIsNan", 156, true, true, false },
- { "OpIsInf", 157, true, true, false },
- { "OpIsFinite", 158, true, true, false },
- { "OpIsNormal", 159, true, true, false },
- { "OpSignBitSet", 160, true, true, false },
- { "OpLessOrGreater", 161, true, true, false },
- { "OpOrdered", 162, true, true, false },
- { "OpUnordered", 163, true, true, false },
- { "OpLogicalEqual", 164, true, true, false },
- { "OpLogicalNotEqual", 165, true, true, false },
- { "OpLogicalOr", 166, true, true, false },
- { "OpLogicalAnd", 167, true, true, false },
- { "OpLogicalNot", 168, true, true, false },
- { "OpSelect", 169, true, true, false },
- { "OpIEqual", 170, true, true, false },
- { "OpINotEqual", 171, true, true, false },
- { "OpUGreaterThan", 172, true, true, false },
- { "OpSGreaterThan", 173, true, true, false },
- { "OpUGreaterThanEqual", 174, true, true, false },
- { "OpSGreaterThanEqual", 175, true, true, false },
- { "OpULessThan", 176, true, true, false },
- { "OpSLessThan", 177, true, true, false },
- { "OpULessThanEqual", 178, true, true, false },
- { "OpSLessThanEqual", 179, true, true, false },
- { "OpFOrdEqual", 180, true, true, false },
- { "OpFUnordEqual", 181, true, true, false },
- { "OpFOrdNotEqual", 182, true, true, false },
- { "OpFUnordNotEqual", 183, true, true, false },
- { "OpFOrdLessThan", 184, true, true, false },
- { "OpFUnordLessThan", 185, true, true, false },
- { "OpFOrdGreaterThan", 186, true, true, false },
- { "OpFUnordGreaterThan", 187, true, true, false },
- { "OpFOrdLessThanEqual", 188, true, true, false },
- { "OpFUnordLessThanEqual", 189, true, true, false },
- { "OpFOrdGreaterThanEqual", 190, true, true, false },
- { "OpFUnordGreaterThanEqual", 191, true, true, false },
- { "OpShiftRightLogical", 194, true, true, false },
- { "OpShiftRightArithmetic", 195, true, true, false },
- { "OpShiftLeftLogical", 196, true, true, false },
- { "OpBitwiseOr", 197, true, true, false },
- { "OpBitwiseXor", 198, true, true, false },
- { "OpBitwiseAnd", 199, true, true, false },
- { "OpNot", 200, true, true, false },
- { "OpBitFieldInsert", 201, true, true, false },
- { "OpBitFieldSExtract", 202, true, true, false },
- { "OpBitFieldUExtract", 203, true, true, false },
- { "OpBitReverse", 204, true, true, false },
- { "OpBitCount", 205, true, true, false },
- { "OpDPdx", 207, true, true, false },
- { "OpDPdy", 208, true, true, false },
- { "OpFwidth", 209, true, true, false },
- { "OpDPdxFine", 210, true, true, false },
- { "OpDPdyFine", 211, true, true, false },
- { "OpFwidthFine", 212, true, true, false },
- { "OpDPdxCoarse", 213, true, true, false },
- { "OpDPdyCoarse", 214, true, true, false },
- { "OpFwidthCoarse", 215, true, true, false },
- { "OpEmitVertex", 218, false, false, false },
- { "OpEndPrimitive", 219, false, false, false },
- { "OpEmitStreamVertex", 220, false, false, false },
- { "OpEndStreamPrimitive", 221, false, false, false },
- { "OpControlBarrier", 224, false, false, false },
- { "OpMemoryBarrier", 225, false, false, false },
- { "OpAtomicLoad", 227, true, true, false },
- { "OpAtomicStore", 228, false, false, false },
- { "OpAtomicExchange", 229, true, true, false },
- { "OpAtomicCompareExchange", 230, true, true, false },
- { "OpAtomicCompareExchangeWeak", 231, true, true, false },
- { "OpAtomicIIncrement", 232, true, true, false },
- { "OpAtomicIDecrement", 233, true, true, false },
- { "OpAtomicIAdd", 234, true, true, false },
- { "OpAtomicISub", 235, true, true, false },
- { "OpAtomicSMin", 236, true, true, false },
- { "OpAtomicUMin", 237, true, true, false },
- { "OpAtomicSMax", 238, true, true, false },
- { "OpAtomicUMax", 239, true, true, false },
- { "OpAtomicAnd", 240, true, true, false },
- { "OpAtomicOr", 241, true, true, false },
- { "OpAtomicXor", 242, true, true, false },
- { "OpPhi", 245, true, true, false },
- { "OpLoopMerge", 246, false, false, false },
- { "OpSelectionMerge", 247, false, false, false },
- { "OpLabel", 248, true, false, false },
- { "OpBranch", 249, false, false, false },
- { "OpBranchConditional", 250, false, false, false },
- { "OpSwitch", 251, false, false, false },
- { "OpKill", 252, false, false, false },
- { "OpReturn", 253, false, false, false },
- { "OpReturnValue", 254, false, false, false },
- { "OpUnreachable", 255, false, false, false },
- { "OpLifetimeStart", 256, false, false, false },
- { "OpLifetimeStop", 257, false, false, false },
- { "OpGroupAsyncCopy", 259, true, true, false },
- { "OpGroupWaitEvents", 260, false, false, false },
- { "OpGroupAll", 261, true, true, false },
- { "OpGroupAny", 262, true, true, false },
- { "OpGroupBroadcast", 263, true, true, false },
- { "OpGroupIAdd", 264, true, true, false },
- { "OpGroupFAdd", 265, true, true, false },
- { "OpGroupFMin", 266, true, true, false },
- { "OpGroupUMin", 267, true, true, false },
- { "OpGroupSMin", 268, true, true, false },
- { "OpGroupFMax", 269, true, true, false },
- { "OpGroupUMax", 270, true, true, false },
- { "OpGroupSMax", 271, true, true, false },
- { "OpReadPipe", 274, true, true, false },
- { "OpWritePipe", 275, true, true, false },
- { "OpReservedReadPipe", 276, true, true, false },
- { "OpReservedWritePipe", 277, true, true, false },
- { "OpReserveReadPipePackets", 278, true, true, false },
- { "OpReserveWritePipePackets", 279, true, true, false },
- { "OpCommitReadPipe", 280, false, false, false },
- { "OpCommitWritePipe", 281, false, false, false },
- { "OpIsValidReserveId", 282, true, true, false },
- { "OpGetNumPipePackets", 283, true, true, false },
- { "OpGetMaxPipePackets", 284, true, true, false },
- { "OpGroupReserveReadPipePackets", 285, true, true, false },
- { "OpGroupReserveWritePipePackets", 286, true, true, false },
- { "OpGroupCommitReadPipe", 287, false, false, false },
- { "OpGroupCommitWritePipe", 288, false, false, false },
- { "OpEnqueueMarker", 291, true, true, false },
- { "OpEnqueueKernel", 292, true, true, false },
- { "OpGetKernelNDrangeSubGroupCount", 293, true, true, false },
- { "OpGetKernelNDrangeMaxSubGroupSize", 294, true, true, false },
- { "OpGetKernelWorkGroupSize", 295, true, true, false },
- { "OpGetKernelPreferredWorkGroupSizeMultiple", 296, true, true, false },
- { "OpRetainEvent", 297, false, false, false },
- { "OpReleaseEvent", 298, false, false, false },
- { "OpCreateUserEvent", 299, true, true, false },
- { "OpIsValidEvent", 300, true, true, false },
- { "OpSetUserEventStatus", 301, false, false, false },
- { "OpCaptureEventProfilingInfo", 302, false, false, false },
- { "OpGetDefaultQueue", 303, true, true, false },
- { "OpBuildNDRange", 304, true, true, false },
- { "OpImageSparseSampleImplicitLod", 305, true, true, false },
- { "OpImageSparseSampleExplicitLod", 306, true, true, false },
- { "OpImageSparseSampleDrefImplicitLod", 307, true, true, false },
- { "OpImageSparseSampleDrefExplicitLod", 308, true, true, false },
- { "OpImageSparseSampleProjImplicitLod", 309, true, true, false },
- { "OpImageSparseSampleProjExplicitLod", 310, true, true, false },
- { "OpImageSparseSampleProjDrefImplicitLod", 311, true, true, false },
- { "OpImageSparseSampleProjDrefExplicitLod", 312, true, true, false },
- { "OpImageSparseFetch", 313, true, true, false },
- { "OpImageSparseGather", 314, true, true, false },
- { "OpImageSparseDrefGather", 315, true, true, false },
- { "OpImageSparseTexelsResident", 316, true, true, false },
- { "OpNoLine", 317, false, false, false },
- { "OpAtomicFlagTestAndSet", 318, true, true, false },
- { "OpAtomicFlagClear", 319, false, false, false },
- { "OpImageSparseRead", 320, true, true, false },
- { "OpSizeOf", 321, true, true, false },
- { "OpTypePipeStorage", 322, true, false, false },
- { "OpConstantPipeStorage", 323, true, true, false },
- { "OpCreatePipeFromPipeStorage", 324, true, true, false },
- { "OpGetKernelLocalSizeForSubgroupCount", 325, true, true, false },
- { "OpGetKernelMaxNumSubgroups", 326, true, true, false },
- { "OpTypeNamedBarrier", 327, true, false, false },
- { "OpNamedBarrierInitialize", 328, true, true, false },
- { "OpMemoryNamedBarrier", 329, false, false, false },
- { "OpModuleProcessed", 330, false, false, false },
- { "OpExecutionModeId", 331, false, false, false },
- { "OpDecorateId", 332, false, false, false },
- { "OpSubgroupBallotKHR", 4421, true, true, false },
- { "OpSubgroupFirstInvocationKHR", 4422, true, true, false },
- { "OpSubgroupReadInvocationKHR", 4432, true, true, false },
- { "OpGroupIAddNonUniformAMD", 5000, true, true, false },
- { "OpGroupFAddNonUniformAMD", 5001, true, true, false },
- { "OpGroupFMinNonUniformAMD", 5002, true, true, false },
- { "OpGroupUMinNonUniformAMD", 5003, true, true, false },
- { "OpGroupSMinNonUniformAMD", 5004, true, true, false },
- { "OpGroupFMaxNonUniformAMD", 5005, true, true, false },
- { "OpGroupUMaxNonUniformAMD", 5006, true, true, false },
- { "OpGroupSMaxNonUniformAMD", 5007, true, true, false } };
-
-static const SPIRVOpCode OP_CODE_NULL{};
-
-const SPIRVOpCode& FindOpCode( uint32_t code )
-{
- for( auto&& opcode : OP_CODE_ARRAY )
- {
- if( opcode.code == code )
- {
- return opcode;
- }
- }
- return OP_CODE_NULL;
-}
-
-} // namespace
-} // namespace SpirV
-} // namespace Vulkan
-} // namespace Graphics
-} // namespace Dali
-
-#endif //DALI_GRAPHICS_VULKAN_SPIRV_SPIRV_OPCODES_H
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics/vulkan/internal/spirv/vulkan-spirv.h>
-#include <dali/graphics/vulkan/internal/spirv/vulkan-spirv-opcode.h>
-#include <dali/graphics/vulkan/internal/vulkan-debug.h>
-
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-namespace SpirV
-{
-SPIRVShader::Impl& SPIRVShader::GetImplementation() const
-{
- return *mImpl;
-}
-
-struct SPIRVShader::Impl
-{
- /**
- * 32bit word needed to identify SPIRV code
- */
- static constexpr uint32_t MAGIC_NUMBER{ 0x07230203u };
-
- /**
- * SPIRV header binary structure
- */
- struct Header
- {
- uint32_t magicNumber;
- uint32_t versionNumber; // 0 | major | minor | 0
- uint32_t generatorMagicNumber;
- uint32_t bound;
- uint32_t reserved;
- };
-
- /**
- * Stores descriptorset bindings and createinfo data used by reflection
- */
- struct DescriptorSetLayoutAndBindingInfo
- {
- std::vector< vk::DescriptorSetLayoutBinding > bindings;
- vk::DescriptorSetLayoutCreateInfo createInfo;
- };
-
- SPIRVOpCode& FindByResultId( uint32_t resultId ) const
- {
- return *( opResults[resultId] );
- }
-
- SPIRVOpCode* FindByResultId( SPIRVOpCode& opcode ) const
- {
- if( !opcode.hasResult )
- {
- return nullptr;
- }
- return opResults[opcode.localData.resultId];
- }
-
- SPIRVOpCode* FindByResultPtrId( uint32_t resultId ) const
- {
- if( resultId < opResults.size() )
- {
- return opResults[resultId];
- }
- return nullptr;
- }
-
- /**
- * Constructor
- * @param pData
- * @param size
- * @param stages
- */
- Impl( void* pData, std::size_t size, vk::ShaderStageFlags stages )
- {
- data.resize( size );
- auto begin = reinterpret_cast<uint32_t*>( pData );
- auto end = begin + size;
- std::copy( begin, end, data.begin() );
- }
-
- /**
- * Constructor
- * @tparam T
- * @param buffer
- * @param stages
- */
- template< typename T >
- explicit Impl( std::vector< T > buffer, vk::ShaderStageFlags stages )
- {
- data.resize( ( buffer.size() * sizeof( buffer[0] ) ) / sizeof( uint32_t ) );
- auto begin = reinterpret_cast<uint32_t*>( &*buffer.begin());
- auto end = reinterpret_cast<uint32_t*>( &*buffer.end());
- std::copy( begin, end, data.begin() );
- }
-
- auto FindDecorationsForId( uint32_t id )
- {
- std::vector< SPIRVOpCode* > retval{};
- for( auto&& op : opCodes )
- {
- if( op.code == SpvOpDecorate && op.GetParameterU32( 0 ) == id )
- {
- retval.push_back( &op );
- }
- }
- return retval;
- }
-
- auto FindMemberDecorationsForId( uint32_t id, uint32_t memberIndex )
- {
- std::vector< SPIRVOpCode* > retval{};
- for( auto&& op : opCodes )
- {
- if( op.code == SpvOpMemberDecorate && op.GetParameterU32( 0 ) == id && op.GetParameterU32( 1 ) == memberIndex )
- {
- retval.push_back( &op );
- }
- }
- return retval;
- }
-
- SPIRVOpCode& GetReferencedOpCode( const SPIRVOpCode& opCode, uint32_t refIndex ) const
- {
- return FindByResultId( opCode.GetParameterU32( refIndex ) );
- }
-
- auto GetDecorationsOpId( const SPIRVOpCode& resultOp )
- {
- std::vector< SPIRVOpCode* > retval;
- if( resultOp.hasResult )
- {
- for( auto&& op : opCodes )
- {
- if( op == SpvOpDecorate && op.GetParameterU32( 0 ) == resultOp.localData.resultId )
- {
- retval.push_back( &op );
- }
- }
- }
- return retval;
- }
-
- bool CheckDecorationForOpId( const SPIRVOpCode& resultOp, SpvDecoration expectedDecoration )
- {
- if( resultOp.hasResult )
- {
- for( auto&& op : opCodes )
- {
- if( op == SpvOpDecorate && op.GetParameterU32( 0 ) == resultOp.localData.resultId &&
- op.GetParameter< SpvDecoration >( 1 ) == expectedDecoration )
- {
- return true;
- }
- }
- }
- return false;
- }
-
- struct SPIRVReflectionData
- {
- SPIRVReflectionData() = default;
-
- SPIRVReflectionData( const SPIRVReflectionData& ) = default;
-
- SPIRVReflectionData& operator=( const SPIRVReflectionData& ) = default;
-
- SPIRVReflectionData( SPIRVReflectionData&& ) = delete;
-
- SPIRVReflectionData& operator=( SPIRVReflectionData&& ) = delete;
-
- std::string name{};
- SPIRVOpCode* op{ nullptr };
- SpvStorageClass storage{ SpvStorageClassMax };
- vk::DescriptorType descriptorType{}; // only valid for uniforms
- std::unordered_map< SpvDecoration, SPIRVOpCode* > decorations{};
- std::vector< SPIRVReflectionData > members{}; // used by structs only
- uint32_t structSize{ 0u };
- };
-
- template< class M, class K >
- bool MapContains( const M& map, const K& key ) const
- {
- return map.find( key ) != map.end();
- }
-
-
- template< class V >
- struct GetResult
- {
- GetResult( bool v, V& value )
- : success( v ), result( &value )
- {
- }
-
- GetResult( bool v )
- : success( v ), result( nullptr )
- {
- }
-
- operator V&()
- {
- return *result;
- }
-
- operator V*()
- {
- return result;
- }
-
- GetResult() : success( false ), result( nullptr )
- {
- }
-
- bool success;
- V* result;
- };
-
- template< class K, class V >
- GetResult< V > GetMapItem( std::unordered_map< K, V >& map, const K& key )
- {
- auto iter = map.find( key );
- if( iter == map.end() )
- {
- return GetResult< V >( false );
- }
-
- return GetResult< V >( true, iter->second );
- }
-
- struct SPIRVTypeInfo
- {
- vk::Format vkFormat;
- uint32_t sizeInBytes;
- uint32_t components;
- uint32_t rows;
- uint32_t componentSizeInBytes;
- };
-
- auto GetTypeInfo( const SPIRVOpCode& typeOpCode ) const
- {
- auto retval = SPIRVTypeInfo{};
-
- const vk::Format VEC[] =
- {
- vk::Format::eUndefined,
- vk::Format::eR32Sfloat,
- vk::Format::eR32G32Sfloat,
- vk::Format::eR32G32B32Sfloat,
- vk::Format::eR32G32B32A32Sfloat,
- };
-
- // note: always assumed:
- // - not normalized
- // - float
- // - signed
- if( typeOpCode == SpvOpTypeMatrix )
- {
- retval.components = typeOpCode.GetParameterU32( 2 );
- retval.rows = retval.components;
- retval.componentSizeInBytes = sizeof( float );
- retval.sizeInBytes = ( retval.components * retval.components ) * retval.componentSizeInBytes;
- retval.vkFormat = VEC[retval.components];
- }
- else if( typeOpCode == SpvOpTypeVector )
- {
- retval.components = typeOpCode.GetParameterU32( 2 );
- retval.rows = 1;
- retval.componentSizeInBytes = sizeof( float );
- retval.sizeInBytes = retval.components * retval.componentSizeInBytes;
- retval.vkFormat = VEC[retval.components];
- }
- else if( typeOpCode == SpvOpTypeFloat )
- {
- retval.components = 1;
- retval.rows = 1;
- retval.componentSizeInBytes = sizeof( float );
- retval.sizeInBytes = sizeof( float );
- retval.vkFormat = vk::Format::eR32Sfloat;
- }
- else if( typeOpCode == SpvOpTypeInt )
- {
- retval.components = 1;
- retval.rows = 1;
- retval.componentSizeInBytes = sizeof( uint32_t );
- retval.sizeInBytes = sizeof( uint32_t );
- retval.vkFormat = vk::Format::eR32Sint;
- }
- else
- {
- retval.components = 0;
- retval.rows = 0;
- retval.componentSizeInBytes = 0;
- retval.sizeInBytes = 0;
- retval.vkFormat = vk::Format::eUndefined;
- }
-
- return retval;
- }
-
-
- auto BuildReflection()
- {
- // collect variables
- using MemberNameArray = std::vector< SPIRVOpCode* >;
- auto vars = std::vector< SPIRVOpCode* >{};
- auto opNames = std::unordered_map< uint32_t, SPIRVOpCode* >{};
-
- // member names, key: struct id, value: ordered vector of OpMemberName ops
- auto opMemberNames = std::unordered_map< uint32_t, MemberNameArray >{};
- for( auto&& op : opCodes )
- {
- if( op == SpvOpVariable )
- {
- vars.push_back( &op );
- }
- else if( op == SpvOpName )
- {
- opNames.emplace( op.GetParameterU32( 0 ), &op );
- }
- else if( op == SpvOpMemberName )
- {
- auto id = op.GetParameterU32( 0 );
- GetResult< MemberNameArray > result{};
- MemberNameArray* memberNames{ nullptr };
- if( !( result = GetMapItem( opMemberNames, id ) ).success )
- {
- opMemberNames.emplace( id, MemberNameArray{} );
- memberNames = &opMemberNames[id];
- }
- else
- {
- memberNames = result.result;
- }
-
- if( memberNames->size() <= op.GetParameterU32( 1 ) )
- {
- memberNames->resize( op.GetParameterU32( 1 ) + 1 );
- }
- ( *memberNames )[op.GetParameterU32( 1 )] = &op;
- }
- }
-
- // find uniforms and inputs
- auto decorationVariables = std::unordered_map< uint32_t, SPIRVReflectionData >{};
- auto uniformVariables = std::vector< SPIRVOpCode* >{};
- auto inputVariables = std::vector< SPIRVOpCode* >{};
- auto outputVariables = std::vector< SPIRVOpCode* >{};
- for( auto&& op : vars )
- {
- auto storage = op->GetParameter< SpvStorageClass >( 2 );
- bool varFound{ false };
- if( storage == SpvStorageClassUniform || storage == SpvStorageClassUniformConstant )
- {
- uniformVariables.emplace_back( op );
- varFound = true;
- }
- else if( storage == SpvStorageClassInput )
- {
- inputVariables.emplace_back( op );
- varFound = true;
- }
- else if( storage == SpvStorageClassOutput )
- {
- outputVariables.emplace_back( op );
- varFound = true;
- }
-
- // find decorations if variable
- if( varFound )
- {
- auto id = op->localData.resultId;
- auto decorations = FindDecorationsForId( id );
- SPIRVReflectionData decorationInfo;
- decorationInfo.op = op;
- decorationInfo.storage = storage;
-
- // update descriptor type if viable
- decorationInfo.descriptorType = FindDescriptorTypeForVariable( *op );
-
- for( auto&& decoration : decorations )
- {
- auto decorationQualifier = decoration->GetParameter< SpvDecoration >( 1 );
- decorationInfo.decorations.emplace( decorationQualifier, decoration );
- DALI_LOG_STREAM( gVulkanFilter, Debug::General, decorationQualifier );
- }
- decorationVariables.emplace( id, decorationInfo );
-
- // store name if element is named
- GetResult< SPIRVOpCode* > name{};
-
- bool foundName = false;
- if( ( name = GetMapItem( opNames, id ) ).success )
- {
-
- // variable may not be named ( global scope of the shader )
- if( !( *name.result )->GetParameterAsString( 1 ).empty() )
- {
- DALI_LOG_STREAM( gVulkanFilter, Debug::General, "Found name" );
- decorationVariables[id].name = ( *name.result )->GetParameterAsString( 1 );
- foundName = true;
- }
- }
-
- // continue if name hasn't been found, this means the variable is an uniform
- // in the global scope
- if( !foundName )
- {
- auto pointerId = op->GetParameterU32( 0 );
- auto pointer = FindByResultId( pointerId );
- auto pointerToType = FindByResultId( pointer.GetParameterU32( 2 ) );
-
- // find name of the structure
- GetResult< SPIRVOpCode* > retval{};
- if( ( retval = GetMapItem( opNames, pointerToType.localData.resultId ) ).success )
- {
- DALI_LOG_STREAM( gVulkanFilter, Debug::General,
- "Found: " << ( *retval.result )->GetParameterAsString( 1 ) );
- decorationVariables[id].name = ( *retval.result )->GetParameterAsString( 1 );
- }
-
- // depending on the type, we may need to extract members, member types as well
- // as other relevant data
- if( pointerToType == SpvOpTypeStruct )
- {
-
- auto memberCount = pointerToType.localData.count - 2;
- DALI_LOG_STREAM( gVulkanFilter, Debug::General,
- "Found struct, look for member names and member decorations: "
- "member count: " << memberCount );
-
- // for each member resolve type and compute size of the structure
- auto memberNames = opMemberNames[pointerToType.localData.resultId];
- for( auto i = 0u; i < memberCount; ++i )
- {
- auto& memberName = memberNames[i];
- SPIRVReflectionData memberOpInfo;
- memberOpInfo.name = memberName->GetParameterAsString( 2 );
- auto memberResultId = pointerToType.GetParameterU32( i + 1 );
- memberOpInfo.op = FindByResultPtrId( memberResultId );
-
- // look for decoration for each member ( needed in order to build data structures )
- auto memberDecorationOps = FindMemberDecorationsForId( pointerToType.localData.resultId, i );
- for( auto&& mop : memberDecorationOps )
- {
- memberOpInfo.decorations.emplace( mop->GetParameter< SpvDecoration >( 2 ), mop );
- }
- decorationVariables[id].members.emplace_back( memberOpInfo );
- DALI_LOG_STREAM( gVulkanFilter, Debug::General, "memberName: " << memberName->GetParameterAsString( 2 ) );
- }
-
- uint32_t structSize = 0u;
-
- // for last member update size of the data structure ( for blocks only )
- if( memberCount )
- {
- if( memberCount > 0 )
- {
- auto& lastMember = decorationVariables[id].members.back();
-
- if( MapContains( lastMember.decorations, SpvDecorationOffset ) )
- {
- structSize = lastMember.decorations[SpvDecorationOffset]->GetParameterU32( 3 );
- }
- auto typeInfo = GetTypeInfo( *lastMember.op );
- structSize += typeInfo.sizeInBytes;
- }
- decorationVariables[id].structSize = structSize;
- }
- DALI_LOG_STREAM( gVulkanFilter, Debug::General, "struct size: " << structSize );
- }
- }
- }
- }
-
- DALI_LOG_STREAM( gVulkanFilter, Debug::General, "Found " << uniformVariables.size() << " variables" );
-
- return decorationVariables;
- }
-
- auto LoadOpCodes( const std::vector< SPIRVWord >& _data )
- {
- auto retval = std::vector< SPIRVOpCode >{};
-
- // test if we have valid SPIRV header
- auto iter = data.begin();
- if( !CheckHeader() )
- {
- DALI_LOG_STREAM( gVulkanFilter, Debug::General, "Not SPIRV!" );
- return retval;
- }
-
- DALI_LOG_STREAM( gVulkanFilter, Debug::General, "SPIR-V detected" );
- std::advance( iter, 5u ); // skip header
-
- while( iter != data.end() )
- {
- auto opword = *iter;
- auto wordCount = ( ( opword >> 16 ) & 0xFFFF );
- auto opCode = ( ( opword ) & 0xFFFF );
-
- auto& op = FindOpCode( opCode );
-
- if( op != OP_CODE_NULL )
- {
- uint32_t resultIndex{ 0 };
- int resultIndexOffset = 1;
- int32_t resultType{ 0u };
-
- // make a copy
- retval.emplace_back( op );
- auto& opcode = retval.back();
- opcode.localData.start = &*iter;
- opcode.localData.count = wordCount;
-
- // update result type and index for non-void opcodes
- if( op.hasResultType )
- {
- resultIndexOffset++;
- }
- if( op.hasResult )
- {
- if( op.hasResultType )
- {
- resultType = static_cast<int32_t>( *( iter + 1 ));
- }
- resultIndex = *( iter + resultIndexOffset );
- opcode.localData.resultId = resultIndex;
- opcode.localData.resultType = resultType;
- }
- }
-
- // next instruction
- std::advance( iter, wordCount );
- }
-
- return retval;
- }
-
- auto CreateOpResults( std::vector< SPIRVOpCode >& _opcodes )
- {
- auto retval = std::vector< SPIRVOpCode* >{};
- for( auto i = 0u; i < _opcodes.size(); ++i )
- {
- const auto& op = _opcodes[i];
- if( op.hasResult )
- {
- if( retval.size() <= op.localData.resultId )
- {
- retval.resize( op.localData.resultId + 1 );
- }
- retval[op.localData.resultId] = &_opcodes[i];
- }
- }
- return retval;
- }
-
- vk::DescriptorType FindDescriptorTypeForVariable( SPIRVOpCode& opVariable )
- {
- vk::DescriptorType descriptorType{};
-
- auto storageClass = opVariable.GetParameter< SpvStorageClass >( 2 );
-
- // we need to detect storage by call into function
- if( storageClass == SpvStorageClassUniformConstant )
- {
- auto& resource = opVariable;
- if( TestStorageImageDescriptor( resource ) )
- {
- descriptorType = vk::DescriptorType::eStorageImage;
- }
- else if( TestSamplerDescriptor( resource ) )
- {
- descriptorType = vk::DescriptorType::eSampler;
- }
- else if( TestSampledImageDescriptor( resource ) )
- {
- descriptorType = vk::DescriptorType::eSampledImage;
- }
- else if( TestCombinedImageSamplerDescriptor( resource ) )
- {
- descriptorType = vk::DescriptorType::eCombinedImageSampler;
- }
- else if( TestUniformTexelBufferDescriptor( resource ) )
- {
- descriptorType = vk::DescriptorType::eUniformTexelBuffer;
- }
- else if( TestStorageTexelBufferDescriptor( resource ) )
- {
- descriptorType = vk::DescriptorType::eStorageTexelBuffer;
- }
- else
- {
- // @todo check the shader, something hasn't been recognized
- descriptorType = vk::DescriptorType{};
- }
-
- if( descriptorType != vk::DescriptorType{} )
- {
- //uniformResources.push_back( &resource );
- }
- }
- else if( storageClass == SpvStorageClassUniform )
- {
- descriptorType = vk::DescriptorType::eUniformBuffer;
- }
- return descriptorType;
- }
-
- auto GenerateVulkanDescriptorSetLayouts()
- {
- // key: descriptor set, value: ds layout create info and binding
- auto vkDescriptorSetLayoutCreateInfos = std::unordered_map< uint32_t, DescriptorSetLayoutAndBindingInfo >{};
-
- for( auto&& symbol : reflectionData )
- {
- auto storage = symbol.second.storage;
- auto& symbolData = symbol.second;
- if( storage == SpvStorageClassUniform || storage == SpvStorageClassUniformConstant )
- {
- auto binding = MapContains( symbolData.decorations, SpvDecorationBinding ) ? symbolData
- .decorations[SpvDecorationBinding]->GetParameterU32( 2 ) : 0u;
- auto descriptorSet = MapContains( symbolData.decorations, SpvDecorationDescriptorSet ) ? symbolData
- .decorations[SpvDecorationDescriptorSet]->GetParameterU32( 2 ) : 0u;
- DALI_LOG_STREAM( gVulkanFilter, Debug::General,
- "found layout: binding: " << binding << " ds: " << descriptorSet << ", type: "
- << U32( symbolData.descriptorType ) );
-
- auto& ds = ( MapContains( vkDescriptorSetLayoutCreateInfos, descriptorSet ) ?
- vkDescriptorSetLayoutCreateInfos[descriptorSet] :
- ( *vkDescriptorSetLayoutCreateInfos.emplace( descriptorSet, DescriptorSetLayoutAndBindingInfo{} )
- .first ).second );
-
-
- ds.bindings.emplace_back( vk::DescriptorSetLayoutBinding{}.setBinding( binding )
- .setDescriptorCount( 1 )
- .setDescriptorType( symbolData.descriptorType )
- .setStageFlags( vk::ShaderStageFlagBits::eVertex |
- vk::ShaderStageFlagBits::eFragment ) );
- }
- }
-
- // sort bindings and complete create info structures
- for( auto&& ds : vkDescriptorSetLayoutCreateInfos )
- {
- std::sort( ds.second.bindings.begin(), ds.second.bindings.end(),
- []( auto& a, auto& b ) { return a.binding < b.binding; } );
- ds.second.createInfo.setBindingCount( U32( ds.second.bindings.size() ) );
- ds.second.createInfo.pBindings = ds.second.bindings.data();
- }
-
- return vkDescriptorSetLayoutCreateInfos;
- }
-
- bool Initialise()
- {
- // load opcodes
- opCodes = std::move( LoadOpCodes( data ) );
-
- // create results lookup array
- opResults = std::move( CreateOpResults( opCodes ) );
-
- // build reflection map
- reflectionData = std::move( BuildReflection() );
-
- // build vulkan descriptor set layout infos
- descriptorSetLayoutCreateInfoMap = std::move( GenerateVulkanDescriptorSetLayouts() );
-
- // generate additional reflection structures
- uint32_t blockIndex = 0u;
- for( auto&& symbol : reflectionData )
- {
- auto& symbolData = symbol.second;
- auto binding = MapContains( symbolData.decorations, SpvDecorationBinding ) ? symbolData
- .decorations[SpvDecorationBinding]->GetParameterU32( 2 ) : 0u;
- auto descriptorSet = MapContains( symbolData.decorations, SpvDecorationDescriptorSet ) ? symbolData
- .decorations[SpvDecorationDescriptorSet]->GetParameterU32( 2 ) : 0u;
-
- if( symbolData.storage == SpvStorageClassUniform )
- {
- auto block = SPIRVUniformBlock{};
- block.name = symbolData.name;
- block.size = symbolData.structSize;
- block.binding = binding;
- block.descriptorSet = descriptorSet;
-
- uint32_t location{ 0u };
- for( auto&& member : symbolData.members )
- {
- auto blockMember = SPIRVUniformBlockMember{};
- blockMember.name = member.name;
- blockMember.location = location++;
- blockMember.offset = MapContains( member.decorations, SpvDecorationOffset ) ? member
- .decorations[SpvDecorationOffset]->GetParameterU32( 3 ) : 0u;
- blockMember.blockIndex = blockIndex;
- block.members.emplace_back( blockMember );
- }
- blockIndex++;
- uniformBlockReflection.emplace_back( block );
-
- }
- else if( symbolData.storage == SpvStorageClassUniformConstant )
- {
- auto opaque = SPIRVUniformOpaque{};
- opaque.name = symbolData.name;
- opaque.binding = binding;
- opaque.descriptorSet = descriptorSet;
- opaque.type = symbolData.descriptorType;
- uniformOpaqueReflection.emplace_back( opaque );
- }
- }
-
- return true;
- }
-
- /**
- * Recognizes descriptor type VkDescriptorTypeStorageImage
- * GLSL:
- * layout (set=m, binding=n, r32f) uniform image2D myStorageImage;
- *
- * SPIR-V:
- * %7 = OpTypeImage %6 2D 0 0 0 2 R32f
- * %8 = OpTypePointer UniformConstant %7
- * %9 = OpVariable %8 UniformConstant
- * @param resource
- * @return
- */
- bool TestStorageImageDescriptor( SPIRVOpCode& opcode )
- {
- auto opPointer = &FindByResultId( opcode.GetParameterU32( 0 ) );
- if( ( opPointer && *opPointer == SpvOpTypePointer ) )
- {
- auto& opTypeImage = GetReferencedOpCode( *opPointer, 2 );
- if( opTypeImage == SpvOpTypeImage && opTypeImage.GetParameterU32( 6 ) == 2 )
- {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Recognizes descriptor type VkDescriptorTypeSampler
- * GLSL:
- layout (set=m, binding=n) uniform sampler mySampler;
- *
- * SPIR-V:
- %3 = OpTypeFunction %2
- %6 = OpTypeSampler
- %7 = OpTypePointer UniformConstant %6
- %8 = OpVariable %7 UniformConstant
-
- * @param resource
- * @return
- */
- bool TestSamplerDescriptor( SPIRVOpCode& opcode )
- {
- auto opPointer = &FindByResultId( opcode.GetParameterU32( 0 ) );
- if( ( opPointer && *opPointer == SpvOpTypePointer ) )
- {
- auto& opTypeSampler = GetReferencedOpCode( *opPointer, 2 );
- if( opTypeSampler == SpvOpTypeSampler )
- {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Recognizes descriptor type VkDescriptorTypeSampledImage
- * GLSL:
- * layout (set=m, binding=n) uniform texture2D mySampledImage;
- * SPIR_V:
- %6 = OpTypeFloat 32
- %7 = OpTypeImage %6 2D 0 0 0 1 Unknown
- %8 = OpTypePointer UniformConstant %7
- %9 = OpVariable %8 UniformConstant
- *
- * @param resource
- * @return
- */
- bool TestSampledImageDescriptor( SPIRVOpCode& opcode )
- {
- auto opPointer = &FindByResultId( opcode.GetParameterU32( 0 ) );
- if( ( opPointer && *opPointer == SpvOpTypePointer ) )
- {
- auto& opTypeImage = GetReferencedOpCode( *opPointer, 2 );
- if( opTypeImage == SpvOpTypeImage && opTypeImage.GetParameterU32( 6 ) == 1 )
- {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Recognizes descriptor type VkDescriptorTypeCombinedImageSampler
- * GLSL:
- * layout (set=m, binding=n) uniform sampler2D myCombinedImageSampler;
- * SPIR-V:
- %7 = OpTypeImage %6 2D 0 0 0 1 Unknown
- %8 = OpTypeSampledImage %7
- %9 = OpTypePointer UniformConstant %8
- %10 = OpVariable %9 UniformConstant
- * @param resource
- * @return
- */
- bool TestCombinedImageSamplerDescriptor( SPIRVOpCode& opcode )
- {
- auto opPointer = &FindByResultId( opcode.GetParameterU32( 0 ) );
- if( ( opPointer && *opPointer == SpvOpTypePointer ) )
- {
- auto& opCode = GetReferencedOpCode( *opPointer, 2 );
- if( opCode == SpvOpTypeSampledImage )
- {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Recognizes descriptor type VkDescriptorTypeUniformTexelBuffer
- * GLSL:
- * layout (set=m, binding=n) uniform samplerBuffer myUniformTexelBuffer;
- * SPIR-V:
- %6 = OpTypeFloat 32
- %7 = OpTypeImage %6 Buffer 0 0 0 1 Unknown
- %8 = OpTypePointer UniformConstant %7
- %9 = OpVariable %8 UniformConstant
- * @param resource
- * @return
- */
- bool TestUniformTexelBufferDescriptor( SPIRVOpCode& opcode )
- {
- auto opPointer = &FindByResultId( opcode.GetParameterU32( 0 ) );
- if( ( opPointer && *opPointer == SpvOpTypePointer ) )
- {
- auto& opCode = GetReferencedOpCode( *opPointer, 2 );
- if( opCode == SpvOpTypeImage && opCode.GetParameter< SpvDim >( 2 ) == SpvDimBuffer &&
- opCode.GetParameterU32( 6 ) == 1 )
- {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Recognizes descriptor type VkDescriptorTypeStorageTexelBuffer
- * GLSL:
- * layout (set=m, binding=n, r32f) uniform imageBuffer myStorageTexelBuffer;
- * SPIR-V:
- %7 = OpTypeImage %6 Buffer 0 0 0 2 R32f
- %8 = OpTypePointer UniformConstant %7
- %9 = OpVariable %8 UniformConstant
- * @param resource
- * @return
- */
- bool TestStorageTexelBufferDescriptor( SPIRVOpCode& opcode )
- {
- auto opPointer = &FindByResultId( opcode.GetParameterU32( 0 ) );
- if( ( opPointer && *opPointer == SpvOpTypePointer ) )
- {
- auto& opCode = GetReferencedOpCode( *opPointer, 2 );
- if( opCode == SpvOpTypeImage && opCode.GetParameter< SpvDim >( 2 ) == SpvDimBuffer &&
- opCode.GetParameterU32( 6 ) == 2 )
- {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Recognizes descriptor type VkDescriptorTypeUniformBuffer
- * GLSL:
- layout (set=m, binding=n) uniform myUniformBuffer
- {
- vec4 myElement[32];
- };
- * SPIR-V:
- %11 = OpTypeStruct %10
- %12 = OpTypePointer Uniform %11
- %13 = OpVariable %12 Uniform
- * @todo pull data out of OpDecorate ( Block )
- * @param resource
- * @return
- */
- bool TestUniformBufferDescriptor( SPIRVOpCode& opcode )
- {
- auto opPointer = &FindByResultId( opcode.GetParameterU32( 0 ) );
- if( ( opPointer && *opPointer == SpvOpTypePointer ) &&
- opPointer->GetParameter< SpvStorageClass >( 1 ) == SpvStorageClassUniform )
- {
- auto& opTypeStruct = GetReferencedOpCode( *opPointer, 2 );
- if( opTypeStruct == SpvOpTypeStruct )
- {
- return CheckDecorationForOpId( opTypeStruct, SpvDecorationBlock );
- }
- }
- return false;
- }
-
- bool TestStorageBufferDescriptor( SPIRVOpCode& opcode )
- {
- auto opPointer = FindByResultId( opcode );
- if( ( opPointer && *opPointer == SpvOpTypePointer ) &&
- opPointer->GetParameter< SpvStorageClass >( 1 ) == SpvStorageClassUniform )
- {
- auto& opTypeStruct = GetReferencedOpCode( *opPointer, 2 );
- if( opTypeStruct == SpvOpTypeStruct )
- {
- return CheckDecorationForOpId( opTypeStruct, SpvDecorationBufferBlock );
- }
- }
- return false;
- }
-
- std::vector< vk::DescriptorSetLayoutCreateInfo > GenerateDescriptorSetLayoutCreateInfo() const
- {
- auto retval = std::vector< vk::DescriptorSetLayoutCreateInfo >{};
- for( auto& layout : descriptorSetLayoutCreateInfoMap )
- {
- retval.emplace_back( layout.second.createInfo );
- }
-
- return retval;
- }
-
- bool GetVertexInputAttributes( std::vector< SPIRVVertexInputAttribute >& out, bool canOverlap = false )
- {
- for( auto&& i : reflectionData )
- {
- if( i.second.storage == SpvStorageClassInput )
- {
- auto attr = SPIRVVertexInputAttribute{};
- attr.name = i.second.name;
- attr.location = MapContains( i.second.decorations, SpvDecorationLocation ) ?
- i.second.decorations[SpvDecorationLocation]->GetParameterU32( 2 ) : 0u;
- attr.format = GetTypeInfo(
- GetReferencedOpCode( GetReferencedOpCode( *i.second.op, 0 ), 2 )
- ).vkFormat;
- out.emplace_back( attr );
- }
- }
-
- return true;
- }
-
- /**
- * Tests if the header is valid for SPIR-V
- * @return
- */
- bool CheckHeader()
- {
- header = *reinterpret_cast<Header*>( data.data());
- return MAGIC_NUMBER == header.magicNumber;
- }
-
-public:
- std::vector< SPIRVOpCode > opCodes; // contains all opcodes
- std::vector< SPIRVOpCode* > opResults; // links to the resulting opcode or nullptr if opcode doesn't return
-
- std::unordered_map< uint32_t, SPIRVReflectionData > reflectionData;
- std::unordered_map< uint32_t, DescriptorSetLayoutAndBindingInfo > descriptorSetLayoutCreateInfoMap;
-
- std::vector< SPIRVWord > data;
-
-
- std::vector< SPIRVUniformBlock > uniformBlockReflection;
- std::vector< SPIRVUniformOpaque > uniformOpaqueReflection;
- Header header;
-
-};
-
-/**************************************************************************************
- * SPIRVShader
- */
-
-SPIRVShader::SPIRVShader() = default;
-
-SPIRVShader::~SPIRVShader() = default;
-
-SPIRVShader::SPIRVShader( SPIRVShader&& shader ) noexcept = default;
-
-SPIRVShader::SPIRVShader( Impl& impl )
-{
- mImpl.reset( &impl );
-}
-
-SPIRVShader::SPIRVShader( std::vector< SPIRVWord > code, vk::ShaderStageFlags stages )
-{
- mImpl = std::make_unique< Impl >( code, stages );
-}
-
-std::vector< vk::DescriptorSetLayoutCreateInfo > SPIRVShader::GenerateDescriptorSetLayoutCreateInfo() const
-{
- return mImpl->GenerateDescriptorSetLayoutCreateInfo();
-}
-
-uint32_t SPIRVShader::GetOpCodeCount() const
-{
- return static_cast<uint32_t>( mImpl->opCodes.size());
-}
-
-const SPIRVOpCode* SPIRVShader::GetOpCodeAt( uint32_t index ) const
-{
- return &mImpl->opCodes[index];
-}
-
-const SPIRVOpCode* SPIRVShader::GetOpCodeForResultId( uint32_t resultId ) const
-{
- return mImpl->opResults[resultId];
-}
-
-SPIRVWord SPIRVShader::GetOpCodeParameterWord( const SPIRVOpCode& opCode, uint32_t index ) const
-{
- return GetOpCodeParameter< SPIRVWord >( opCode, index );
-}
-
-SpvOp SPIRVShader::GetOpCodeType( SPIRVOpCode& opCode )
-{
- return SpvOpMax;
-}
-
-const uint32_t* SPIRVShader::GetOpCodeParameterPtr( const SPIRVOpCode& opCode, uint32_t index ) const
-{
- return ( opCode.localData.start + index + 1 );
-}
-
-void SPIRVShader::GetVertexInputAttributes( std::vector< SPIRVVertexInputAttribute >& out ) const
-{
- mImpl->GetVertexInputAttributes( out );
-}
-
-const std::vector< SPIRVUniformBlock >& SPIRVShader::GetUniformBlocks() const
-{
- return mImpl->uniformBlockReflection;
-}
-
-const std::vector< SPIRVUniformOpaque >& SPIRVShader::GetOpaqueUniforms() const
-{
- return mImpl->uniformOpaqueReflection;
-}
-
-bool SPIRVShader::FindUniformMemberByName( const std::string& uniformName, SPIRVUniformBlockMember& out ) const
-{
- for( auto&& ubo : mImpl->uniformBlockReflection )
- {
- for( auto&& member : ubo.members )
- {
- if( member.name == uniformName )
- {
- out = member;
- return true;
- }
- }
- }
- return false;
-}
-
-/**************************************************************************************
- * SPIRVUtils
- */
-
-/**
- * SPIRVUtils
- * @param data
- * @return
- */
-std::unique_ptr< SPIRVShader > SPIRVUtils::Parse( std::vector< SPIRVWord > data, vk::ShaderStageFlags stages )
-{
- auto shader = std::unique_ptr< SPIRVShader >( new SPIRVShader( data, stages ) );
- if( !shader->GetImplementation().Initialise() )
- {
- return nullptr;
- }
- return shader;
-}
-
-std::unique_ptr< SPIRVShader >
-SPIRVUtils::Parse( const SPIRVWord* data, size_t sizeInBytes, vk::ShaderStageFlags stages )
-{
- std::vector< SPIRVWord > spirvCode{};
- auto wordSize = sizeInBytes / sizeof( SPIRVWord );
- spirvCode.resize( wordSize );
- std::copy( data, data + wordSize, spirvCode.begin() );
- return Parse( spirvCode, stages );
-}
-
-} // namespace SpirV
-
-} // namespace Vulkan
-
-} // namespace Graphics
-
-} // namespace Dali
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef DALI_GRAPHICS_VULKAN_SPIRV_SPIRV_H
-#define DALI_GRAPHICS_VULKAN_SPIRV_SPIRV_H
-
-#include <dali/graphics/vulkan/internal/vulkan-types.h>
-#include <cstdint>
-#include <vector>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-namespace SpirV
-{
-
-// include C header
-
-#include "spirv.h"
-
-using SPIRVWord = uint32_t;
-
-/**
- * Opcode storage, doesn't expose direct interface, must be used within
- * SPIRVShader context
- */
-struct SPIRVOpCode;
-
-struct SPIRVVertexInputAttribute
-{
- uint32_t location;
- std::string name;
- vk::Format format;
-};
-
-/**
- * Describes a member of a buffer/uniform block
- */
-struct SPIRVUniformBlockMember
-{
- std::string name;
- uint32_t offset;
- uint32_t location;
- uint32_t blockIndex;
-};
-
-/**
- * Describes single uniform block
- */
-struct SPIRVUniformBlock
-{
- std::string name;
- uint32_t descriptorSet;
- uint32_t binding;
- uint32_t size;
- std::vector< SPIRVUniformBlockMember > members;
-};
-
-/**
- * Describes non-buffer opaque types
- */
-struct SPIRVUniformOpaque
-{
- std::string name;
- uint32_t descriptorSet;
- uint32_t binding;
- vk::DescriptorType type;
-};
-
-/**
- * Defines SPIRVShader program
- */
-class SPIRVShader
-{
- friend class SPIRVUtils;
-
-public:
-
- SPIRVShader( SPIRVShader&& shader ) noexcept;
-
- SPIRVShader( const SPIRVShader& shader ) = delete;
-
- ~SPIRVShader();
-
- /**
- * Generates descriptor set layout info from the supplied shader
- * @note This function does not create the layout itself!
- * @return create info structure
- */
- std::vector< vk::DescriptorSetLayoutCreateInfo > GenerateDescriptorSetLayoutCreateInfo() const;
-
- /**
- * Retrieves vertex input attributes ( names and locations ) from the shader
- * @return fills the given vector of attributes
- */
- void GetVertexInputAttributes( std::vector< SPIRVVertexInputAttribute >& out ) const;
-
- /**
- * Retrieves all uniform block data
- */
- const std::vector< SPIRVUniformBlock >& GetUniformBlocks() const;
-
- /**
- *
- * @return
- */
- const std::vector< SPIRVUniformOpaque >& GetOpaqueUniforms() const;
-
- /**
- * Looks for uniform by name and retrieves location within
- * uniform buffer
- * @note Uniform member name must be unique, otherwise first found is returned
- * @param uniformName
- * @return
- */
- bool FindUniformMemberByName( const std::string& uniformName, SPIRVUniformBlockMember& out ) const;
-
- /**
- * Returns total number of OpCodes
- * @return
- */
- uint32_t GetOpCodeCount() const;
-
- /**
- * Returns OpCode at specified index
- * @param index
- * @return
- */
- const SPIRVOpCode* GetOpCodeAt( uint32_t index ) const;
-
- /**
- * Returns OpCode associated with specified result id
- * @param resultId
- * @return
- */
- const SPIRVOpCode* GetOpCodeForResultId( uint32_t resultId ) const;
-
- /**
- * SPIRVOpCode API
- */
-
- /**
- * Helper function that allows to convert SPIRVWords into requested type
- * @tparam T
- * @param index
- * @return
- */
- template< class T >
- T GetOpCodeParameter( const SPIRVOpCode& opCode, uint32_t index ) const
- {
- return *reinterpret_cast<const T*>( GetOpCodeParameterPtr( opCode, index ));
- }
-
- /**
- * Returns SPIRV parameter as 32bit SPIRVWord
- * @param index
- * @return
- */
- SPIRVWord GetOpCodeParameterWord( const SPIRVOpCode& opCode, uint32_t index ) const;
-
- /**
- *
- * @param opCode
- * @return
- */
- SpvOp GetOpCodeType( SPIRVOpCode& opCode );
-
-private:
-
- /**
- * Accesses parameter via pointer
- * @param index
- * @return
- */
- const uint32_t* GetOpCodeParameterPtr( const SPIRVOpCode& opCode, uint32_t index ) const;
-
- struct Impl;
- std::unique_ptr< Impl > mImpl;
-
- explicit SPIRVShader( Impl& impl );
-
- SPIRVShader();
-
- /**
- * Constructor that should be called only from SPIRVUtils
- * @param code
- */
- explicit SPIRVShader( std::vector< SPIRVWord > code, vk::ShaderStageFlags stages );
-
-public:
- /**
- * Accessor to the implementation object
- * @return
- */
- Impl& GetImplementation() const;
-};
-
-
-/**
- * Simple set
- */
-class SPIRVUtils
-{
-public:
-
- /**
- * Creates SPIRVShader instance
- * @param data
- * @return
- */
- static std::unique_ptr< SPIRVShader > Parse( std::vector< SPIRVWord > data, vk::ShaderStageFlags stages );
-
- static std::unique_ptr< SPIRVShader > Parse( const SPIRVWord* data, size_t sizeInBytes, vk::ShaderStageFlags stages );
-
-private:
-
- struct Impl;
- std::unique_ptr< Impl > mImpl;
-};
-
-}
-} // namespace Vulkan
-} // namespace Graphics
-} // namespace Dali
-
-#endif // DALI_GRAPHICS_VULKAN_SPIRV_SPIRV_H
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics/vulkan/internal/vulkan-buffer.h>
-#include <dali/graphics/vulkan/vulkan-graphics.h>
-#include <dali/graphics/vulkan/internal/vulkan-debug.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-
-const Buffer& Buffer::ConstRef()
-{
- return *this;
-}
-
-Buffer& Buffer::Ref()
-{
- return *this;
-}
-
-Buffer::Buffer( Graphics& graphics, const vk::BufferCreateInfo& createInfo )
- : VkManaged(),
- mGraphics( &graphics ),
- mDeviceMemory( nullptr ),
- mInfo( createInfo )
-{
-}
-
-vk::BufferUsageFlags Buffer::GetUsage() const
-{
- return mInfo.usage;
-}
-
-Memory* Buffer::GetMemory() const
-{
- return mDeviceMemory.get();
-}
-
-uint32_t Buffer::GetSize() const
-{
- return static_cast<uint32_t>(mInfo.size);
-}
-
-vk::Buffer Buffer::GetVkHandle() const
-{
- return mBuffer;
-}
-
-void Buffer::DestroyNow()
-{
- DestroyVulkanResources( mGraphics->GetDevice(), mBuffer, mDeviceMemory->ReleaseVkObject(), &mGraphics->GetAllocator() );
- mBuffer = nullptr;
- mDeviceMemory = nullptr;
-}
-
-bool Buffer::OnDestroy()
-{
- if( mBuffer )
- {
- auto device = mGraphics->GetDevice();
- auto buffer = mBuffer;
- auto allocator = &mGraphics->GetAllocator();
- auto memory = mDeviceMemory->ReleaseVkObject();
-
- mGraphics->DiscardResource( [ device, buffer, memory, allocator ]() {
- Buffer::DestroyVulkanResources( device, buffer, memory, allocator );
- } );
- }
- return false;
-}
-
-void Buffer::DestroyVulkanResources( vk::Device device, vk::Buffer buffer, vk::DeviceMemory memory, const vk::AllocationCallbacks* allocator )
-{
- DALI_LOG_INFO( gVulkanFilter, Debug::General, "Invoking deleter function: buffer->%p\n",
- static_cast< VkBuffer >(buffer) )
- device.destroyBuffer( buffer, allocator );
-
- device.freeMemory( memory, allocator );
-}
-
-
-}
-
-}
-
-}
+++ /dev/null
-#ifndef DALI_GRAPHICS_VULKAN_BUFFER_H
-#define DALI_GRAPHICS_VULKAN_BUFFER_H
-
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics/vulkan/internal/vulkan-types.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-
-class Memory;
-
-class Buffer : public VkManaged
-{
- friend class Graphics;
-
-public:
-
- const Buffer& ConstRef();
-
- Buffer& Ref();
-
- /**
- * Returns buffer usage flags
- * @return
- */
- vk::BufferUsageFlags GetUsage() const;
-
- /**
- * Returns buffer size in bytes
- * @return
- */
- uint32_t GetSize() const;
-
- /**
- * Returns Vulkan VkBuffer object associated with this buffer
- * @return
- */
- vk::Buffer GetVkHandle() const;
-
- /**
- * Returns handle to the allocated memory
- * @return
- */
- Memory* GetMemory() const;
-
- /**
- * Destroys underlying Vulkan resources on the caller thread.
- *
- * @note Calling this function is unsafe and makes any further use of
- * buffer invalid.
- */
- void DestroyNow();
-
- /**
- *
- * @return
- */
- bool OnDestroy() override;
-
- Buffer( const Buffer& ) = delete;
-
- Buffer& operator=( const Buffer& ) = delete;
-
-private:
-
- /**
- * Creates new VkBuffer with given specification, it doesn't
- * bind the memory.
- * @param graphics
- * @param createInfo
- */
- Buffer( Graphics& graphics, const vk::BufferCreateInfo& createInfo );
-
- /**
- * Destroys used Vulkan resource objects
- * @param device Vulkan device
- * @param buffer Vulkan buffer
- * @param memory Vulkan device memory
- * @param allocator Pointer to the Vulkan allocator callbacks
- */
- static void DestroyVulkanResources( vk::Device device, vk::Buffer buffer, vk::DeviceMemory memory, const vk::AllocationCallbacks* allocator );
-
-private:
- Graphics* mGraphics;
- std::unique_ptr<Memory> mDeviceMemory;
- vk::BufferCreateInfo mInfo;
- vk::Buffer mBuffer;
-};
-
-
-}
-}
-}
-
-#endif //VULKAN_PROJECT_BUFFER_H
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// INTERNAL INCLUDES
-#include <dali/graphics/vulkan/internal/vulkan-types.h>
-#include <dali/graphics/vulkan/internal/vulkan-buffer.h>
-#include <dali/graphics/vulkan/internal/vulkan-command-buffer.h>
-#include <dali/graphics/vulkan/internal/vulkan-command-pool.h>
-#include <dali/graphics/vulkan/vulkan-graphics.h>
-#include <dali/graphics/vulkan/internal/vulkan-swapchain.h>
-#include <dali/graphics/vulkan/internal/vulkan-image.h>
-#include <dali/graphics/vulkan/internal/vulkan-fence.h>
-#include <dali/graphics/vulkan/internal/vulkan-surface.h>
-#include <dali/graphics/vulkan/internal/vulkan-framebuffer.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-/**
- *
- * Class: CommandBuffer
- *
- */
-
-CommandBuffer::CommandBuffer( CommandPool& commandPool,
- uint32_t poolIndex,
- const vk::CommandBufferAllocateInfo& allocateInfo,
- vk::CommandBuffer vulkanHandle )
- : mOwnerCommandPool( &commandPool ),
- mGraphics( &mOwnerCommandPool->GetGraphics() ),
- mPoolAllocationIndex( poolIndex ),
- mAllocateInfo( allocateInfo ),
- mCommandBuffer( vulkanHandle )
-{
-}
-
-CommandBuffer::~CommandBuffer() = default;
-
-/** Begin recording */
-void CommandBuffer::Begin( vk::CommandBufferUsageFlags usageFlags,
- vk::CommandBufferInheritanceInfo* inheritanceInfo )
-{
- assert( !mRecording && "CommandBuffer already is in the recording state" );
- auto info = vk::CommandBufferBeginInfo{};
- info.setPInheritanceInfo( inheritanceInfo );
- info.setFlags( usageFlags );
-
- VkAssert( mCommandBuffer.begin( info ) );
-
- mRecording = true;
-}
-
-/** Finish recording */
-void CommandBuffer::End()
-{
- assert( mRecording && "CommandBuffer is not in the recording state!" );
- VkAssert( mCommandBuffer.end() );
- mRecording = false;
-}
-
-/** Reset command buffer */
-void CommandBuffer::Reset()
-{
- assert( !mRecording && "Can't reset command buffer during recording!" );
- assert( mCommandBuffer && "Invalid command buffer!" );
- mCommandBuffer.reset( vk::CommandBufferResetFlagBits::eReleaseResources );
-}
-
-/** Free command buffer */
-void CommandBuffer::Free()
-{
- assert( mCommandBuffer && "Invalid command buffer!" );
- mGraphics->GetDevice().freeCommandBuffers( mOwnerCommandPool->GetVkHandle(), mCommandBuffer );
-}
-
-vk::CommandBuffer CommandBuffer::GetVkHandle() const
-{
- return mCommandBuffer;
-}
-
-bool CommandBuffer::IsPrimary() const
-{
- return mAllocateInfo.level == vk::CommandBufferLevel::ePrimary;
-}
-
-void CommandBuffer::BindVertexBuffers( uint32_t firstBinding,
- uint32_t bindingCount,
- std::vector< Handle< Buffer>> buffers,
- const vk::DeviceSize* pOffsets )
-{
- // update list of used resources and create an array of VkBuffers
- std::vector< vk::Buffer > vkBuffers;
- vkBuffers.reserve( buffers.size() );
- for( auto&& buffer : buffers )
- {
- vkBuffers.emplace_back( buffer->GetVkHandle() );
- }
-
- mCommandBuffer.bindVertexBuffers( firstBinding, bindingCount, vkBuffers.data(), pOffsets );
-}
-
-void CommandBuffer::BindIndexBuffer( RefCountedBuffer buffer, uint32_t offset, vk::IndexType indexType )
-{
- // validate
- assert( ( buffer->GetUsage() & vk::BufferUsageFlagBits::eIndexBuffer ) &&
- "The buffer used as index buffer has wrong usage flags!" );
-
- mCommandBuffer.bindIndexBuffer( buffer->GetVkHandle(), offset, indexType );
-}
-
-void CommandBuffer::BindVertexBuffer( uint32_t binding,
- const RefCountedBuffer& buffer,
- vk::DeviceSize offset )
-{
- BindVertexBuffers( binding, 1, std::vector< Handle< Buffer>>( { buffer } ), &offset );
-}
-
-void CommandBuffer::BindGraphicsPipeline( const vk::Pipeline& pipeline )
-{
- mCommandBuffer.bindPipeline( vk::PipelineBindPoint::eGraphics, pipeline );
-}
-
-void CommandBuffer::BindDescriptorSets( const std::vector< vk::DescriptorSet >& descriptorSets,
- const vk::PipelineLayout& pipelineLayout,
- uint32_t firstSet,
- uint32_t descriptorSetCount )
-{
- // TODO: support dynamic offsets
- mCommandBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics,
- pipelineLayout,
- firstSet,
- descriptorSetCount,
- descriptorSets.data(),
- 0,
- nullptr );
-}
-
-void CommandBuffer::Draw( uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance )
-{
- mCommandBuffer.draw( vertexCount, instanceCount, firstVertex, firstInstance );
-}
-
-void CommandBuffer::DrawIndexed( uint32_t indexCount,
- uint32_t instanceCount,
- uint32_t firstIndex,
- uint32_t vertexOffset,
- uint32_t firstInstance )
-{
- mCommandBuffer.drawIndexed( indexCount,
- instanceCount,
- firstIndex,
- static_cast<int32_t>( vertexOffset ),
- firstInstance );
-}
-
-void CommandBuffer::BeginRenderPass( FBID framebufferId, uint32_t bufferIndex )
-{
- auto swapchain = mGraphics->GetSwapchainForFBID( 0u );
- auto surface = mGraphics->GetSurface( 0u );
- auto frameBuffer = swapchain->GetCurrentFramebuffer();
- auto renderPass = frameBuffer->GetRenderPass();
- auto clearValues = frameBuffer->GetClearValues();
-
- auto info = vk::RenderPassBeginInfo{};
- info.setFramebuffer( frameBuffer->GetVkHandle() );
- info.setRenderPass( renderPass );
- info.setClearValueCount( U32( clearValues.size() ) );
- info.setPClearValues( clearValues.data() );
- info.setRenderArea( vk::Rect2D( { 0, 0 }, surface->GetCapabilities().currentExtent ) );
-
- mCommandBuffer.beginRenderPass( info, vk::SubpassContents::eInline );
-}
-
-void CommandBuffer::BeginRenderPass( vk::RenderPassBeginInfo renderPassBeginInfo, vk::SubpassContents subpassContents )
-{
- mCommandBuffer.beginRenderPass( renderPassBeginInfo, subpassContents );
-}
-
-void CommandBuffer::EndRenderPass()
-{
- mCommandBuffer.endRenderPass();
-}
-
-void CommandBuffer::ExecuteCommands( const std::vector< Dali::Graphics::Vulkan::Handle< CommandBuffer>>& commandBuffers,
- uint32_t offset, uint32_t count )
-{
- assert( mAllocateInfo.level == vk::CommandBufferLevel::ePrimary
- &&
- "Cannot record command: ExecuteCommands\tReason: The command buffer recording this command is not primary" );
-
- auto vkBuffers = std::vector< vk::CommandBuffer >{};
- vkBuffers.reserve( commandBuffers.size() );
-
- auto iter = commandBuffers.begin();
- std::advance( iter, offset );
-
- for( uint32_t i = 0; i < count; ++i )
- {
- const auto& buf = *iter;
- assert( buf->mAllocateInfo.level == vk::CommandBufferLevel::eSecondary &&
- "Cannot record command: Execute Commands\tReason: A command buffer provided for execution is not secondary" );
-
- vkBuffers.emplace_back( buf->GetVkHandle() );
- ++iter;
- }
-
- mCommandBuffer.executeCommands( vkBuffers );
-}
-
-void
-CommandBuffer::ExecuteCommands( const std::vector< Dali::Graphics::Vulkan::Handle< CommandBuffer>>& commandBuffers )
-{
- ExecuteCommands( commandBuffers, 0, uint32_t( commandBuffers.size() ) );
-}
-
-void CommandBuffer::PipelineBarrier( vk::PipelineStageFlags srcStageMask,
- vk::PipelineStageFlags dstStageMask,
- vk::DependencyFlags dependencyFlags,
- std::vector< vk::MemoryBarrier > memoryBarriers,
- std::vector< vk::BufferMemoryBarrier > bufferBarriers,
- std::vector< vk::ImageMemoryBarrier > imageBarriers )
-{
- mCommandBuffer.pipelineBarrier( srcStageMask,
- dstStageMask,
- dependencyFlags,
- memoryBarriers,
- bufferBarriers,
- imageBarriers );
-}
-
-void CommandBuffer::CopyBufferToImage( RefCountedBuffer srcBuffer,
- RefCountedImage dstImage,
- vk::ImageLayout dstLayout,
- std::vector< vk::BufferImageCopy > regions )
-{
- mCommandBuffer.copyBufferToImage( srcBuffer->GetVkHandle(),
- dstImage->GetVkHandle(),
- dstLayout,
- regions );
-}
-
-void CommandBuffer::CopyImage( RefCountedImage srcImage,
- vk::ImageLayout srcLayout,
- RefCountedImage dstImage,
- vk::ImageLayout dstLayout,
- const std::vector<vk::ImageCopy>& regions )
-{
- mCommandBuffer.copyImage( srcImage->GetVkHandle(), srcLayout, dstImage->GetVkHandle(), dstLayout, regions );
-}
-
-void CommandBuffer::SetScissor( uint32_t firstScissor, uint32_t scissorCount, const vk::Rect2D* pScissors )
-{
- mCommandBuffer.setScissor( firstScissor, scissorCount, pScissors );
-}
-
-void CommandBuffer::SetViewport( uint32_t firstViewport, uint32_t viewportCount, const vk::Viewport* pViewports )
-{
- mCommandBuffer.setViewport( firstViewport, viewportCount, pViewports );
-}
-
-void CommandBuffer::ClearDepthStencilImage( const RefCountedImage& image,
- vk::ImageLayout layout,
- vk::ClearDepthStencilValue depthStencilClearValue,
- std::vector<vk::ImageSubresourceRange> ranges )
-{
- mCommandBuffer.clearDepthStencilImage(
- image->GetVkHandle(),
- layout,
- depthStencilClearValue,
- ranges
- );
-}
-
-void CommandBuffer::ClearDepthStencilImage( const RefCountedImage& image,
- vk::ImageLayout layout,
- vk::ClearDepthStencilValue depthStencilClearValue,
- vk::ImageAspectFlags aspect)
-{
- vk::ImageSubresourceRange range;
- range.setLayerCount( 1 )
- .setBaseArrayLayer( 0 )
- .setAspectMask( aspect )
- .setBaseMipLevel( 0 )
- .setLevelCount( 1 );
-
- mCommandBuffer.clearDepthStencilImage(
- image->GetVkHandle(),
- layout,
- depthStencilClearValue,
- { range }
- );
-}
-
-uint32_t CommandBuffer::GetPoolAllocationIndex() const
-{
- return mPoolAllocationIndex;
-}
-
-bool CommandBuffer::OnDestroy()
-{
- mOwnerCommandPool->ReleaseCommandBuffer( *this );
- return true;
-}
-
-} // namespace Vulkan
-} // namespace Graphics
-} // namespace Dali
+++ /dev/null
-#ifndef DALI_GRAPHICS_VULKAN_COMMAND_BUFFER_H
-#define DALI_GRAPHICS_VULKAN_COMMAND_BUFFER_H
-
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// INTERNAL INCLUDES
-#include <dali/graphics/vulkan/internal/vulkan-types.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-
-class Image;
-
-class Graphics;
-
-class Buffer;
-
-class Pipeline;
-
-class DescriptorSet;
-
-class CommandBuffer : public VkManaged
-{
- friend class CommandPool;
-
- friend struct CommandBufferPool;
-
-public:
-
- CommandBuffer() = delete;
-
- ~CommandBuffer() override;
-
- /** Begin recording */
- void Begin( vk::CommandBufferUsageFlags usageFlags, vk::CommandBufferInheritanceInfo* inheritanceInfo );
-
- /** Finish recording */
- void End();
-
- /** Reset command buffer */
- void Reset();
-
- /** Free command buffer */
- void Free();
-
- /** Returns Vulkan object associated with the buffer */
- vk::CommandBuffer GetVkHandle() const;
-
- /**
- * Tests if the command buffer is primary
- * @return Returns true if the command buffer is primary
- */
- bool IsPrimary() const;
-
- /**
- * Binds an array of vertex buffers
- * @param firstBinding
- * @param bindingCount
- * @param buffers
- * @param pOffsets
- */
- void BindVertexBuffers( uint32_t firstBinding, uint32_t bindingCount,
- std::vector< Dali::Graphics::Vulkan::Handle< Buffer>> buffers,
- const vk::DeviceSize* pOffsets );
-
- /**
- * Binds an index buffer
- * @param buffer
- * @param offset
- * @param indexType
- */
- void BindIndexBuffer( RefCountedBuffer buffer, uint32_t offset, vk::IndexType indexType );
-
- /**
- * Binds single vertex buffer
- * @param binding
- * @param buffer
- * @param offset
- */
- void
- BindVertexBuffer( uint32_t binding, const Dali::Graphics::Vulkan::Handle< Buffer >& buffer, vk::DeviceSize offset );
-
- /**
- * Binds graphics pipeline
- * @param pipeline Vulkan pipeline object
- */
- void BindGraphicsPipeline( const vk::Pipeline& pipeline );
-
- /**
- * Binds descriptor sets to the most recently bound Pipeline
- * @param descriptorSets array of not-managed Vulkan descriptor sets
- * @param pipelineLayout pipeline layout
- * @param firstSet index of the first descriptor set
- * @param descriptorSetCount number of descriptor sets to bind
- */
- void BindDescriptorSets( const std::vector< vk::DescriptorSet >& descriptorSets,
- const vk::PipelineLayout& pipelineLayout,
- uint32_t firstSet,
- uint32_t descriptorSetCount );
-
- /**
- * Issues draw command
- * @param vertexCount
- * @param instanceCount
- * @param firstVertex
- * @param firstInstance
- */
- void Draw( uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance );
-
- /**
- * Issues draw indexed primiteve command
- * @param indexCount
- * @param instanceCount
- * @param firstIndex
- * @param vertexOffset
- * @param firstInstance
- */
- void DrawIndexed( uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, uint32_t vertexOffset,
- uint32_t firstInstance );
-
- /**
- * Begins render pass using VkRenderPass and VkFramebuffer associated with FBID
- * @todo should be replaced with proper implementation and use the framebuffer
- * @param framebufferId
- * @param bufferIndex
- */
- void BeginRenderPass( FBID framebufferId, uint32_t bufferIndex );
-
- /**
- * Allows to issue custom VkRenderPassBeginInfo structure
- * @param renderPassBeginInfo
- * @param subpassContents
- */
- void BeginRenderPass( vk::RenderPassBeginInfo renderPassBeginInfo, vk::SubpassContents subpassContents );
-
- /**
- * Ends current render pass
- */
- void EndRenderPass();
-
- /**
- * Records pipeline barrier
- * @param srcStageMask
- * @param dstStageMask
- * @param dependencyFlags
- * @param memoryBarriers
- * @param bufferBarriers
- * @param imageBarriers
- */
- void PipelineBarrier( vk::PipelineStageFlags srcStageMask,
- vk::PipelineStageFlags dstStageMask,
- vk::DependencyFlags dependencyFlags,
- std::vector< vk::MemoryBarrier > memoryBarriers,
- std::vector< vk::BufferMemoryBarrier > bufferBarriers,
- std::vector< vk::ImageMemoryBarrier > imageBarriers );
-
- /**
- * Executes secondary command buffers within primary command buffer
- * @param commandBuffers
- */
- void ExecuteCommands( const std::vector< Dali::Graphics::Vulkan::Handle< CommandBuffer>>& commandBuffers );
-
- /**
- * Executes secondary command buffers within primary command buffer
- * @param commandBuffers
- */
- void ExecuteCommands( const std::vector< Dali::Graphics::Vulkan::Handle< CommandBuffer>>& commandBuffers, uint32_t offset,
- uint32_t count );
-
- /**
- * Copies buffer into the specified image
- * @param srcBuffer
- * @param dstImage
- * @param dtsLayout
- * @param regions
- */
- void CopyBufferToImage( RefCountedBuffer srcBuffer, RefCountedImage dstImage, vk::ImageLayout dstLayout,
- std::vector< vk::BufferImageCopy > regions );
-
- /**
- * Copies image to image
- * @param srcImage
- * @param srcLayout
- * @param dstImage
- * @param dstLAyout
- * @param regions
- */
- void CopyImage( RefCountedImage srcImage,
- vk::ImageLayout srcLayout,
- RefCountedImage dstImage,
- vk::ImageLayout dstLayout,
- const std::vector<vk::ImageCopy>& regions );
-
- /**
- * Sets scissors when VK_DYNAMIC_STATE_SCISSOR used
- * @param firstScissor
- * @param scissorCount
- * @param pScissors
- */
- void SetScissor( uint32_t firstScissor, uint32_t scissorCount, const vk::Rect2D* pScissors );
-
- /**
- * Sets viewport when VK_DYNAMIC_STATE_VIEWPORT used
- * @param firstViewport
- * @param viewportCount
- * @param pViewports
- */
- void SetViewport( uint32_t firstViewport, uint32_t viewportCount, const vk::Viewport* pViewports );
-
- /**
- * Clears depth/stencil image to specified value
- *
- * @param[in] image input depth/stencil image
- * @param[in] layout current layout
- * @param[in] depthStencilClearValue desired clear value
- * @param[in] ranges subresource ranges to be affected by clear command
- */
- void ClearDepthStencilImage( const RefCountedImage& image,
- vk::ImageLayout layout,
- vk::ClearDepthStencilValue depthStencilClearValue,
- std::vector<vk::ImageSubresourceRange> ranges );
- /**
- * Clears depth/stencil image to specified value
- *
- * @param[in] image input depth/stencil image
- * @param[in] layout current layout
- * @param[in] depthStencilClearValue desired clear value
- * @param[in] aspect Image aspect to be affected by the command
- */
- void ClearDepthStencilImage( const RefCountedImage& image,
- vk::ImageLayout layout,
- vk::ClearDepthStencilValue depthStencilClearValue,
- vk::ImageAspectFlags aspect);
- /**
- * Implements VkManaged::OnDestroy
- * @return
- */
- bool OnDestroy() override;
-
-private:
-
- /**
- * Returns allocation index
- * @return
- */
- uint32_t GetPoolAllocationIndex() const;
-
-private:
-
- // Constructor called by the CommandPool only
- CommandBuffer( CommandPool& commandPool,
- uint32_t poolIndex,
- const vk::CommandBufferAllocateInfo& allocateInfo,
- vk::CommandBuffer vulkanHandle );
-
-private:
-
- CommandPool* mOwnerCommandPool;
- Graphics* mGraphics;
- uint32_t mPoolAllocationIndex;
- vk::CommandBufferAllocateInfo mAllocateInfo{};
-
- vk::CommandBuffer mCommandBuffer{};
-
- bool mRecording{ false };
-};
-
-} // namespace Vulkan
-} // namespace Graphics
-} // namespace Dali
-
-#endif // DALI_GRAPHICS_VULKAN_COMMAND_BUFFER_H
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// INTERNAL INCLUDES
-#include <dali/graphics/vulkan/vulkan-graphics.h>
-#include <dali/graphics/vulkan/internal/vulkan-command-pool.h>
-#include <dali/graphics/vulkan/internal/vulkan-command-buffer.h>
-#include <dali/graphics/vulkan/internal/vulkan-debug.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-
-/**
- *
- * Struct: InternalPool
- */
-CommandPool::InternalPool::Node::Node( uint32_t _nextFreeIndex, CommandBuffer* _commandBuffer )
- : nextFreeIndex( _nextFreeIndex ),
- commandBuffer( _commandBuffer )
-{
-}
-
-CommandPool::InternalPool::InternalPool( CommandPool& owner, Dali::Graphics::Vulkan::Graphics* graphics,
- uint32_t initialCapacity, bool isPrimary )
- : mOwner( owner ),
- mGraphics( graphics ),
- mPoolData{},
- mFirstFree( INVALID_NODE_INDEX ),
- mCapacity( initialCapacity ),
- mAllocationCount( 0u ),
- mIsPrimary( isPrimary )
-{
- // don't allocate anything if initial capacity is 0
- if( initialCapacity )
- {
- Resize( initialCapacity );
- }
-}
-
-CommandPool::InternalPool::~InternalPool()
-{
- // free all buffers here
- for( auto&& cmd : mPoolData )
- {
- delete cmd.commandBuffer;
- }
-}
-
-std::vector< vk::CommandBuffer >
-CommandPool::InternalPool::AllocateVkCommandBuffers( vk::CommandBufferAllocateInfo allocateInfo )
-{
- return VkAssert( mGraphics->GetDevice().allocateCommandBuffers( allocateInfo ) );
-}
-
-void CommandPool::InternalPool::Resize( uint32_t newCapacity )
-{
- if( newCapacity <= mPoolData.size() )
- {
- return;
- }
-
- auto diff = newCapacity - mPoolData.size();
-
- auto allocateInfo = vk::CommandBufferAllocateInfo{}
- .setCommandBufferCount( U32( diff ) )
- .setCommandPool( mOwner.GetVkHandle() )
- .setLevel( mIsPrimary ? vk::CommandBufferLevel::ePrimary : vk::CommandBufferLevel::eSecondary );
- auto newBuffers = AllocateVkCommandBuffers( allocateInfo );
-
- uint32_t i = U32( mPoolData.size() + 1 );
-
- mFirstFree = U32( mPoolData.size() );
- if( !mPoolData.empty() )
- {
- mPoolData.back()
- .nextFreeIndex = U32( mPoolData.size() );
- }
- for( auto&& cmdbuf : newBuffers )
- {
- auto commandBuffer = new CommandBuffer( mOwner, i - 1, allocateInfo, cmdbuf );
- mPoolData.emplace_back( i, commandBuffer );
- ++i;
- }
- mPoolData.back().nextFreeIndex = INVALID_NODE_INDEX;
- mCapacity = U32( mPoolData.size() );
-}
-
-RefCountedCommandBuffer CommandPool::InternalPool::AllocateCommandBuffer( bool reset )
-{
- // resize if no more nodes
- if( mFirstFree == INVALID_NODE_INDEX )
- {
- auto newSize = static_cast<uint32_t>(mPoolData.empty() ? 1 : 2 * mPoolData.size());
- Resize( U32( newSize ) );
- }
-
- auto& node = mPoolData[mFirstFree];
- mFirstFree = node.nextFreeIndex;
-
- if( reset )
- {
- node.commandBuffer->Reset();
- }
-
- ++mAllocationCount;
- return RefCountedCommandBuffer( node.commandBuffer );
-}
-
-void CommandPool::InternalPool::ReleaseCommandBuffer( CommandBuffer& buffer, bool reset )
-{
- auto indexInPool = buffer.GetPoolAllocationIndex();
- mPoolData[indexInPool].nextFreeIndex = mFirstFree;
- mFirstFree = indexInPool;
-
- if( reset )
- {
- buffer.Reset();
- }
- --mAllocationCount;
-}
-
-uint32_t CommandPool::InternalPool::GetCapacity() const
-{
- return mCapacity;
-}
-
-uint32_t CommandPool::InternalPool::GetAllocationCount() const
-{
- return mAllocationCount;
-}
-
-/**
- *
- * Class: CommandPool
- */
-RefCountedCommandPool CommandPool::New( Graphics& graphics, const vk::CommandPoolCreateInfo& createInfo )
-{
- auto retval = Handle< CommandPool >( new CommandPool( graphics, createInfo ) );
-
- if( retval && retval->Initialize() )
- {
- graphics.AddCommandPool( retval );
- }
-
- return retval;
-}
-
-RefCountedCommandPool CommandPool::New( Graphics& graphics )
-{
- return New( graphics, vk::CommandPoolCreateInfo{} );
-}
-
-bool CommandPool::Initialize()
-{
- mCreateInfo.setFlags( vk::CommandPoolCreateFlagBits::eResetCommandBuffer );
- mCommandPool = VkAssert( mGraphics->GetDevice().createCommandPool( mCreateInfo, mGraphics->GetAllocator() ) );
- mInternalPoolPrimary = std::make_unique< InternalPool >( *this, mGraphics, 0, true );
- mInternalPoolSecondary = std::make_unique< InternalPool >( *this, mGraphics, 0, false );
- return true;
-}
-
-CommandPool::CommandPool() = default;
-
-CommandPool::CommandPool( Graphics& graphics, const vk::CommandPoolCreateInfo& createInfo )
- : mGraphics( &graphics ),
- mCreateInfo( createInfo )
-{
-}
-
-CommandPool::~CommandPool() = default;
-
-vk::CommandPool CommandPool::GetVkHandle() const
-{
- return mCommandPool;
-}
-
-Graphics& CommandPool::GetGraphics() const
-{
- return *mGraphics;
-}
-
-RefCountedCommandBuffer CommandPool::NewCommandBuffer( const vk::CommandBufferAllocateInfo& allocateInfo )
-{
- return NewCommandBuffer( allocateInfo.level == vk::CommandBufferLevel::ePrimary );
-}
-
-RefCountedCommandBuffer CommandPool::NewCommandBuffer( bool isPrimary )
-{
- auto& usedPool = isPrimary ? *mInternalPoolPrimary : *mInternalPoolSecondary;
- return usedPool.AllocateCommandBuffer( false );
-}
-
-void CommandPool::Reset( bool releaseResources )
-{
- mGraphics->GetDevice()
- .resetCommandPool( mCommandPool,
- releaseResources ? vk::CommandPoolResetFlagBits::eReleaseResources
- : vk::CommandPoolResetFlags{} );
-}
-
-bool CommandPool::ReleaseCommandBuffer( CommandBuffer& buffer )
-{
- if( buffer.IsPrimary() )
- {
- mInternalPoolPrimary->ReleaseCommandBuffer( buffer );
- }
- else
- {
- mInternalPoolSecondary->ReleaseCommandBuffer( buffer );
- }
- return false;
-}
-
-uint32_t CommandPool::GetCapacity() const
-{
- return mInternalPoolPrimary->GetCapacity() +
- mInternalPoolSecondary->GetCapacity();
-}
-
-uint32_t CommandPool::GetAllocationCount() const
-{
- return mInternalPoolPrimary->GetAllocationCount() +
- mInternalPoolSecondary->GetAllocationCount();
-}
-
-uint32_t CommandPool::GetAllocationCount( vk::CommandBufferLevel level ) const
-{
- return level == vk::CommandBufferLevel::ePrimary ?
- mInternalPoolPrimary->GetAllocationCount() :
- mInternalPoolSecondary->GetAllocationCount();
-}
-
-bool CommandPool::OnDestroy()
-{
- auto device = mGraphics->GetDevice();
- auto commandPool = mCommandPool;
- auto allocator = &mGraphics->GetAllocator();
-
- mGraphics->DiscardResource( [ device, commandPool, allocator ]() {
- DALI_LOG_INFO( gVulkanFilter, Debug::General, "Invoking deleter function: command pool->%p\n",
- static_cast< VkCommandPool >( commandPool ) )
- device.destroyCommandPool( commandPool, allocator );
- } );
-
- return false;
-}
-
-} // namespace Vulkan
-} // namespace Graphics
-} // namespace Dali
-
+++ /dev/null
-#ifndef DALI_GRAPHICS_VULKAN_COMMANDPOOL
-#define DALI_GRAPHICS_VULKAN_COMMANDPOOL
-
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// INTERNAL INCLUDES
-#include <dali/graphics/vulkan/internal/vulkan-types.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-
-class Graphics;
-
-class CommandBuffer;
-
-
-class CommandPool : public VkManaged
-{
-
- friend class Graphics;
-
- //TODO: Move logic to the Graphics class
-public:
-
- ~CommandPool() override;
-
- /**
- *
- * @return
- */
- vk::CommandPool GetVkHandle() const;
-
- /**
- *
- * @return
- */
- Graphics& GetGraphics() const;
-
- /**
- * Resets command pool
- */
- void Reset( bool releaseResources );
-
- /**
- *
- * @param allocateInfo
- * @return
- */
- RefCountedCommandBuffer NewCommandBuffer( const vk::CommandBufferAllocateInfo& allocateInfo );
-
- /**
- *
- * @param isPrimary
- * @return
- */
- RefCountedCommandBuffer NewCommandBuffer( bool isPrimary = true );
-
- /**
- * Releases command buffer
- * @param buffer
- * @return
- */
- bool ReleaseCommandBuffer( CommandBuffer& buffer );
-
- /**
- * Returns current pool capacity ( 0 if nothing allocated )
- * @return
- */
- uint32_t GetCapacity() const;
-
- /**
- * Returns number of allocated command buffers
- * @return
- */
- uint32_t GetAllocationCount() const;
-
- /**
- * Returns number of allocated command buffers by level
- * @param level
- * @return
- */
- uint32_t GetAllocationCount( vk::CommandBufferLevel level ) const;
-
- bool OnDestroy() override; //TODO: Queue deleter for destruction
-
-private: //Private methods
-
- CommandPool();
-
- CommandPool( Graphics& graphics, const vk::CommandPoolCreateInfo& createInfo );
-
- /**
- *
- * @param graphics
- * @param createInfo
- * @return
- */
- static RefCountedCommandPool New( Graphics& graphics, const vk::CommandPoolCreateInfo& createInfo );
-
- /**
- *
- * @param graphics
- * @return
- */
- static RefCountedCommandPool New( Graphics& graphics );
-
- bool Initialize();
-
-private: //Internal structs
- /**
- * CommandBufferPool contains preallocated command buffers that are
- * reusable.
- */
- struct InternalPool
- {
- static constexpr uint32_t INVALID_NODE_INDEX{ 0xffffffffu };
-
- struct Node
- {
- Node( uint32_t _nextFreeIndex, CommandBuffer* _commandBuffer );
-
- uint32_t nextFreeIndex;
- CommandBuffer* commandBuffer;
- };
-
- InternalPool( CommandPool& owner, Graphics* graphics, uint32_t initialCapacity, bool isPrimary );
-
- ~InternalPool();
-
- /**
- * Creates new batch of command buffers
- * @param allocateInfo
- * @return
- */
- std::vector< vk::CommandBuffer > AllocateVkCommandBuffers( vk::CommandBufferAllocateInfo allocateInfo );
-
- /**
- * Resizes command pool to the new capacity. Pool may only grow
- * @param newCapacity
- */
- void Resize( uint32_t newCapacity );
-
- /**
- * Allocates new command buffer
- * @return
- */
- RefCountedCommandBuffer AllocateCommandBuffer( bool reset );
-
- /**
- * Releases command buffer back to the pool
- * @param reset if true, Resets command buffer
- * @param ref
- */
- void ReleaseCommandBuffer( CommandBuffer& buffer, bool reset = false );
-
- uint32_t GetCapacity() const;
-
- uint32_t GetAllocationCount() const;
-
- CommandPool& mOwner;
- Graphics* mGraphics;
- std::vector< Node > mPoolData;
- uint32_t mFirstFree;
- uint32_t mCapacity;
- uint32_t mAllocationCount;
- bool mIsPrimary;
- };
-
-private: // Data members
- Graphics* mGraphics;
- vk::CommandPoolCreateInfo mCreateInfo;
- vk::CommandPool mCommandPool;
-
- // Pools are lazily allocated, depends on the requested command buffers
- std::unique_ptr< InternalPool > mInternalPoolPrimary;
- std::unique_ptr< InternalPool > mInternalPoolSecondary;
-
-};
-
-
-} // namespace Vulkan
-} // namespace Graphics
-} // namespace Dali
-
-#endif // DALI_GRAPHICS_VULKAN_COMMANDPOOL
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <dali/graphics/vulkan/internal/vulkan-debug-allocator.h>
-#include <mutex>
-#include <map>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-
-#define DALI_VULKAN_DEBUG_ALLOCATOR
-#ifdef DALI_VULKAN_DEBUG_ALLOCATOR
-
-struct MemoryAllocationTag
-{
- MemoryAllocationTag( const MemoryAllocationTag& rhs )
- {
- if( strlen(rhs.tagBuffer) )
- {
- strcpy( tagBuffer, rhs.tagBuffer );
- }
- parentPtr = rhs.parentPtr;
- }
-
- MemoryAllocationTag()
- {
- tagBuffer[0] = 0;
- }
-
- explicit MemoryAllocationTag( const char* tagString )
- {
- strcpy( tagBuffer, tagString );
- }
-
- char tagBuffer[256];
- void* parentPtr { nullptr };
-};
-
-namespace
-{
-struct AllocationTracker
-{
- enum class ObjectType
- {
- IMAGE,
- IMAGE_VIEW,
- SAMPLER,
- FENCE,
- BUFFER,
- DEVICE_MEMORY,
- FRAMEBUFFER,
- RENDERPASS,
- UNDEFINED
- };
-
- AllocationTracker()
- {
- totalObjects = 0u;
- totalBytesAllocated = 0u;
- allocationId = 0u;
- }
- struct Allocation
- {
- void* ptr;
- size_t size;
- size_t alignment;
- size_t allocationId;
- bool reallocated;
- uint32_t freed;
- ObjectType objectType;
- VkSystemAllocationScope allocationScope;
- std::unique_ptr<MemoryAllocationTag> allocationTag;
-
- // used by stats
- uint32_t totalSizeWithSuballocations;
- uint32_t totalSuballocationCount;
- };
-
- size_t totalObjects;
- size_t totalBytesAllocated;
- size_t allocationId;
- std::recursive_mutex allocMutex{};
-
- void* valloc( size_t size, size_t align, VkSystemAllocationScope scope, MemoryAllocationTag* debugTag )
- {
- void* retval = malloc( size );
- auto allocation = Allocation();
- allocation.ptr = retval;
- allocation.size = size;
-
- allocation.alignment = align;
- allocation.allocationScope = scope;
- allocation.reallocated = false;
- if( debugTag )
- {
- allocation.allocationTag.reset( new MemoryAllocationTag( *debugTag ) );
- if( !debugTag->parentPtr )
- {
- // set parent allocation pointer
- debugTag->parentPtr = allocation.ptr;
- }
- }
-
- std::lock_guard<std::recursive_mutex> lock( allocMutex );
- totalObjects++;
- totalBytesAllocated += size;
- allocation.allocationId = ++allocationId;
- allocationData[retval] = std::move( allocation );
- return retval;
- }
-
- void* vrealloc( void* original, size_t size, size_t align, VkSystemAllocationScope scope, MemoryAllocationTag* debugTag )
- {
- void* retval = ::realloc( original, size );
- auto allocation = Allocation();
-
- allocation.ptr = retval;
- allocation.size = size;
- allocation.alignment = align;
- allocation.allocationScope = scope;
- allocation.reallocated = true;
- if( debugTag )
- {
- allocation.allocationTag.reset( new MemoryAllocationTag( *debugTag ) );
- if( !debugTag->parentPtr )
- {
- // set parent allocation pointer
- debugTag->parentPtr = allocation.ptr;
- }
- }
-
- std::lock_guard<std::recursive_mutex> lock( allocMutex );
- allocation.allocationId = ++allocationId;
- if( original )
- {
- // find original
- auto it = allocationData.find( original );
- if( it != allocationData.end() )
- {
- totalBytesAllocated -= (*it).second.size;
- totalObjects--;
- if( original != retval )
- {
- allocationData.erase( it );
- }
- }
- }
- totalBytesAllocated += size;
- totalObjects++;
- allocationData[retval] = std::move( allocation );
- return retval;
- }
-
- void vfree( void* ptr )
- {
- if( !ptr )
- {
- return;
- }
- std::lock_guard<std::recursive_mutex> lock( allocMutex );
- auto it = allocationData.find( ptr );
- if( it != allocationData.end() )
- {
- if( it->second.freed )
- {
- printf("[MEMORY] Object id = %d, ptr = %p has been freed %d times!\n",
- int(it->second.allocationId), it->second.ptr, int(it->second.freed+1));
-
- }
- else
- {
- free( (*it).first );
- totalObjects--;
- totalBytesAllocated -= (*it).second.size;
- allocationData.erase( it );
- }
- ++it->second.freed;
- }
- else
- {
- // trying to kill unallocated stuff!!!
- puts("Object not in the register!");
- }
- }
-
- void updateSubAllocations( Allocation& allocation )
- {
- allocation.totalSizeWithSuballocations = uint32_t( allocation.size );
- allocation.totalSuballocationCount = 1u;
-
- // find suballocations
- for( auto& k : allocationData )
- {
- if( k.second.allocationTag && k.second.allocationTag->parentPtr == allocation.ptr )
- {
- allocation.totalSizeWithSuballocations += uint32_t(k.second.size);
- allocation.totalSuballocationCount++;
- }
- }
- }
-
-
- void printStatus()
- {
- std::lock_guard<std::recursive_mutex> lock( allocMutex );
- puts("Memory stats:");
- printf("Total allocations: %d\n", int( totalObjects ));
- printf("Total allocations: %d\n", int( totalBytesAllocated ));
-
- size_t objectCount { 0u };
- size_t objectMemory { 0u };
- size_t commandCount { 0u };
- size_t commandMemory { 0u };
-
- size_t imageCount { 0u };
- size_t imageViewCount { 0u };
- size_t bufferCount { 0u };
- size_t samplerCount { 0u };
- size_t framebufferCount { 0u };
- size_t renderPassCount { 0u };
- size_t deviceMemoryCount { 0u };
- size_t shaderModuleCount { 0u };
- size_t pipelineCount { 0u };
- size_t pipelineLayoutCount { 0u };
- size_t dsLayoutCount { 0u };
- size_t dsPoolCount { 0u };
- size_t dsPoolMemory { 0u };
-
- std::vector<Allocation*> descriptorPoolAllocations;
- for( auto& item : allocationData )
- {
- if( !item.second.freed )
- {
- if( item.second.allocationScope == VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
- && item.second.allocationTag
- && !item.second.allocationTag->parentPtr )
- {
- objectCount++;
- objectMemory += item.second.size;
-
- std::string str( item.second.allocationTag->tagBuffer );
- if(str == "IMAGEVIEW")
- imageViewCount++;
- else if(str == "IMAGE")
- imageCount++;
- else if(str == "SAMPLER")
- samplerCount++;
- else if(str == "SAMPLER")
- bufferCount++;
- else if(str == "DEVICEMEMORY")
- deviceMemoryCount++;
- else if(str == "SHADERMODULE")
- shaderModuleCount++;
- else if(str == "DESCRIPTORPOOL")
- {
- dsPoolCount++;
- dsPoolMemory += item.second.size;
- descriptorPoolAllocations.emplace_back(&item.second);
- }
- else if(str == "PIPELINE")
- pipelineCount++;
- else if(str == "PIPELINELAYOUT")
- pipelineLayoutCount++;
- else if(str == "DESCRIPTORSETLAYOUT")
- dsLayoutCount++;
-
- updateSubAllocations( item.second );
- }
- else if( item.second.allocationScope == VK_SYSTEM_ALLOCATION_SCOPE_COMMAND )
- {
- commandCount++;
- commandMemory += item.second.size;
- }
- }
- }
-
- printf(" Objects : count = %d, size = %d\n", int(objectCount), int(objectMemory) );
- printf(" IMAGE = %d\n", int(imageCount) );
- printf(" IMAGEVIEW = %d\n", int(imageViewCount) );
- printf(" BUFFER = %d\n", int(bufferCount) );
- printf(" SAMPLER = %d\n", int(samplerCount) );
- printf(" FRAMEBUFFER = %d\n", int(framebufferCount) );
- printf(" RENDERPASS = %d\n", int(renderPassCount) );
- printf(" DEVICEMEM = %d\n", int(deviceMemoryCount) );
- printf(" SHADERMODULE = %d\n", int(shaderModuleCount) );
- printf(" PIPELINE = %d\n", int(pipelineCount ));
- printf(" PIPELINE_LAYOUT = %d\n", int(pipelineLayoutCount));
- printf(" DESCRIPTOR_SET_LAYOUT = %d\n", int(dsLayoutCount ));
- printf(" DESCRIPTOR_POOL = %d, size = %d\n", int(dsPoolCount), int(dsPoolMemory));
-
- for(const auto& dspool : descriptorPoolAllocations )
- {
- printf(" Pool: %p, size = %d, allSize = %d, sub = %d\n",
- dspool->ptr, int(dspool->size),
- int(dspool->totalSizeWithSuballocations),
- int(dspool->totalSuballocationCount) );
- }
-
- printf(" Commands: count = %d, size = %d\n", int(commandCount), int(commandMemory) );
-
- puts("");
- }
-
- std::map<void*, Allocation> allocationData;
-
-} gAllocationTracker;
-
-void* vkAllocationFunction(
- void* pUserData,
- size_t size,
- size_t alignment,
- VkSystemAllocationScope allocationScope)
-{
- auto retval = gAllocationTracker.valloc( size, alignment, allocationScope,
- pUserData ? reinterpret_cast<MemoryAllocationTag*>(pUserData) : nullptr );
-
- return retval;
-}
-
-void* vkReallocationFunction(
- void* pUserData,
- void* pOriginal,
- size_t size,
- size_t alignment,
- VkSystemAllocationScope allocationScope)
-{
- auto retval = gAllocationTracker.vrealloc( pOriginal, size, alignment, allocationScope,
- pUserData ? reinterpret_cast<MemoryAllocationTag*>(pUserData) : nullptr );
- return retval;
-}
-
-void vkFreeFunction(
- void* pUserData,
- void* pMemory)
-{
- gAllocationTracker.vfree( pMemory );
-}
-
-vk::AllocationCallbacks gDebugAllocationCallbacks( nullptr, vkAllocationFunction, vkReallocationFunction, vkFreeFunction );
-}
-
-
-
-#endif
-
-const vk::AllocationCallbacks* GetDebugAllocator()
-{
-#ifdef DALI_VULKAN_DEBUG_ALLOCATOR
- return &gDebugAllocationCallbacks;
-#else
- return nullptr;
-#endif
-}
-
-void PrintAllocationStatus()
-{
- gAllocationTracker.printStatus();
-}
-
-MemoryAllocationTag* CreateMemoryAllocationTag( const char* tagString )
-{
- if(!tagString)
- {
- return nullptr;
- }
- return new MemoryAllocationTag( tagString );
-}
-
-}
-}
-}
+++ /dev/null
-#ifndef DALI_GRAPHICS_VULKAN_DEBUG_ALLOCATOR_H
-#define DALI_GRAPHICS_VULKAN_DEBUG_ALLOCATOR_H
-
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <dali/graphics/vulkan/internal/vulkan-types.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-
-/**
- * Returns a custom allocator
- * @return
- */
-const vk::AllocationCallbacks* GetDebugAllocator();
-
-void PrintAllocationStatus();
-
-struct MemoryAllocationTag;
-
-/** Memory allocation tags are being released automatically ( hopefully ) */
-MemoryAllocationTag* CreateMemoryAllocationTag( const char* tagString );
-
-} // namespace Vulkan
-} // namespace Graphics
-} // namespace Dali
-
-
-#endif //DALI_VULKAN_161117_VULKAN_DEBUG_ALLOCATOR_H
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <dali/graphics/vulkan/internal/vulkan-debug.h>
-#include <stack>
-#if defined(DEBUG_ENABLED)
-
-std::string ArgListToString( const char* format, va_list args )
-{
- std::string str; // empty string
- if( format != nullptr )
- {
- char* buffer = nullptr;
- int err = vasprintf( &buffer, format, args );
- if( err >= 0 ) // No error
- {
- str = buffer;
- free( buffer );
- }
- }
- return str;
-}
-
-std::string FormatToString( const char* format, ... )
-{
- va_list arg;
- va_start( arg, format );
- std::string s = ArgListToString( format, arg );
- va_end( arg );
- return s;
-}
-
-
-const char* LOG_VULKAN( getenv( "LOG_VULKAN" ) );
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-
-thread_local std::stack<BlackBox*> gBlackBoxStack;
-
-void BlackBox::push()
-{
- gBlackBoxStack.push( this );
-}
-
-void BlackBox::pop()
-{
- gBlackBoxStack.pop();
-}
-
-BlackBox& BlackBox::get()
-{
- return *gBlackBoxStack.top();
-}
-
-}
-}
-}
-
-#endif
-
+++ /dev/null
-#ifndef DALI_GRAPHICS_VULKAN_DEBUG_H
-#define DALI_GRAPHICS_VULKAN_DEBUG_H
-
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#undef DEBUG_ENABLED
-#include <queue>
-#include <string>
-#include <sstream>
-#if defined(DEBUG_ENABLED)
-
-
-#include <iostream>
-#include <cstdarg>
-#include <string>
-
-extern const char* LOG_VULKAN;
-
-
-std::string ArgListToString( const char* format, va_list args );
-
-std::string FormatToString( const char* format, ... );
-
-#define DALI_LOG_STREAM( filter, level, stream ) \
- if( nullptr != LOG_VULKAN) \
- { \
- std::cout << stream << std::endl; \
- }
-
-#define DALI_LOG_INFO( filter, level, format, ... ) \
- if( nullptr != LOG_VULKAN ) \
- { \
- std::cout << FormatToString( (format), ##__VA_ARGS__ ); \
- }
-
-#else
-#define DALI_LOG_STREAM( filter, level, stream )
-#define DALI_LOG_INFO( filter, level, format, ... )
-#endif
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-
-/**
- * Helper function converting Vulkan C++ types into void* ( for logging )
- */
-template<class T, class K>
-const void* VkVoidCast( const K& o )
-{
- return static_cast<T>(o);
-}
-
-#ifdef DEBUG_ENABLED
-struct BlackBox
-{
- std::queue<std::string> debugLog;
-
- template<class T>
- BlackBox& operator <<(const T& value )
- {
- stream << value;
- return *this;
- }
-
- BlackBox& log()
- {
- stream.str(std::string());
- return *this;
- }
-
- const std::string& end()
- {
- static const std::string terminator("");
- debugLog.push( stream.str() );
- if( debugLog.size() > 128 )
- {
- debugLog.pop();
- }
- return terminator;
- }
-
- void push();
-
- static void pop();
-
- static BlackBox& get();
-
- std::stringstream stream;
-};
-#endif
-
-
-} // Namespace Vulkan
-
-} // Namespace Graphics
-
-} // Namespace Dali
-
-
-#endif // DALI_GRAPHICS_VULKAN_DEBUG_H
+++ /dev/null
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// INTERNAL INCLUDES
-#include <dali/graphics/vulkan/internal/vulkan-fence.h>
-#include <dali/graphics/vulkan/vulkan-graphics.h>
-#include <dali/graphics/vulkan/internal/vulkan-debug.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-
-Fence::Fence( Graphics& graphics ) : mGraphics( &graphics )
-{
-}
-
-const Fence& Fence::ConstRef() const
-{
- return *this;
-}
-
-Fence& Fence::Ref()
-{
- return *this;
-}
-
-Fence::~Fence() = default;
-
-vk::Fence Fence::GetVkHandle() const
-{
- return mFence;
-}
-
-bool Fence::OnDestroy()
-{
- // Copy the Vulkan handles and pointers here.
- // Cannot capture the "this" pointer in the lambda.
- // When the lambda is invoked "this" is already destroyed.
- // This method is only deferring execution to the end of the frame.
- auto device = mGraphics->GetDevice();
- auto fence = mFence;
- auto allocator = &mGraphics->GetAllocator();
-
- // capture copies of the pointers and handles
- mGraphics->DiscardResource( [ device, fence, allocator ]() {
- DALI_LOG_INFO( gVulkanFilter, Debug::General, "Invoking deleter function: fence->%p\n",
- static_cast< VkFence >(fence) )
- device.destroyFence( fence, allocator );
- } );
-
- return false;
-}
-
-
-} // namespace Vulkan
-} // namespace Graphics
-} // namespace Dali
+++ /dev/null
-#ifndef DALI_GRAPHICS_VULKAN_FENCE
-#define DALI_GRAPHICS_VULKAN_FENCE
-
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// INTERNAL INCLUDES
-#include <dali/graphics/vulkan/internal/vulkan-types.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-
-class Graphics;
-
-class Fence : public VkManaged
-{
- friend class Graphics;
-
-public:
-
- ~Fence() override;
-
- const Fence& ConstRef() const;
-
- Fence& Ref();
-
- vk::Fence GetVkHandle() const;
-
- bool OnDestroy() override;
-
-private:
- explicit Fence( Graphics& graphics );
-
-private:
-
- Graphics* mGraphics;
- vk::Fence mFence;
-};
-
-} // namespace Vulkan
-} // namespace Graphics
-} // namespace Dali
-
-#endif // DALI_GRAPHICS_VULKAN_FENCE
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics/vulkan/internal/vulkan-framebuffer.h>
-#include <dali/graphics/vulkan/vulkan-graphics.h>
-#include <dali/graphics/vulkan/internal/vulkan-image.h>
-#include <dali/graphics/vulkan/internal/vulkan-image-view.h>
-#include <dali/graphics/vulkan/internal/vulkan-debug.h>
-#include <utility>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-
-//FramebufferAttachment ------------------------
-RefCountedFramebufferAttachment FramebufferAttachment::NewColorAttachment( RefCountedImageView imageView,
- vk::ClearColorValue clearColorValue,
- bool presentable )
-{
- assert( imageView->GetImage()->GetUsageFlags() & vk::ImageUsageFlagBits::eColorAttachment );
-
- auto attachment = new FramebufferAttachment( std::move( imageView ),
- clearColorValue,
- AttachmentType::COLOR,
- presentable );
-
- return RefCountedFramebufferAttachment( attachment );
-}
-
-RefCountedFramebufferAttachment FramebufferAttachment::NewDepthAttachment( RefCountedImageView imageView,
- vk::ClearDepthStencilValue clearDepthStencilValue )
-{
- assert( imageView->GetImage()->GetUsageFlags() & vk::ImageUsageFlagBits::eDepthStencilAttachment );
-
- auto attachment = new FramebufferAttachment( std::move( imageView ),
- clearDepthStencilValue,
- AttachmentType::DEPTH_STENCIL,
- false /* presentable */ );
-
- return RefCountedFramebufferAttachment( attachment );
-}
-
-FramebufferAttachment::FramebufferAttachment( const RefCountedImageView& imageView,
- vk::ClearValue clearColor,
- AttachmentType type,
- bool presentable )
-: mImageView( imageView ),
- mClearValue( clearColor ),
- mType( type )
-{
- auto image = imageView->GetImage();
-
- auto sampleCountFlags = image->GetSampleCount();
-
- mDescription.setSamples( sampleCountFlags );
-
- if( type == AttachmentType::DEPTH_STENCIL )
- {
- mDescription.setStoreOp( vk::AttachmentStoreOp::eStore );
- }
- else
- {
- mDescription.setStoreOp( vk::AttachmentStoreOp::eStore );
- }
- mDescription.setStencilStoreOp( vk::AttachmentStoreOp::eStore );
- mDescription.setStencilLoadOp( vk::AttachmentLoadOp::eClear );
- mDescription.setFormat( image->GetFormat() );
- mDescription.setInitialLayout( vk::ImageLayout::eUndefined );
- mDescription.setLoadOp( vk::AttachmentLoadOp::eClear );
-
- if( type == AttachmentType::DEPTH_STENCIL )
- {
- mDescription.finalLayout = vk::ImageLayout::eDepthStencilAttachmentOptimal;
- }
- else
- {
- mDescription.finalLayout = presentable ? vk::ImageLayout::ePresentSrcKHR : vk::ImageLayout::eShaderReadOnlyOptimal;
- }
-}
-
-RefCountedImageView FramebufferAttachment::GetImageView() const
-{
- return mImageView;
-}
-
-const vk::AttachmentDescription& FramebufferAttachment::GetDescription() const
-{
- return mDescription;
-}
-
-const vk::ClearValue& FramebufferAttachment::GetClearValue() const
-{
- return mClearValue;
-}
-
-AttachmentType FramebufferAttachment::GetType() const
-{
- return mType;
-}
-
-bool FramebufferAttachment::IsValid() const
-{
- return mImageView;
-}
-
-
-//Framebuffer -------------------------------
-Framebuffer::Framebuffer( Graphics& graphics,
- const std::vector< RefCountedFramebufferAttachment >& colorAttachments,
- const RefCountedFramebufferAttachment& depthAttachment,
- vk::Framebuffer vkHandle,
- vk::RenderPass renderPass,
- uint32_t width,
- uint32_t height,
- bool externalRenderPass )
-: mGraphics( &graphics ),
- mWidth( width ),
- mHeight( height ),
- mColorAttachments( colorAttachments ),
- mDepthAttachment( depthAttachment ),
- mFramebuffer( vkHandle ),
- mRenderPass( renderPass ),
- mExternalRenderPass( externalRenderPass )
-{
-}
-
-uint32_t Framebuffer::GetWidth() const
-{
- return mWidth;
-}
-
-uint32_t Framebuffer::GetHeight() const
-{
- return mHeight;
-}
-
-RefCountedFramebufferAttachment Framebuffer::GetAttachment( AttachmentType type, uint32_t index ) const
-{
- switch( type )
- {
- case AttachmentType::COLOR:
- {
- return mColorAttachments[index];
- }
- case AttachmentType::DEPTH_STENCIL:
- {
- return mDepthAttachment;
- }
- case AttachmentType::INPUT:
- case AttachmentType::RESOLVE:
- case AttachmentType::PRESERVE:
- case AttachmentType::UNDEFINED:
- break;
- }
-
- return RefCountedFramebufferAttachment{};
-}
-
-std::vector< RefCountedFramebufferAttachment > Framebuffer::GetAttachments( AttachmentType type ) const
-{
- auto retval = std::vector< RefCountedFramebufferAttachment >{};
- switch( type )
- {
- case AttachmentType::COLOR:
- {
- retval.reserve( mColorAttachments.size() );
- retval.insert( retval.end(), mColorAttachments.begin(), mColorAttachments.end() );
- return std::move( retval );
- }
- case AttachmentType::DEPTH_STENCIL:
- {
- retval.reserve( 1 );
- retval.push_back( mDepthAttachment );
- return std::move( retval );
- }
- case AttachmentType::INPUT:
- case AttachmentType::RESOLVE:
- case AttachmentType::PRESERVE:
- case AttachmentType::UNDEFINED:
- {
- return std::move( retval );
- }
- }
- return std::move( retval );
-}
-
-uint32_t Framebuffer::GetAttachmentCount( AttachmentType type ) const
-{
- switch( type )
- {
- case AttachmentType::COLOR:
- {
- return U32( mColorAttachments.size() );
- }
- case AttachmentType::DEPTH_STENCIL:
- {
- return mDepthAttachment->IsValid() ? 1u : 0u;
- }
- case AttachmentType::INPUT:
- case AttachmentType::RESOLVE:
- case AttachmentType::PRESERVE:
- case AttachmentType::UNDEFINED:
- return 0u;
- }
- return 0u;
-}
-
-vk::RenderPass Framebuffer::GetRenderPass() const
-{
- return mRenderPass;
-}
-
-vk::Framebuffer Framebuffer::GetVkHandle() const
-{
- return mFramebuffer;
-}
-
-std::vector< vk::ClearValue > Framebuffer::GetClearValues() const
-{
- auto result = std::vector< vk::ClearValue >{};
-
- std::transform( mColorAttachments.begin(), // @todo & color clear enabled
- mColorAttachments.end(),
- std::back_inserter( result ),
- []( const RefCountedFramebufferAttachment& attachment ) {
- return attachment->GetClearValue();
- } );
-
- if( mDepthAttachment && mDepthAttachment->IsValid() ) // @todo & depth clear enabled
- {
- result.push_back( mDepthAttachment->GetClearValue() );
- }
-
- return std::move( result );
-}
-
-bool Framebuffer::OnDestroy()
-{
- auto device = mGraphics->GetDevice();
- auto frameBuffer = mFramebuffer;
-
- vk::RenderPass renderPass = mExternalRenderPass ? vk::RenderPass{} : mRenderPass;
-
- auto allocator = &mGraphics->GetAllocator();
-
- mGraphics->DiscardResource( [ device, frameBuffer, renderPass, allocator ]() {
-
- DALI_LOG_INFO( gVulkanFilter, Debug::General, "Invoking deleter function: framebuffer->%p\n",
- static_cast< VkFramebuffer >(frameBuffer) )
- device.destroyFramebuffer( frameBuffer, allocator );
-
- if( renderPass )
- {
- DALI_LOG_INFO( gVulkanFilter, Debug::General, "Invoking deleter function: render pass->%p\n",
- static_cast< VkRenderPass >(renderPass) )
- device.destroyRenderPass( renderPass, allocator );
- }
-
- } );
-
- return false;
-}
-
-} // Namespace Vulkan
-
-} // Namespace Graphics
-
-} // Namespace Dali
+++ /dev/null
-#ifndef DALI_GRAPHICS_VULKAN_FRAMEBUFFER
-#define DALI_GRAPHICS_VULKAN_FRAMEBUFFER
-
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics/vulkan/internal/vulkan-types.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-
-enum class AttachmentType
-{
- COLOR,
- DEPTH_STENCIL,
- INPUT,
- RESOLVE,
- PRESERVE,
- UNDEFINED
-};
-
-class Graphics;
-
-class FramebufferAttachment : public VkManaged
-{
- friend class Graphics;
-
-public:
-
- static RefCountedFramebufferAttachment NewColorAttachment( RefCountedImageView imageView,
- vk::ClearColorValue clearColorValue,
- bool presentable );
-
- static RefCountedFramebufferAttachment NewDepthAttachment( RefCountedImageView imageView,
- vk::ClearDepthStencilValue clearDepthStencilValue );
-
- RefCountedImageView GetImageView() const;
-
- const vk::AttachmentDescription& GetDescription() const;
-
- const vk::ClearValue& GetClearValue() const;
-
- AttachmentType GetType() const;
-
- bool IsValid() const;
-
-private:
- FramebufferAttachment() = default;
-
- FramebufferAttachment( const RefCountedImageView& imageView,
- vk::ClearValue clearColor,
- AttachmentType type,
- bool presentable );
-
- RefCountedImageView mImageView;
-
- vk::AttachmentDescription mDescription;
-
- vk::ClearValue mClearValue;
-
- AttachmentType mType;
-};
-
-/**
- * Framebuffer encapsulates following objects:
- * - Images ( attachments )
- * - Framebuffer
- * - ImageViews
- */
-class Framebuffer : public VkManaged
-{
-public:
- friend class Graphics;
-
- uint32_t GetWidth() const;
-
- uint32_t GetHeight() const;
-
- RefCountedFramebufferAttachment GetAttachment( AttachmentType type, uint32_t index ) const;
-
- std::vector< RefCountedFramebufferAttachment > GetAttachments( AttachmentType type ) const;
-
- uint32_t GetAttachmentCount( AttachmentType type ) const;
-
- vk::RenderPass GetRenderPass() const;
-
- vk::Framebuffer GetVkHandle() const;
-
- std::vector< vk::ClearValue > GetClearValues() const;
-
- bool OnDestroy() override;
-
-private:
-
- Framebuffer( Graphics& graphics,
- const std::vector< RefCountedFramebufferAttachment >& colorAttachments,
- const RefCountedFramebufferAttachment& depthAttachment,
- vk::Framebuffer vkHandle,
- vk::RenderPass renderPass,
- uint32_t width,
- uint32_t height,
- bool externalRenderPass = false );
-
-private:
- Graphics* mGraphics;
-
- uint32_t mWidth;
- uint32_t mHeight;
-
- std::vector< RefCountedFramebufferAttachment > mColorAttachments;
-
- RefCountedFramebufferAttachment mDepthAttachment;
-
- vk::Framebuffer mFramebuffer;
-
- vk::RenderPass mRenderPass;
-
- bool mExternalRenderPass;
-};
-
-
-} // Namespace Vulkan
-
-} // Namespace Graphics
-
-} // Namespace Dali
-
-#endif // DALI_GRAPHICS_VULKAN_FRAMEBUFFER
+++ /dev/null
-#ifndef DALI_GRAPHICS_VULKAN_HPP_WRAPPER_H
-#define DALI_GRAPHICS_VULKAN_HPP_WRAPPER_H
-
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// Vulkan without exceptions
-#ifndef VULKAN_HPP_NO_EXCEPTIONS
-#define VULKAN_HPP_NO_EXCEPTIONS
-#endif
-
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wfloat-equal"
-#pragma GCC diagnostic ignored "-Wswitch-enum"
-
-#include <vulkan/vulkan.hpp>
-
-#pragma GCC diagnostic pop
-
-#endif // DALI_GRAPHICS_VULKAN_HPP_WRAPPER_H
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics/vulkan/internal/vulkan-image-view.h>
-#include <dali/graphics/vulkan/vulkan-graphics.h>
-#include <dali/graphics/vulkan/internal/vulkan-image.h>
-#include <dali/graphics/vulkan/internal/vulkan-debug.h>
-#include <utility>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-
-ImageView::ImageView( Graphics& graphics, RefCountedImage image, vk::ImageViewCreateInfo createInfo )
- : mGraphics( &graphics ),
- mImage( std::move( image ) ),
- mCreateInfo( std::move( createInfo ) ),
- mImageView( nullptr )
-{
-}
-
-ImageView::~ImageView() = default;
-
-vk::ImageView ImageView::GetVkHandle() const
-{
- return mImageView;
-}
-
-RefCountedImage ImageView::GetImage() const
-{
- return mImage;
-}
-
-uint32_t ImageView::GetLayerCount() const
-{
- return mImage->GetLayerCount();
-}
-
-uint32_t ImageView::GetMipLevelCount() const
-{
- return mImage->GetMipLevelCount();
-}
-
-vk::ImageAspectFlags ImageView::GetImageAspectMask() const
-{
- return vk::ImageAspectFlags();
-}
-
-const ImageView& ImageView::ConstRef()
-{
- return *this;
-}
-
-ImageView& ImageView::Ref()
-{
- return *this;
-}
-
-bool ImageView::OnDestroy()
-{
- auto device = mGraphics->GetDevice();
- auto imageView = mImageView;
- auto allocator = &mGraphics->GetAllocator();
-
- mGraphics->DiscardResource( [ device, imageView, allocator ]() {
- DALI_LOG_INFO( gVulkanFilter, Debug::General, "Invoking deleter function: image view->%p\n",
- static_cast< VkImageView >(imageView) )
- device.destroyImageView( imageView, allocator );
- } );
-
- return VkManaged::OnDestroy();
-}
-
-} // namespace Vulkan
-} // namespace Graphics
-} // namespace Dali
-
+++ /dev/null
-#ifndef DALI_GRAPHICS_VULKAN_IMAGE_VIEW
-#define DALI_GRAPHICS_VULKAN_IMAGE_VIEW
-
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics/vulkan/internal/vulkan-types.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-
-class Graphics;
-
-/*
- * ImageView
- */
-class ImageView : public VkManaged
-{
- friend class Graphics;
-
-public:
-
- ~ImageView() override;
-
- /**
- *
- * @return
- */
- vk::ImageView GetVkHandle() const;
-
- /**
- * Returns bound ImageRef
- * @return
- */
- RefCountedImage GetImage() const;
-
- /**
- *
- * @return
- */
- uint32_t GetLayerCount() const;
-
- /**
- *
- * @return
- */
- uint32_t GetMipLevelCount() const;
-
- /**
- *
- * @return
- */
- vk::ImageAspectFlags GetImageAspectMask() const;
-
- const ImageView& ConstRef();
-
- ImageView& Ref();
-
- bool OnDestroy() override;
-
-private:
- ImageView( Graphics& graphics,
- RefCountedImage image,
- vk::ImageViewCreateInfo createInfo );
-
-private:
- Graphics* mGraphics;
- RefCountedImage mImage;
- vk::ImageViewCreateInfo mCreateInfo;
- vk::ImageView mImageView;
-};
-
-} //namespace Vulkan
-} //namespace Graphics
-} //namespace Dali
-
-#endif //DALI_GRAPHICS_VULKAN_IMAGE_VIEW
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics/vulkan/vulkan-graphics.h>
-#include <dali/graphics/vulkan/internal/vulkan-image.h>
-#include <dali/graphics/vulkan/internal/vulkan-debug.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-
-Image::Image( Graphics& graphics, const vk::ImageCreateInfo& createInfo, vk::Image externalImage )
- : mGraphics( &graphics ),
- mCreateInfo( createInfo ),
- mImage( externalImage ),
- mImageLayout( mCreateInfo.initialLayout ),
- mIsExternal( static_cast<bool>(externalImage) )
-{
- auto depthStencilFormats = std::vector< vk::Format >{
- vk::Format::eD32Sfloat,
- vk::Format::eD16Unorm,
- vk::Format::eD32SfloatS8Uint,
- vk::Format::eD24UnormS8Uint,
- vk::Format::eD16UnormS8Uint,
- vk::Format::eS8Uint,
- };
-
- auto hasDepth = std::find( depthStencilFormats.begin(), depthStencilFormats.end(), createInfo.format );
-
- if( hasDepth != depthStencilFormats.end() )
- {
- auto format = *hasDepth;
-
- if( format == vk::Format::eD32Sfloat || format == vk::Format::eD16Unorm )
- {
- mAspectFlags = vk::ImageAspectFlagBits::eDepth;
- }
- else if( format == vk::Format::eS8Uint )
- {
- mAspectFlags = vk::ImageAspectFlagBits::eStencil;
- }
- else
- {
- mAspectFlags = vk::ImageAspectFlagBits::eDepth | vk::ImageAspectFlagBits::eStencil;
- }
- }
- else
- {
- mAspectFlags = vk::ImageAspectFlagBits::eColor;
- }
-}
-
-vk::Image Image::GetVkHandle() const
-{
- return mImage;
-}
-
-vk::ImageLayout Image::GetImageLayout() const
-{
- return mImageLayout;
-}
-
-uint32_t Image::GetWidth() const
-{
- return mCreateInfo.extent.width;
-}
-
-uint32_t Image::GetHeight() const
-{
- return mCreateInfo.extent.height;
-}
-
-uint32_t Image::GetLayerCount() const
-{
- return mCreateInfo.arrayLayers;
-}
-
-uint32_t Image::GetMipLevelCount() const
-{
- return mCreateInfo.mipLevels;
-}
-
-vk::Format Image::GetFormat() const
-{
- return mCreateInfo.format;
-}
-
-vk::ImageType Image::GetImageType() const
-{
- return mCreateInfo.imageType;
-}
-
-vk::ImageTiling Image::GetImageTiling() const
-{
- return mCreateInfo.tiling;
-}
-
-vk::ImageAspectFlags Image::GetAspectFlags() const
-{
- return mAspectFlags;
-}
-
-void Image::SetImageLayout( vk::ImageLayout imageLayout )
-{
- mImageLayout = imageLayout;
-}
-
-const Image& Image::ConstRef()
-{
- return *this;
-}
-
-Image& Image::Ref()
-{
- return *this;
-}
-
-vk::ImageUsageFlags Image::GetUsageFlags() const
-{
- return mCreateInfo.usage;
-}
-
-vk::SampleCountFlagBits Image::GetSampleCount() const
-{
- return mCreateInfo.samples;
-}
-
-void Image::DestroyNow()
-{
- DestroyVulkanResources( mGraphics->GetDevice(), mImage, mDeviceMemory->ReleaseVkObject(), &mGraphics->GetAllocator() );
- mImage = nullptr;
- mDeviceMemory = nullptr;
-}
-
-bool Image::OnDestroy()
-{
- if( !mIsExternal )
- {
- if( mImage )
- {
- auto device = mGraphics->GetDevice();
- auto image = mImage;
- auto allocator = &mGraphics->GetAllocator();
- auto memory = mDeviceMemory->ReleaseVkObject();
-
- mGraphics->DiscardResource( [ device, image, memory, allocator ]() {
- DestroyVulkanResources( device, image, memory, allocator );
- }
- );
- }
- }
-
- return false;
-}
-
-void Image::DestroyVulkanResources( vk::Device device, vk::Image image, vk::DeviceMemory memory, const vk::AllocationCallbacks* allocator )
-{
- DALI_LOG_INFO( gVulkanFilter, Debug::General, "Invoking deleter function: image->%p\n",
- static_cast< VkImage >(image) )
- device.destroyImage( image, allocator );
-
- device.freeMemory( memory, allocator );
-}
-
-
-} // namespace Vulkan
-
-} // namespace Graphics
-
-} // namespace Dali
+++ /dev/null
-#ifndef DALI_GRAPHICS_VULKAN_IMAGE
-#define DALI_GRAPHICS_VULKAN_IMAGE
-
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics/vulkan/internal/vulkan-types.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-
-class Graphics;
-class Memory;
-
-class Image : public VkManaged
-{
- friend class Graphics;
-
-public:
-
- /**
- * Returns underlying Vulkan object
- * @return
- */
- vk::Image GetVkHandle() const;
-
- /**
- * Returns VkImageLayout associated with the image
- * @return
- */
- vk::ImageLayout GetImageLayout() const;
-
- /**
- * Returns width in pixels
- * @return
- */
- uint32_t GetWidth() const;
-
- /**
- * Returns height in pixels
- * @return
- */
- uint32_t GetHeight() const;
-
- /**
- * Returns number of layers
- * @return
- */
- uint32_t GetLayerCount() const;
-
- /**
- * Returns number of mipmap levels
- * @return
- */
- uint32_t GetMipLevelCount() const;
-
- /**
- * Returns pixel format
- * @return
- */
- vk::Format GetFormat() const;
-
- /**
- * returns image type ( VkImageType)
- * @return
- */
- vk::ImageType GetImageType() const;
-
- /**
- * Returns used image tiling mode
- * @return
- */
- vk::ImageTiling GetImageTiling() const;
-
- vk::ImageAspectFlags GetAspectFlags() const;
-
- /**
- *
- * @return
- */
- vk::ImageUsageFlags GetUsageFlags() const;
-
- vk::SampleCountFlagBits GetSampleCount() const;
-
- void SetImageLayout( vk::ImageLayout imageLayout );
-
- const Image& ConstRef();
-
- Image& Ref();
-
- bool OnDestroy() override;
-
- Memory* GetMemory() const
- {
- return mDeviceMemory.get();
- }
-
- /**
- * Destroys underlying Vulkan resources on the caller thread.
- *
- * @note Calling this function is unsafe and makes any further use of
- * image invalid.
- */
- void DestroyNow();
-
-private:
-
- /**
- * Creates new VkImage with given specification, it doesn't
- * bind the memory.
- * @param graphics
- * @param createInfo
- */
- Image( Graphics& graphics, const vk::ImageCreateInfo& createInfo, vk::Image externalImage = nullptr );
-
- /**
- * Destroys used Vulkan resource objects
- * @param device Vulkan device
- * @param image Vulkan image
- * @param memory Vulkan device memory
- * @param allocator Pointer to the Vulkan allocator callbacks
- */
- static void DestroyVulkanResources( vk::Device device, vk::Image image, vk::DeviceMemory memory, const vk::AllocationCallbacks* allocator );
-
-private:
- Graphics* mGraphics;
- vk::ImageCreateInfo mCreateInfo;
- vk::Image mImage;
- vk::ImageLayout mImageLayout;
- vk::ImageAspectFlags mAspectFlags;
-
- std::unique_ptr<Memory> mDeviceMemory;
- bool mIsExternal;
-};
-
-} // namespace Vulkan
-
-} // namespace Graphics
-
-} // namespace Dali
-
-#endif // DALI_GRAPHICS_VULKAN_IMAGE
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// INTERNAL INCLUDES
-#include <dali/graphics/vulkan/internal/vulkan-command-buffer.h>
-#include <dali/graphics/vulkan/internal/vulkan-fence.h>
-#include <dali/graphics/vulkan/vulkan-graphics.h>
-#include <dali/graphics/vulkan/internal/vulkan-queue.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-
-// submission
-SubmissionData::SubmissionData( const std::vector< vk::Semaphore >& waitSemaphores_,
- vk::PipelineStageFlags waitDestinationStageMask_,
- const std::vector< RefCountedCommandBuffer >& commandBuffers_,
- const std::vector< vk::Semaphore >& signalSemaphores_ )
- : waitSemaphores( waitSemaphores_ ),
- waitDestinationStageMask( waitDestinationStageMask_ ),
- commandBuffers( commandBuffers_ ),
- signalSemaphores( signalSemaphores_ )
-{
-}
-
-SubmissionData& SubmissionData::SetWaitSemaphores( const std::vector< vk::Semaphore >& semaphores )
-{
- waitSemaphores = semaphores;
- return *this;
-}
-
-SubmissionData& SubmissionData::SetWaitDestinationStageMask( vk::PipelineStageFlags dstStageMask )
-{
- waitDestinationStageMask = dstStageMask;
- return *this;
-}
-
-SubmissionData& SubmissionData::SetCommandBuffers( const std::vector< RefCountedCommandBuffer >& cmdBuffers )
-{
- commandBuffers = cmdBuffers;
- return *this;
-}
-
-SubmissionData& SubmissionData::SetSignalSemaphores( const std::vector< vk::Semaphore >& semaphores )
-{
- signalSemaphores = semaphores;
- return *this;
-}
-
-// queue
-Queue::Queue( Graphics& graphics,
- vk::Queue queue,
- uint32_t queueFamilyIndex,
- uint32_t queueIndex,
- vk::QueueFlags queueFlags )
- : mGraphics( graphics ),
- mQueue( queue ),
- mFlags( queueFlags ),
- mQueueFamilyIndex( queueFamilyIndex ),
- mQueueIndex( queueIndex ),
- mMutex()
-{
-}
-
-Queue::~Queue() = default; // queues are non-destructible
-
-vk::Queue Queue::GetVkHandle()
-{
- return mQueue;
-}
-
-std::unique_ptr<std::lock_guard<std::recursive_mutex>> Queue::Lock()
-{
- return std::unique_ptr<std::lock_guard<std::recursive_mutex>>( new std::lock_guard<std::recursive_mutex>( mMutex ) );
-}
-
-} // namespace Vulkan
-} // namespace Graphics
-} // namespace Dali
+++ /dev/null
-#ifndef DALI_GRAPHICS_VULKAN_QUEUE
-#define DALI_GRAPHICS_VULKAN_QUEUE
-
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// INTERNAL INCLUDES
-#include <dali/graphics/vulkan/internal/vulkan-types.h>
-
-#include <mutex>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-
-class Fence;
-
-struct SubmissionData
-{
- SubmissionData() = default;
-
- explicit SubmissionData( const std::vector< vk::Semaphore >& waitSemaphores_,
- vk::PipelineStageFlags waitDestinationStageMask_,
- const std::vector< RefCountedCommandBuffer >& commandBuffers_,
- const std::vector< vk::Semaphore >& signalSemaphores_ );
-
- SubmissionData& SetWaitSemaphores( const std::vector< vk::Semaphore >& semaphores );
-
- SubmissionData& SetWaitDestinationStageMask( vk::PipelineStageFlags dstStageMask );
-
- SubmissionData& SetCommandBuffers( const std::vector< RefCountedCommandBuffer >& cmdBuffers );
-
- SubmissionData& SetSignalSemaphores( const std::vector< vk::Semaphore >& semaphores );
-
- std::vector< vk::Semaphore > waitSemaphores;
- vk::PipelineStageFlags waitDestinationStageMask;
- std::vector< RefCountedCommandBuffer > commandBuffers;
- std::vector< vk::Semaphore > signalSemaphores;
-};
-
-class Graphics;
-
-class Queue
-{
- friend class Graphics;
-
-public:
-
- ~Queue(); // queues are non-destructible
-
- vk::Queue GetVkHandle();
-
- std::unique_ptr<std::lock_guard<std::recursive_mutex>> Lock();
-
-private:
- Queue( Graphics& graphics,
- vk::Queue queue,
- uint32_t queueFamilyIndex,
- uint32_t queueIndex,
- vk::QueueFlags queueFlags );
-
-private:
- Graphics& mGraphics;
- vk::Queue mQueue;
- vk::QueueFlags mFlags;
- uint32_t mQueueFamilyIndex;
- uint32_t mQueueIndex;
-
- std::recursive_mutex mMutex;
-};
-
-} // namespace Vulkan
-
-} // namespace Graphics
-
-} // namespace Dali
-
-#endif // DALI_GRAPHICS_VULKAN_QUEUE
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// INTERNAL INCLUDES
-#include <dali/graphics/vulkan/internal/vulkan-sampler.h>
-#include <dali/graphics/vulkan/vulkan-graphics.h>
-#include <dali/graphics/vulkan/internal/vulkan-debug.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-
-/**
- * Sampler
- */
-Sampler::Sampler( Graphics& graphics, const vk::SamplerCreateInfo& createInfo )
- : mGraphics( &graphics ),
- mCreateInfo( createInfo )
-{
-}
-
-vk::SamplerCreateFlags Sampler::GetCreateFlags() const
-{
- return mCreateInfo.flags;
-}
-
-vk::Filter Sampler::GetMinFilter() const
-{
- return mCreateInfo.minFilter;
-}
-
-vk::Filter Sampler::GetMagFilter() const
-{
- return mCreateInfo.magFilter;
-}
-
-vk::SamplerMipmapMode Sampler::GetMipMapMode() const
-{
- return mCreateInfo.mipmapMode;
-}
-
-vk::SamplerAddressMode Sampler::GetAddressModeU() const
-{
- return mCreateInfo.addressModeU;
-}
-
-vk::SamplerAddressMode Sampler::GetAddressModeV() const
-{
- return mCreateInfo.addressModeV;
-}
-
-vk::SamplerAddressMode Sampler::GetAddressModeW() const
-{
- return mCreateInfo.addressModeW;
-}
-
-float Sampler::GetMipLodBias() const
-{
- return mCreateInfo.mipLodBias;
-}
-
-vk::Bool32 Sampler::AnisotropyEnabled() const
-{
- return mCreateInfo.anisotropyEnable;
-}
-
-float Sampler::GetMaxAnisotropy() const
-{
- return mCreateInfo.maxAnisotropy;
-}
-
-vk::Bool32 Sampler::CompareEnabled() const
-{
- return mCreateInfo.compareEnable;
-}
-
-vk::CompareOp Sampler::GetCompareOperation() const
-{
- return mCreateInfo.compareOp;
-}
-
-float Sampler::GetMinLod() const
-{
- return mCreateInfo.minLod;
-}
-
-float Sampler::GetMaxLod() const
-{
- return mCreateInfo.maxLod;
-}
-
-vk::BorderColor Sampler::GetBorderColor() const
-{
- return mCreateInfo.borderColor;
-}
-
-vk::Bool32 Sampler::UsesUnnormalizedCoordinates() const
-{
- return mCreateInfo.unnormalizedCoordinates;
-}
-
-Sampler::~Sampler() = default;
-
-vk::Sampler Sampler::GetVkHandle() const
-{
- return mSampler;
-}
-
-const Sampler& Sampler::ConstRef()
-{
- return *this;
-}
-
-Sampler& Sampler::Ref()
-{
- return *this;
-}
-
-bool Sampler::OnDestroy()
-{
- auto device = mGraphics->GetDevice();
- auto sampler = mSampler;
- auto allocator = &mGraphics->GetAllocator();
-
- mGraphics->DiscardResource( [ device, sampler, allocator ]() {
- DALI_LOG_INFO( gVulkanFilter, Debug::General, "Invoking deleter function: sampler->%p\n",
- static_cast< VkSampler >(sampler) )
- device.destroySampler( sampler, allocator );
- } );
-
- return false;
-}
-
-} // namespace Vulkan
-} // namespace Graphics
-} // namespace Dali
+++ /dev/null
-#ifndef DALI_GRAPHICS_VULKAN_SAMPLER_H
-#define DALI_GRAPHICS_VULKAN_SAMPLER_H
-
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// INTERNAL INCLUDES
-#include <dali/graphics/vulkan/internal/vulkan-types.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-
-class Graphics;
-
-class Sampler : public VkManaged
-{
- friend class Graphics;
-
-public:
-
- vk::SamplerCreateFlags GetCreateFlags() const;
-
- vk::Filter GetMinFilter() const;
-
- vk::Filter GetMagFilter() const;
-
- vk::SamplerMipmapMode GetMipMapMode() const;
-
- vk::SamplerAddressMode GetAddressModeU() const;
-
- vk::SamplerAddressMode GetAddressModeV() const;
-
- vk::SamplerAddressMode GetAddressModeW() const;
-
- float GetMipLodBias() const;
-
- vk::Bool32 AnisotropyEnabled() const;
-
- float GetMaxAnisotropy() const;
-
- vk::Bool32 CompareEnabled() const;
-
- vk::CompareOp GetCompareOperation() const;
-
- float GetMinLod() const;
-
- float GetMaxLod() const;
-
- vk::BorderColor GetBorderColor() const;
-
- vk::Bool32 UsesUnnormalizedCoordinates() const;
-
- /**
- * Returns VkSampler object
- * @return
- */
- vk::Sampler GetVkHandle() const;
-
- const Sampler& ConstRef();
-
- Sampler& Ref();
-
- bool OnDestroy() override;
-
-private:
-
- explicit Sampler( Graphics& graphics, const vk::SamplerCreateInfo& createInfo );
-
- ~Sampler() override;
-
-private:
- Graphics* mGraphics;
- vk::SamplerCreateInfo mCreateInfo;
- vk::Sampler mSampler;
-
-};
-
-} // namespace Vulkan
-} // namespace Graphics
-} // namespace Dali
-#endif //DALI_GRAPHICS_VULKAN_SAMPLER_H
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics/vulkan/internal/vulkan-shader.h>
-#include <dali/graphics/vulkan/vulkan-graphics.h>
-#include <dali/graphics/vulkan/internal/spirv/vulkan-spirv.h>
-#include <dali/graphics/vulkan/internal/vulkan-debug.h>
-#include <iostream>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-
-/*
- * Class: Shader::Impl
- */
-struct Shader::Impl
-{
- Impl( Shader& owner, Graphics& graphics, const vk::ShaderModuleCreateInfo& info ) :
- mOwner( owner ),
- mGraphics( graphics ),
- mCreateInfo( info ),
- mPipelineShaderStage( vk::ShaderStageFlagBits::eAllGraphics )
- {
- mSPIRVShader = SpirV::SPIRVUtils::Parse( info.pCode, info.codeSize, vk::ShaderStageFlagBits::eVertex );
- }
-
- ~Impl()
- {
- if( mShaderModule )
- {
- mGraphics.GetDevice().destroyShaderModule( mShaderModule, mGraphics.GetAllocator() );
- }
- }
-
- vk::Result Initialise()
- {
- if( ( mShaderModule = VkAssert(
- mGraphics.GetDevice().createShaderModule( mCreateInfo, mGraphics.GetAllocator() ) ) ) )
- {
- return vk::Result::eSuccess;
- }
- return vk::Result::eErrorInitializationFailed;
- }
-
- vk::ShaderModule GetVkHandle() const
- {
- return mShaderModule;
- }
-
- Shader& mOwner;
- Graphics& mGraphics;
- vk::ShaderModuleCreateInfo mCreateInfo;
- vk::ShaderModule mShaderModule;
- std::unique_ptr< SpirV::SPIRVShader > mSPIRVShader;
- vk::ShaderStageFlagBits mPipelineShaderStage;
-};
-
-/*
- * Class: Shader
- */
-Handle< Shader > Shader::New( Graphics& graphics, const vk::ShaderModuleCreateInfo& info )
-{
- auto shader = Handle< Shader >( new Shader( graphics, info ) ); // can't use make unique because of permissions
- if( shader )
- {
- shader->mImpl->Initialise();
- }
- return shader;
-}
-
-Handle< Shader > Shader::New( Graphics& graphics, const void* bytes, std::size_t size )
-{
- return New( graphics, vk::ShaderModuleCreateInfo{}
- .setCodeSize( size )
- .setPCode( reinterpret_cast<const uint32_t*>(bytes) ) );
-}
-
-Shader::Shader( Graphics& graphics, const vk::ShaderModuleCreateInfo& info )
-{
- mImpl = MakeUnique< Impl >( *this, graphics, info );
-}
-
-Shader::~Shader() = default;
-
-vk::ShaderModule Shader::GetVkHandle() const
-{
- return mImpl->GetVkHandle();
-}
-
-bool Shader::OnDestroy()
-{
- auto device = mImpl->mGraphics.GetDevice();
- auto shaderModule = mImpl->mShaderModule;
- auto allocator = &mImpl->mGraphics.GetAllocator();
-
- mImpl->mGraphics.DiscardResource( [ device, shaderModule, allocator ]() {
- DALI_LOG_INFO( gVulkanFilter, Debug::General, "Invoking deleter function: shader module->%p\n",
- static_cast< VkShaderModule >(shaderModule) )
- device.destroyShaderModule( shaderModule, allocator );
- } );
-
- return true;
-}
-
-const SpirV::SPIRVShader& Shader::GetSPIRVReflection() const
-{
- return *mImpl->mSPIRVShader;
-}
-
-void Shader::SetExplicitShaderStage( vk::ShaderStageFlagBits shaderStage )
-{
- mImpl->mPipelineShaderStage = shaderStage;
-}
-
-vk::ShaderStageFlagBits Shader::GetExplicitShaderStage() const
-{
- return mImpl->mPipelineShaderStage;
-}
-
-
-}
-}
-}
+++ /dev/null
-#ifndef DALI_GRAPHICS_VULKAN_SHADER
-#define DALI_GRAPHICS_VULKAN_SHADER
-
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// INTERNAL INCLUDES
-#include <dali/graphics/vulkan/internal/vulkan-types.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-namespace SpirV
-{
-class SPIRVShader;
-}
-
-class Graphics;
-
-class Shader : public VkManaged // can be overriden as ShaderGLSL for example
-{
-public:
-
- enum class Type
- {
- VERTEX = static_cast<int>( vk::ShaderStageFlagBits::eVertex ),
- FRAGMENT = static_cast<int>( vk::ShaderStageFlagBits::eFragment ),
- COMPUTE = static_cast<int>( vk::ShaderStageFlagBits::eCompute ),
- GEOMETRY = static_cast<int>( vk::ShaderStageFlagBits::eGeometry ),
- };
-
- /**
- *
- * @param graphics
- * @param info
- * @return
- */
- static Handle< Shader > New( Graphics& graphics, const vk::ShaderModuleCreateInfo& info );
-
- /**
- * Creates new shader module from SPIR-V code
- * @param graphics
- * @param bytes
- * @param size
- * @return
- */
- static Handle< Shader > New( Graphics& graphics, const void* bytes, std::size_t size );
-
- /**
- *
- */
- ~Shader() override;
-
- vk::ShaderModule GetVkHandle() const;
-
- const SpirV::SPIRVShader& GetSPIRVReflection() const;
-
- bool OnDestroy() override;
-
- operator vk::ShaderModule() const
- {
- return GetVkHandle();
- }
-
- /**
- * Sets a unique pipeline stage to be used with the shader
- * @param shaderStage
- */
- void SetExplicitShaderStage( vk::ShaderStageFlagBits shaderStage );
-
- vk::ShaderStageFlagBits GetExplicitShaderStage() const;
-
-private:
-
- Shader( Graphics& graphics, const vk::ShaderModuleCreateInfo& info );
-
-private:
-
- struct Impl;
- std::unique_ptr< Impl > mImpl;
-};
-
-} // Namespace Vulkan
-
-} // Namespace Graphics
-
-} // Namespace Dali
-
-#endif // DALI_GRAPHICS_VULKAN_SHADER
+++ /dev/null
-/*
- * This is the test code that allows to run Vulkan backend
- * as standalone application. Supports both Xcb and Xlib window
- * integration. MUST NOT BE COMPILED WITH DALI!
- */
-
-// for surface implementation
-#ifndef VK_USE_PLATFORM_XLIB_KHR
-#define VK_USE_PLATFORM_XLIB_KHR
-#endif
-#ifndef VK_USE_PLATFORM_XCB_KHR
-#define VK_USE_PLATFORM_XCB_KHR
-#endif
-
-#include <glm/glm.hpp>
-#include <glm/gtc/matrix_transform.hpp>
-#include <glm/matrix.hpp>
-#include <glm/vector_relational.hpp>
-
-using namespace glm;
-
-#include <dali/integration-api/graphics/graphics.h>
-#include <dali/integration-api/graphics/vulkan/vk-surface-factory.h>
-#include <dali/integration-api/graphics/vulkan/vulkan-hpp-wrapper.h>
-
-#include <unistd.h>
-#include <xcb/xcb.h>
-
-// internals
-//#include "generated/spv-shaders-gen.h"
-#include "vulkan-types.h"
-#include <dali/graphics/vulkan/internal/vulkan-types.h>
-
-#include <dali/graphics/vulkan/internal/vulkan-gpu-memory-allocator.h>
-#include <dali/graphics/vulkan/internal/vulkan-gpu-memory-handle.h>
-#include <dali/graphics/vulkan/internal/vulkan-gpu-memory-manager.h>
-#include <dali/graphics/vulkan/internal/vulkan-buffer.h>
-#include <dali/graphics/vulkan/internal/vulkan-command-buffer.h>
-#include <dali/graphics/vulkan/internal/vulkan-command-pool.h>
-#include <dali/graphics/vulkan/internal/vulkan-descriptor-set.h>
-#include <dali/graphics/vulkan/internal/vulkan-framebuffer.h>
-#include <dali/graphics/vulkan/vulkan-graphics.h>
-#include <dali/graphics/vulkan/internal/vulkan-image.h>
-#include <dali/graphics/vulkan/internal/vulkan-pipeline.h>
-#include <dali/graphics/vulkan/internal/vulkan-shader.h>
-#include <dali/graphics/vulkan/internal/vulkan-surface.h>
-#include <dali/graphics/vulkan/internal/spirv/vulkan-spirv.h>
-
-#define USE_XLIB 0
-
-#include <iostream>
-#include <dali/integration-api/debug.h>
-
-using Dali::Graphics::Vulkan::Buffer;
-using Dali::Graphics::Vulkan::CommandBuffer;
-using Dali::Graphics::Vulkan::CommandPool;
-using Dali::Graphics::Vulkan::DescriptorPool;
-using Dali::Graphics::Vulkan::GpuMemoryAllocator;
-using Dali::Graphics::Vulkan::GpuMemoryManager;
-using Dali::Graphics::Vulkan::Pipeline;
-using Dali::Graphics::Vulkan::RefCountedPipeline;
-using Dali::Graphics::Vulkan::Shader;
-using Dali::Graphics::Vulkan::RefCountedShader;
-using Dali::Integration::Graphics::Graphics;
-using Dali::Integration::Graphics::Vulkan::VkSurfaceFactory;
-
-extern std::vector< uint8_t > VSH;
-extern std::vector< uint8_t > FSH;
-
-namespace // unnamed namespace
-{
-#if defined(DEBUG_ENABLED)
-Debug::Filter* gVulkanFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_VULKAN" );
-#endif
-}
-
-template< typename T, typename... Args >
-std::unique_ptr< T > MakeUnique( Args&& ... args )
-{
- return std::unique_ptr< T >( new T( std::forward< Args >( args )... ) );
-}
-
-class VkSurfaceXlib : public Dali::Integration::Graphics::Vulkan::VkSurfaceFactory
-{
-public:
- /**
- * Instantiates surface factory ( should
- * @param display
- * @param window
- */
- VkSurfaceXlib( Display* display, Window window ) : VkSurfaceFactory(), mDisplay( display ), mWindow( window )
- {
- }
-
- virtual vk::SurfaceKHR Create( vk::Instance instance,
- const vk::AllocationCallbacks* allocCallbacks,
- vk::PhysicalDevice physicalDevice ) const override
- {
- vk::XlibSurfaceCreateInfoKHR info;
- info.setDpy( mDisplay ).setWindow( mWindow );
- auto retval = instance.createXlibSurfaceKHR( info, allocCallbacks ).value;
- return retval;
- }
-
-private:
- Display* mDisplay;
- Window mWindow;
- vk::SurfaceKHR mSurface;
-};
-
-class VkSurfaceXcb : public Dali::Integration::Graphics::Vulkan::VkSurfaceFactory
-{
-public:
- /**
- * Instantiates surface factory ( should
- * @param display
- * @param window
- */
- VkSurfaceXcb( xcb_connection_t* connection, xcb_window_t window )
- : VkSurfaceFactory{}, mConnection( connection ), mWindow( window )
- {
- }
-
- virtual vk::SurfaceKHR Create( vk::Instance instance,
- const vk::AllocationCallbacks* allocCallbacks,
- vk::PhysicalDevice physicalDevice ) const override
- {
- vk::XcbSurfaceCreateInfoKHR info;
- info.setConnection( mConnection ).setWindow( mWindow );
- auto retval = instance.createXcbSurfaceKHR( info, allocCallbacks ).value;
- return retval;
- }
-
-private:
- xcb_connection_t* mConnection;
- xcb_window_t mWindow;
- vk::SurfaceKHR mSurface;
-};
-
-namespace Test
-{
-struct xlib_window_t
-{
- uint32_t width{ 0u };
- uint32_t height{ 0u };
- Window window{};
- Display* display{ nullptr };
-
- ~xlib_window_t()
- {
- XDestroyWindow( display, window );
- }
-};
-
-std::unique_ptr< xlib_window_t > create_xlib_window( int width, int height )
-{
- std::unique_ptr< xlib_window_t > wnd{ new xlib_window_t };
- // 1. Create Window ( done by DALI
-
- wnd->width = width;
- wnd->height = height;
- wnd->display = XOpenDisplay( nullptr );
- auto defaultScreen = DefaultScreen( wnd->display );
- wnd->window = XCreateSimpleWindow( wnd->display,
- RootWindow( wnd->display, defaultScreen ),
- 0,
- 0,
- wnd->width,
- wnd->height,
- 1,
- BlackPixel( wnd->display, defaultScreen ),
- WhitePixel( wnd->display, defaultScreen ) );
-
- XSelectInput( wnd->display, wnd->window, ExposureMask | KeyPressMask );
- XMapWindow( wnd->display, wnd->window );
- XSync( wnd->display, false );
-
- return wnd;
-}
-
-struct xcb_window_t
-{
- uint32_t width{ 0u };
- uint32_t height{ 0u };
- ::xcb_window_t window;
- xcb_connection_t* connection;
-
- ~xcb_window_t()
- {
- xcb_destroy_window( connection, window );
- }
-};
-
-std::unique_ptr< Test::xcb_window_t > create_xcb_window( int width, int height )
-{
- std::unique_ptr< Test::xcb_window_t > wnd{ new Test::xcb_window_t };
- // 1. Create Window ( done by DALI
-
- wnd->width = width;
- wnd->height = height;
-
- int screenNum( 0 );
-
- xcb_connection_t* connection = xcb_connect( NULL, &screenNum );
- const xcb_setup_t* setup = xcb_get_setup( connection );
- xcb_screen_iterator_t iter = xcb_setup_roots_iterator( setup );
- for( int i = 0; i < screenNum; ++i )
- xcb_screen_next( &iter );
-
- xcb_screen_t* screen = iter.data;
- ::xcb_window_t window = xcb_generate_id( connection );
-
- uint32_t mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
- uint32_t values[] = { screen->white_pixel, XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_KEY_PRESS };
-
- xcb_create_window( connection,
- XCB_COPY_FROM_PARENT,
- window,
- screen->root,
- 0,
- 0,
- wnd->width,
- wnd->height,
- 0,
- XCB_WINDOW_CLASS_INPUT_OUTPUT,
- screen->root_visual,
- mask,
- values );
-
- xcb_map_window( connection, window );
- const uint32_t coords[] = { 100, 100 };
- xcb_configure_window( connection, window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords );
- xcb_flush( connection );
-
- wnd->connection = connection;
- wnd->window = window;
-
- return wnd;
-}
-} // namespace Test
-
-namespace VulkanTest
-{
-Dali::Graphics::Vulkan::RefCountedGpuMemoryBlock test_gpu_memory_manager(
- Dali::Graphics::Vulkan::Graphics& graphics,
- GpuMemoryManager& gpuManager,
- const Dali::Graphics::Vulkan::Handle< Buffer >& buffer )
-{
- auto device = graphics.GetDevice();
- auto& allocator = graphics.GetAllocator();
-
- auto& gpuAllocator = gpuManager.GetDefaultAllocator();
- return gpuAllocator.Allocate( buffer, vk::MemoryPropertyFlagBits::eHostVisible );
-}
-
-struct UniformData
-{
- mat4 mvp;
- vec4 color;
- vec3 size;
-} __attribute__(( aligned( 16 )));
-
-struct UniformClipData
-{
- mat4 clip;
-} __attribute__(( aligned( 16 )));
-
-mat4 MVP;
-
-template< class T >
-void update_buffer( Dali::Graphics::Vulkan::RefCountedBuffer buffer, T& value )
-{
- auto ptr = reinterpret_cast<T*>( buffer->GetMemoryHandle()
- ->Map());
- *ptr = value;
- buffer->GetMemoryHandle()
- ->Unmap();
-}
-
-void update_translation( Dali::Graphics::Vulkan::RefCountedBuffer buffer )
-{
- static float x = 0.0f;
- x += 0.5f;
-
- /*
- UniformData ub;
-
- auto modelMat = glm::translate( mat4{1}, vec3( x, x, 0.0f ) );
- modelMat = glm::rotate( modelMat, glm::radians( x ), glm::vec3( 0.0f, 0.0f, 1.0f ) );
-
- ub.mvp = ortho( 0.0f, 640.0f, 480.0f, 0.0f, 0.0f, 100.0f ) *
- lookAt( vec3( 0.0f, 0.0f, 10.0f ), vec3( 0.0f, 0.0f, 0.0f ), vec3( 0.0f, 1.0f, 0.0f ) ) * modelMat;
-
- update_buffer( buffer, ub );
- */
-}
-
-Dali::Graphics::Vulkan::RefCountedBuffer create_uniform_buffer( Dali::Graphics::Vulkan::Graphics& gr )
-{
- // create uniform buffer
- auto uniformBuffer = Buffer::New( gr, sizeof( UniformData ), Buffer::Type::UNIFORM );
-
- // allocate memory
- auto memory = gr.GetDeviceMemoryManager()
- .GetDefaultAllocator()
- .Allocate( uniformBuffer,
- vk::MemoryPropertyFlagBits::eHostVisible );
-
- // bind memory
- uniformBuffer->BindMemory( memory );
-
- auto ub = gr.MapMemoryTyped< UniformData* >( memory );
-
- ub->mvp = mat4{ 1.0f } * ortho( 0.0f, 640.0f, 480.0f, 0.0f, 0.0f, 100.0f ) *
- lookAt( vec3( 0.0f, 0.0f, 10.0f ), vec3( 0.0f, 0.0f, 0.0f ), vec3( 0.0f, 1.0f, 0.0f ) );
- ub->color = vec4( 0.0f, 1.0f, 1.0f, 1.0f );
- ub->size = vec3( 1.0f, 1.0f, 1.0f );
-
- memory->Unmap();
-
- return uniformBuffer;
-}
-
-Dali::Graphics::Vulkan::RefCountedBuffer create_clip_buffer( Dali::Graphics::Vulkan::Graphics& gr )
-{
- const glm::mat4 clip(
- 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.5f, 1.0f );
-
- // create uniform buffer
- auto uniformBuffer = gr.CreateBuffer( sizeof( UniformClipData ), BufferType::UNIFORM );
-
- // allocate memory
- auto memory = gr.GetDeviceMemoryManager()
- .GetDefaultAllocator()
- .Allocate( uniformBuffer,
- vk::MemoryPropertyFlagBits::eHostVisible );
- // bind memory
- uniformBuffer->BindMemory( memory );
- auto dst = memory->MapTyped< mat4 >();
- std::copy( &clip, &clip + 1, dst );
- memory->Unmap();
- return uniformBuffer;
-}
-
-Dali::Graphics::Vulkan::Handle< DescriptorPool > create_descriptor_pool( Dali::Graphics::Vulkan::Graphics& gr )
-{
- vk::DescriptorPoolSize size;
- size.setDescriptorCount( 1024 )
- .setType( vk::DescriptorType::eUniformBuffer );
-
- // TODO: how to organize this???
- auto pool = DescriptorPool::New(
- gr, vk::DescriptorPoolCreateInfo{}.setMaxSets( 1024 )
- .setPoolSizeCount( 1 )
- .setPPoolSizes( &size ) );
- return pool;
-}
-
-void test_framebuffer( Dali::Graphics::Vulkan::Graphics& graphics )
-{
- using namespace Dali::Graphics::Vulkan;
- // framebuffer
- auto fb = NewRef< Framebuffer >( graphics, 640, 480 );
-
- // attachment
- auto image = NewRef< Image >( graphics,
- vk::ImageCreateInfo{}
- .setFormat( vk::Format::eR32G32B32A32Sfloat )
- .setTiling( vk::ImageTiling::eOptimal )
- .setMipLevels( 1 )
- .setImageType( vk::ImageType::e2D )
- .setExtent( vk::Extent3D( 640, 480, 1 ) )
- .setArrayLayers( 1 )
- .setUsage( vk::ImageUsageFlagBits::eSampled |
- vk::ImageUsageFlagBits::eColorAttachment )
- .setSharingMode( vk::SharingMode::eExclusive )
- .setInitialLayout( vk::ImageLayout::eUndefined )
- .setSamples( vk::SampleCountFlagBits::e1 ) );
-
- auto imageView = NewRef< ImageView >(
- graphics,
- image,
- vk::ImageViewCreateInfo{}
- .setFormat( vk::Format::eR32G32B32A32Sfloat )
- .setComponents( vk::ComponentMapping(
- vk::ComponentSwizzle::eR, vk::ComponentSwizzle::eG, vk::ComponentSwizzle::eB,
- vk::ComponentSwizzle::eA ) )
- .setImage( image->GetVkHandle() )
- .setSubresourceRange( vk::ImageSubresourceRange{}
- .setLayerCount( 1 )
- .setLevelCount( 1 )
- .setBaseMipLevel( 0 )
- .setBaseArrayLayer( 0 )
- .setAspectMask( vk::ImageAspectFlagBits::eColor ) )
- .setViewType( vk::ImageViewType::e2D ) );
-
- fb->SetAttachment( imageView, Framebuffer::AttachmentType::COLOR, 0u );
-
- //fb->GetRenderPass();
-
- //fb->SetAttachment( )
-}
-
-void test_handle()
-{
- /*
- using namespace Dali::Graphics::Vulkan;
- RefCountedGpuMemoryBlock handle( new GpuMemoryBlock() );
-
- decltype(handle) handle2 = handle;
- handle.GetRefCount();*/
-}
-
-RefCountedPipeline create_pipeline( Dali::Graphics::Vulkan::Graphics& graphics,
- Dali::Graphics::Vulkan::RefCountedShader vertexShader,
- Dali::Graphics::Vulkan::RefCountedShader fragmentShader )
-{
- using namespace Dali::Graphics::Vulkan;
- auto pipelineInfo = vk::GraphicsPipelineCreateInfo{};
- auto pipeline = Pipeline::New( graphics, pipelineInfo );
-
- pipeline->SetShader( vertexShader, Shader::Type::VERTEX );
- pipeline->SetShader( fragmentShader, Shader::Type::FRAGMENT );
- pipeline->SetViewport( 0, 0, 640, 480 );
- pipeline->SetVertexInputState(
- std::vector< vk::VertexInputAttributeDescription >{
- vk::VertexInputAttributeDescription{}.setBinding( 0 )
- .setOffset( 0 )
- .setLocation( 0 )
- .setFormat(
- vk::Format::eR32G32B32Sfloat ) },
- std::vector< vk::VertexInputBindingDescription >{ vk::VertexInputBindingDescription{}
- .setBinding( 0 )
- .setStride( sizeof( float ) * 3 )
- .setInputRate( vk::VertexInputRate::eVertex ) } );
- pipeline->SetInputAssemblyState( vk::PrimitiveTopology::eTriangleList, false );
-
- if( !pipeline->Compile() )
- {
- pipeline.Reset();
- }
- return pipeline;
-}
-
-int TextureTestMain( Dali::Graphics::Vulkan::Graphics& );
-
-int RunTestMain2()
-{
-#if USE_XLIB == 1
- auto window = Test::create_xlib_window( 640, 480 );
- auto surfaceFactory = std::unique_ptr<VkSurfaceXlib>{new VkSurfaceXlib{window->display, window->window}};
-#else
- auto window = Test::create_xcb_window( 640, 480 );
- auto surfaceFactory = std::unique_ptr< VkSurfaceXcb >{ new VkSurfaceXcb{ window->connection, window->window } };
-#endif
-
- auto graphics = MakeUnique< Graphics >();
- auto fbid = graphics->Create( std::move( surfaceFactory ) );
-
- // access internal implementation
- auto& gr = graphics->GetImplementation< Dali::Graphics::Vulkan::Graphics >();
-
- // GPU memory manager
- auto& memmgr = gr.GetDeviceMemoryManager();
-
- return TextureTestMain( gr );
-}
-
-int RunTestMain()
-{
-#if USE_XLIB == 1
- auto window = Test::create_xlib_window( 640, 480 );
- auto surfaceFactory = std::unique_ptr<VkSurfaceXlib>{new VkSurfaceXlib{window->display, window->window}};
-#else
- auto window = Test::create_xcb_window( 640, 480 );
- auto surfaceFactory = std::unique_ptr< VkSurfaceXcb >{ new VkSurfaceXcb{ window->connection, window->window } };
-#endif
-
- auto graphics = MakeUnique< Graphics >();
- auto fbid = graphics->Create( std::move( surfaceFactory ) );
-
- // access internal implementation
- auto& gr = graphics->GetImplementation< Dali::Graphics::Vulkan::Graphics >();
-
- // GPU memory manager
- auto& memmgr = gr.GetDeviceMemoryManager();
-
- const vec3 VERTICES[] = {
- { 0.0f, 0.0f, 0.0f },
- { 320.0f, 0.0f, 0.0f },
- { 0.0f, 160.0f, 0.0f },
- };
-
- // shaders
- auto vertexShader = Shader::New( gr, VSH_CODE.data(), VSH_CODE.size() );
-
- auto fragmentShader = Shader::New( gr, FSH_CODE.data(), FSH_CODE.size() );
-
- // buffer
- auto vertexBuffer = Buffer::New( gr, sizeof( float ) * 3 * 3, Buffer::Type::VERTEX );
-
- auto descriptorPool = create_descriptor_pool( gr );
-
- auto& gpuManager = gr.GetDeviceMemoryManager();
-
- auto bufferMemory = test_gpu_memory_manager( gr, gpuManager, vertexBuffer );
- vertexBuffer->BindMemory( bufferMemory );
-
- auto ptr = gr.MapMemoryTyped< uint8_t* >( bufferMemory );
- std::copy( reinterpret_cast<const uint8_t*>( VERTICES ),
- reinterpret_cast<const uint8_t*>( VERTICES ) + ( sizeof( float ) * 9 ),
- ptr );
- bufferMemory->Unmap();
-
- auto pipeline = create_pipeline( gr, vertexShader, fragmentShader );
-
- auto descriptorSet = descriptorPool->AllocateDescriptorSets(
- vk::DescriptorSetAllocateInfo{}
- .setPSetLayouts( pipeline->GetVkDescriptorSetLayouts()
- .data() )
- .setDescriptorSetCount( pipeline->GetVkDescriptorSetLayouts()
- .size() ) );
-
-
- auto commandPool = CommandPool::New( gr );
-
- auto uniformBuffer = create_uniform_buffer( gr );
-
- auto clipBuffer = create_clip_buffer( gr );
-
- descriptorSet[0]->WriteUniformBuffer( 0, uniformBuffer, 0, uniformBuffer->GetSize() );
- descriptorSet[0]->WriteUniformBuffer( 1, clipBuffer, 0, clipBuffer->GetSize() );
-
- // get new buffer
- auto cmdDraw = commandPool->NewCommandBuffer( false );
-
- // begin recording
- cmdDraw->Begin( vk::CommandBufferUsageFlagBits::eRenderPassContinue );
-
- // vertex buffer
- cmdDraw->BindVertexBuffer( 0, vertexBuffer, 0 );
-
- // pipeline
- cmdDraw->BindGraphicsPipeline( pipeline );
-
- // descriptor sets
- cmdDraw->BindDescriptorSets( descriptorSet, 0 );
-
- // do draw
- cmdDraw->Draw( 3, 1, 0, 0 );
-
- // finish
- cmdDraw->End();
-
- bool running = true;
-
- while( running )
- {
- graphics->PreRender( fbid );
- // queue submit draw
-
- auto cmdbuf = gr.GetSwapchainForFBID( fbid )
- ->GetCurrentCommandBuffer();
-
- // get command buffer for current frame and execute the draw call
- cmdbuf->ExecuteCommands( { cmdDraw } );
-
- graphics->PostRender( fbid );
-
- update_translation( uniformBuffer );
- }
- return 0;
-}
-
-void texture_test( void* data, size_t size )
-{
-
-}
-
-using namespace Dali::Graphics::Vulkan::SpirV;
-
-void spirv_test0( std::vector< SPIRVWord > code )
-{
- auto shader = SPIRVUtils::Parse( code, vk::ShaderStageFlagBits::eVertex );
- auto opcodeCount = shader->GetOpCodeCount();
- DEBUG_LOG_STREAMS( gVulkanFilter, Debug::General, "opcodecount" << opcodeCount );
-
- auto layoutCreateInfo = shader->GenerateDescriptorSetLayoutCreateInfo();
-
- DEBUG_LOG_STREAMS( gVulkanFilter, Debug::General, "yay!" );
-}
-
-void RunSPIRVTest()
-{
- std::vector< SPIRVWord > data;
- data.resize( VSH_CODE.size() / 4 );
- std::copy( VSH_CODE.begin(), VSH_CODE.end(), reinterpret_cast<decltype( VSH_CODE.data() )>(data.data()) );
- spirv_test0( data );
-}
-
-
-} // namespace VulkanTest
-
-int main()
-{
- VulkanTest::RunTestMain2();
-
- //VulkanTest::RunSPIRVTest();
-}
+++ /dev/null
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// INTERNAL INCLUDES
-#include <dali/graphics/vulkan/internal/vulkan-surface.h>
-#include <dali/graphics/vulkan/internal/vulkan-debug.h>
-#include <dali/graphics/vulkan/vulkan-graphics.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-
-Surface::Surface( Graphics& graphics )
-: mGraphics( &graphics )
-{
-}
-
-Surface::~Surface() = default;
-
-vk::SurfaceKHR Surface::GetVkHandle() const
-{
- return mSurface;
-}
-
-const vk::SurfaceCapabilitiesKHR& Surface::GetCapabilities() const
-{
- return mCapabilities;
-}
-
-void Surface::UpdateSize( unsigned int width, unsigned int height )
-{
- mCapabilities.currentExtent.width = width;
- mCapabilities.currentExtent.height = height;
-}
-
-bool Surface::OnDestroy()
-{
- if( mSurface )
- {
- auto instance = mGraphics->GetInstance();
- auto surface = mSurface;
- auto allocator = &mGraphics->GetAllocator();
-
- mGraphics->DiscardResource( [ instance, surface, allocator ]() {
- DALI_LOG_INFO( gVulkanFilter, Debug::General, "Invoking deleter function: surface->%p\n",
- static_cast< VkSurfaceKHR >( surface ) )
- instance.destroySurfaceKHR( surface, allocator );
- } );
-
- mSurface = nullptr;
- }
- return false;
-}
-
-} // namespace Vulkan
-} // namespace Graphics
-} // namespace Dali
+++ /dev/null
-#ifndef DALI_GRAPHICS_VULKAN_SURFACE
-#define DALI_GRAPHICS_VULKAN_SURFACE
-
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// INTERNAL INCLUDES
-#include <dali/graphics/vulkan/internal/vulkan-types.h>
-
-namespace Dali
-{
-
-// Forward declarations
-namespace Integration
-{
-
-namespace Graphics
-{
-
-class SurfaceFactory;
-
-namespace Vulkan
-{
-class VkSurfaceFactory;
-} // namespace Vulkan
-
-} // namespace Graphics
-
-} // namespace Integration
-
-namespace Graphics
-{
-namespace Vulkan
-{
-class Graphics;
-
-class Surface : public VkManaged
-{
- friend class Graphics;
-
-public:
-
- ~Surface() final;
-
- /**
- *
- * @return
- */
- vk::SurfaceKHR GetVkHandle() const;
-
- /**
- * Returns size of surface
- * @return
- */
- const vk::SurfaceCapabilitiesKHR& GetCapabilities() const;
-
- /**
- * Update size of surface
- */
- void UpdateSize( unsigned int width, unsigned int height );
-
- bool OnDestroy() override;
-
-private:
- Surface( Graphics& graphic );
-
-private:
- Graphics* mGraphics;
- vk::SurfaceKHR mSurface;
- vk::SurfaceCapabilitiesKHR mCapabilities;
-};
-
-} // namespace Vulkan
-} // namespace Graphics
-} // namespace Dali
-
-#endif // DALI_GRAPHICS_VULKAN_SURFACE
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// INTERNAL INCLUDES
-#include <dali/graphics/vulkan/vulkan-graphics.h>
-#include <dali/graphics/vulkan/internal/vulkan-command-buffer.h>
-#include <dali/graphics/vulkan/internal/vulkan-command-pool.h>
-#include <dali/graphics/vulkan/internal/vulkan-fence.h>
-#include <dali/graphics/vulkan/internal/vulkan-framebuffer.h>
-
-#include <dali/graphics/vulkan/internal/vulkan-image.h>
-#include <dali/graphics/vulkan/internal/vulkan-image-view.h>
-#include <dali/graphics/vulkan/internal/vulkan-queue.h>
-#include <dali/graphics/vulkan/internal/vulkan-surface.h>
-#include <dali/graphics/vulkan/internal/vulkan-swapchain.h>
-#include <dali/graphics/vulkan/internal/vulkan-debug.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-namespace
-{
-const auto MAX_SWAPCHAIN_RESOURCE_BUFFERS = 2u;
-}
-/**
- * SwapchainBuffer stores all per-buffer data
- */
-struct SwapchainBuffer
-{
- SwapchainBuffer( Graphics& _graphics );
-
- ~SwapchainBuffer();
-
- /**
- * Separate command buffer for each render pass (the final pass is for the swapchain fb)
- */
- std::vector<RefCountedCommandBuffer> commandBuffers;
-
- /**
- * Semaphore signalled on acquire next image
- */
- vk::Semaphore acquireNextImageSemaphore;
-
- /**
- * Semaphore signalled on complete commands submission
- */
- vk::Semaphore submitSemaphore;
-
- RefCountedFence betweenRenderPassFence;
- RefCountedFence endOfFrameFence;
-
- Graphics& graphics;
-};
-
-SwapchainBuffer::SwapchainBuffer(Graphics& _graphics)
-: graphics( _graphics )
-{
- acquireNextImageSemaphore = graphics.GetDevice().createSemaphore( {}, graphics.GetAllocator() ).value;
- submitSemaphore = graphics.GetDevice().createSemaphore( {}, graphics.GetAllocator() ).value;
-
- // Ensure there is at least 1 allocated primary command buffer
- commandBuffers.emplace_back( graphics.CreateCommandBuffer( true ) );
-
- betweenRenderPassFence = graphics.CreateFence({});
- endOfFrameFence = graphics.CreateFence({});
-}
-
-SwapchainBuffer::~SwapchainBuffer()
-{
- // swapchain dies so make sure semaphore are not in use anymore
- graphics.GetDevice().waitIdle();
- graphics.GetDevice().destroySemaphore( acquireNextImageSemaphore, graphics.GetAllocator() );
- graphics.GetDevice().destroySemaphore( submitSemaphore, graphics.GetAllocator() );
-}
-
-Swapchain::Swapchain( Graphics& graphics, Queue& presentationQueue,
- RefCountedSurface surface,
- std::vector< RefCountedFramebuffer >&& framebuffers,
- vk::SwapchainCreateInfoKHR createInfo,
- vk::SwapchainKHR vkHandle )
-: mGraphics( &graphics ),
- mQueue( &presentationQueue ),
- mSurface( std::move( surface ) ),
- mSwapchainImageIndex( 0u ),
- mSwapchainKHR( vkHandle ),
- mSwapchainCreateInfoKHR( std::move( createInfo ) ),
- mFramebuffers( std::move( framebuffers ) ),
- mIsValid( true )
-{
-}
-
-Swapchain::~Swapchain() = default;
-
-RefCountedFramebuffer Swapchain::GetCurrentFramebuffer() const
-{
- return GetFramebuffer( mSwapchainImageIndex );
-}
-
-RefCountedFramebuffer Swapchain::GetFramebuffer( uint32_t index ) const
-{
- return mFramebuffers[index];
-}
-
-RefCountedFramebuffer Swapchain::AcquireNextFramebuffer( bool shouldCollectGarbageNow )
-{
- // prevent from using invalid swapchain
- if( !mIsValid )
- {
- DALI_LOG_INFO( gVulkanFilter, Debug::General, "Attempt to present invalid/expired swapchain: %p\n", static_cast< VkSwapchainKHR >(mSwapchainKHR) );
- return RefCountedFramebuffer();
- }
-
- const auto& device = mGraphics->GetDevice();
-
- // on swapchain first create sync primitives and master command buffer
- // if not created yet
- if( mSwapchainBuffers.empty() )
- {
- mSwapchainBuffers.resize( MAX_SWAPCHAIN_RESOURCE_BUFFERS );
- for( auto& buffer : mSwapchainBuffers )
- {
- buffer.reset( new SwapchainBuffer( *mGraphics ) );
- }
- }
-
- DALI_LOG_INFO( gVulkanFilter, Debug::General, "Swapchain Image Index ( BEFORE Acquire ) = %d", int(mSwapchainImageIndex) );
- auto result = device.acquireNextImageKHR( mSwapchainKHR,
- std::numeric_limits<uint64_t>::max(),
- mSwapchainBuffers[mGraphics->GetCurrentBufferIndex()]->acquireNextImageSemaphore,
- nullptr, &mSwapchainImageIndex );
-
- DALI_LOG_INFO( gVulkanFilter, Debug::General, "Swapchain Image Index ( AFTER Acquire ) = %d", int(mSwapchainImageIndex) );
-
- // swapchain either not optimal or expired, returning nullptr and
- // setting validity to false
- if( result != vk::Result::eSuccess )
- {
- mIsValid = false;
- if ( result == vk::Result::eErrorOutOfDateKHR )
- {
- return RefCountedFramebuffer();
- }
- else
- {
- assert( mIsValid );
- }
- }
-
- // First frames don't need waiting as they haven't been submitted
- // yet. Note, that waiting on the fence without resetting it may
- // cause a stall ( nvidia, ubuntu )
- if( mFrameCounter >= mSwapchainBuffers.size() )
- {
- mGraphics->WaitForFence( mSwapchainBuffers[mGraphics->GetCurrentBufferIndex()]->endOfFrameFence );
- mGraphics->CollectGarbage();
- }
- else
- {
- mGraphics->DeviceWaitIdle();
- mGraphics->CollectGarbage();
- }
-
- return mFramebuffers[mSwapchainImageIndex];
-}
-
-void Swapchain::Present()
-{
- // prevent from using invalid swapchain
- if( !mIsValid )
- {
- DALI_LOG_INFO( gVulkanFilter, Debug::General, "Attempt to present invalid/expired swapchain: %p\n", static_cast< VkSwapchainKHR >(mSwapchainKHR) );
- return;
- }
-
- auto& swapBuffer = mSwapchainBuffers[mGraphics->GetCurrentBufferIndex()];
-
- // End any render pass command buffers
- size_t count = swapBuffer->commandBuffers.size();
- size_t index = 0;
- for( auto& commandBuffer : swapBuffer->commandBuffers )
- {
- // @todo Add semaphores between each render pass
- if( index < count-1 )
- {
- auto submissionData = SubmissionData{};
- submissionData.SetCommandBuffers( { commandBuffer } )
- .SetSignalSemaphores( { } )
- .SetWaitSemaphores( { } )
- .SetWaitDestinationStageMask( vk::PipelineStageFlagBits::eFragmentShader );
- mGraphics->Submit( *mQueue, { std::move( submissionData ) }, swapBuffer->betweenRenderPassFence );
-
- mGraphics->WaitForFence(swapBuffer->betweenRenderPassFence);
- mGraphics->ResetFence( swapBuffer->betweenRenderPassFence );
- }
- else // last frame
- {
- mGraphics->ResetFence( swapBuffer->endOfFrameFence );
-
- auto submissionData = SubmissionData{};
-
- submissionData.SetCommandBuffers( { commandBuffer } )
- .SetSignalSemaphores( { swapBuffer->submitSemaphore } )
- .SetWaitSemaphores( { swapBuffer->acquireNextImageSemaphore } )
- .SetWaitDestinationStageMask( vk::PipelineStageFlagBits::eFragmentShader );
- mGraphics->Submit( *mQueue, { std::move( submissionData ) }, swapBuffer->endOfFrameFence );
- }
-
- ++index;
- }
-
- vk::PresentInfoKHR presentInfo{};
- vk::Result result;
- presentInfo.setPImageIndices( &mSwapchainImageIndex )
- .setPResults( &result )
- .setPSwapchains( &mSwapchainKHR )
- .setSwapchainCount( 1 )
- .setPWaitSemaphores( &swapBuffer->submitSemaphore )
- .setWaitSemaphoreCount( 1 );
-
- mGraphics->Present( *mQueue, presentInfo );
-
- // handle error
- if( presentInfo.pResults[0] != vk::Result::eSuccess )
- {
- // invalidate swapchain
- if ( result == vk::Result::eErrorOutOfDateKHR )
- {
- mIsValid = false;
- }
- else
- {
- mIsValid = false;
- assert( mIsValid );
- }
- }
-
- mFrameCounter++;
-}
-
-void Swapchain::Present( std::vector< vk::Semaphore > waitSemaphores )
-{
- // prevent from using invalid swapchain
- if( !mIsValid )
- {
- DALI_LOG_INFO( gVulkanFilter, Debug::General, "Attempt to present invalid/expired swapchain: %p\n", static_cast< VkSwapchainKHR >(mSwapchainKHR) );
- return;
- }
-
- vk::PresentInfoKHR presentInfo{};
- vk::Result result{};
- presentInfo.setPImageIndices( &mSwapchainImageIndex )
- .setPResults( &result )
- .setPSwapchains( &mSwapchainKHR )
- .setSwapchainCount( 1 )
- .setPWaitSemaphores( nullptr )
- .setWaitSemaphoreCount( 0 );
-
- mGraphics->Present( *mQueue, presentInfo );
-}
-
-
-bool Swapchain::OnDestroy()
-{
- if( mSwapchainKHR )
- {
- auto graphics = mGraphics;
- auto device = graphics->GetDevice();
- auto swapchain = mSwapchainKHR;
- auto allocator = &graphics->GetAllocator();
-
- graphics->DiscardResource( [ device, swapchain, allocator ]() {
- DALI_LOG_INFO( gVulkanFilter, Debug::General, "Invoking deleter function: swap chain->%p\n",
- static_cast< VkSwapchainKHR >(swapchain) )
- device.destroySwapchainKHR( swapchain, allocator );
- } );
-
- mSwapchainKHR = nullptr;
- }
- return false;
-}
-
-vk::SwapchainKHR Swapchain::GetVkHandle()
-{
- return mSwapchainKHR;
-}
-
-bool Swapchain::IsValid() const
-{
- return mIsValid;
-}
-
-void Swapchain::Invalidate()
-{
- mIsValid = false;
-}
-
-void Swapchain::SetDepthStencil(vk::Format depthStencilFormat)
-{
- RefCountedFramebufferAttachment depthAttachment;
- auto swapchainExtent = mSwapchainCreateInfoKHR.imageExtent;
-
- if( depthStencilFormat != vk::Format::eUndefined )
- {
- // Create depth/stencil image
- auto imageCreateInfo = vk::ImageCreateInfo{}
- .setFormat( depthStencilFormat )
- .setMipLevels( 1 )
- .setTiling( vk::ImageTiling::eOptimal )
- .setImageType( vk::ImageType::e2D )
- .setArrayLayers( 1 )
- .setExtent( { swapchainExtent.width, swapchainExtent.height, 1 } )
- .setUsage( vk::ImageUsageFlagBits::eDepthStencilAttachment )
- .setSharingMode( vk::SharingMode::eExclusive )
- .setInitialLayout( vk::ImageLayout::eUndefined )
- .setSamples( vk::SampleCountFlagBits::e1 );
-
- auto dsRefCountedImage = mGraphics->CreateImage( imageCreateInfo );
-
- auto memory = mGraphics->AllocateMemory( dsRefCountedImage, vk::MemoryPropertyFlagBits::eDeviceLocal );
-
- mGraphics->BindImageMemory( dsRefCountedImage, std::move(memory), 0 );
-
- // create the depth stencil ImageView to be used within framebuffer
- auto depthStencilImageView = mGraphics->CreateImageView( dsRefCountedImage );
- auto depthClearValue = vk::ClearDepthStencilValue{}.setDepth( 0.0 )
- .setStencil( STENCIL_DEFAULT_CLEAR_VALUE );
-
- // A single depth attachment for the swapchain.
- depthAttachment = FramebufferAttachment::NewDepthAttachment( depthStencilImageView, depthClearValue );
- }
-
- // Get images
- auto images = VkAssert( mGraphics->GetDevice().getSwapchainImagesKHR( mSwapchainKHR ) );
-
- // allocate framebuffers
- auto framebuffers = std::vector< RefCountedFramebuffer >{};
- framebuffers.reserve( images.size() );
-
- auto clearColor = vk::ClearColorValue{}.setFloat32( { 0.0f, 0.0f, 0.0f, 1.0f } );
-
- for( auto&& image : images )
- {
-
- auto colorImageView = mGraphics->CreateImageView( mGraphics->CreateImageFromExternal( image, mSwapchainCreateInfoKHR.imageFormat, swapchainExtent ) );
-
- // A new color attachment for each framebuffer
- auto colorAttachment = FramebufferAttachment::NewColorAttachment( colorImageView,
- clearColor,
- true /* presentable */ );
-
- framebuffers.push_back( mGraphics->CreateFramebuffer( { colorAttachment },
- depthAttachment,
- swapchainExtent.width,
- swapchainExtent.height ) );
- }
-
- // Before replacing framebuffers in the swapchain, wait until all is done
- mGraphics->DeviceWaitIdle();
-
- mFramebuffers = std::move( framebuffers );
-}
-
-void Swapchain::ResetAllCommandBuffers()
-{
- for( auto& swapbuffer : mSwapchainBuffers )
- {
- for( auto& cmdbuffer : swapbuffer->commandBuffers )
- {
- cmdbuffer->Reset();
- }
- }
-}
-
-void Swapchain::AllocateCommandBuffers( size_t renderPassCount )
-{
- size_t commandBuffersCount = mSwapchainBuffers[mGraphics->GetCurrentBufferIndex()]->commandBuffers.size();
-
- DALI_LOG_STREAM( gVulkanFilter, Debug::General, "AllocateCommandBuffers: cbCount:" << commandBuffersCount
- << " renderPassCount: " << renderPassCount );
-
- if( commandBuffersCount < renderPassCount )
- {
- for( size_t index = commandBuffersCount; index < renderPassCount ; ++index )
- {
- // Create primary buffer for each render pass & begin recording
- auto commandBuffer = mGraphics->CreateCommandBuffer(true);
- mSwapchainBuffers[mGraphics->GetCurrentBufferIndex()]->commandBuffers.emplace_back( commandBuffer );
- }
- }
- else if( renderPassCount < commandBuffersCount )
- {
- mSwapchainBuffers[mGraphics->GetCurrentBufferIndex()]->commandBuffers.resize( renderPassCount );
- }
-}
-
-RefCountedCommandBuffer Swapchain::GetLastCommandBuffer()
-{
- if( mSwapchainBuffers[mGraphics->GetCurrentBufferIndex()]->commandBuffers.empty() )
- {
- AllocateCommandBuffers( 1 );
- }
- return mSwapchainBuffers[mGraphics->GetCurrentBufferIndex()]->commandBuffers.back();
-}
-
-std::vector<RefCountedCommandBuffer>& Swapchain::GetCommandBuffers() const
-{
- return mSwapchainBuffers[mGraphics->GetCurrentBufferIndex()]->commandBuffers;
-}
-
-uint32_t Swapchain::GetImageCount() const
-{
- return uint32_t(mFramebuffers.size());
-}
-
-} // namespace Vulkan
-} // namespace Graphics
-} // namespace Dali
+++ /dev/null
-#ifndef DALI_GRAPHICS_VULKAN_SWAPCHAIN_H
-#define DALI_GRAPHICS_VULKAN_SWAPCHAIN_H
-
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// INTERNAL INCLUDES
-#include <dali/graphics/vulkan/internal/vulkan-types.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-
-class Surface;
-class Queue;
-class SwapchainBuffer;
-
-/**
- * Creates swapchain for given surface and queue
- */
-class Swapchain : public VkManaged
-{
-
- friend class Graphics;
-
-public:
-
- ~Swapchain() override;
-
- Swapchain( const Swapchain& ) = delete;
-
- Swapchain& operator=( const Swapchain& ) = delete;
-
- /**
- * Allocate command buffers for each render pass.
- * @param[in] renderPassCount The number of render passes to allocate for (includes main renderpass)
- */
- void AllocateCommandBuffers( size_t renderPassCount );
-
- /**
- * Returns current framebuffer ( the one which is rendering to )
- * @return
- */
- RefCountedFramebuffer GetCurrentFramebuffer() const;
-
- /**
- * Returns any framebuffer from the queue
- * @param index
- * @return
- */
- RefCountedFramebuffer GetFramebuffer( uint32_t index ) const;
-
- /**
- * This function acquires next framebuffer
- * @todo we should rather use round robin method
- * @return
- */
- RefCountedFramebuffer AcquireNextFramebuffer( bool shouldCollectGarbageNow = true );
-
- /**
- * Return the primary command buffer associated with the swapchain
- */
- RefCountedCommandBuffer GetLastCommandBuffer();
-
- /**
- * Returns the primary command buffers associated with each render pass
- * being recorded
- * @return mutable vector of command buffers
- */
- std::vector<RefCountedCommandBuffer>& GetCommandBuffers() const;
-
- /**
- * Presents using default present queue, asynchronously
- */
- void Present();
-
- /**
- * Presents using default queue, synchronized with supplied semaphores
- * @param waitSemaphores
- */
- void Present( std::vector< vk::Semaphore > waitSemaphores );
-
- bool OnDestroy() override;
-
- vk::SwapchainKHR GetVkHandle();
-
- /**
- * Returns true when swapchain expired
- * @return
- */
- bool IsValid() const;
-
- void Invalidate();
-
- /**
- * Enables depth/stencil buffer for swapchain ( off by default )
- *
- * @param[in] depthStencilFormat valid depth/stencil pixel format
- */
- void SetDepthStencil( vk::Format depthStencilFormat );
-
- /**
- * Resets all existing command buffers for all swapchain images
- * To run it safe it must be sure the GPU is not using any of the
- * command buffers.
- */
- void ResetAllCommandBuffers();
-
- /**
- * Returns number of allocated swapchain images
- * @return Number of swapchain images
- */
- uint32_t GetImageCount() const;
-
-private:
-
- Swapchain( Graphics& graphics,
- Queue& presentationQueue,
- RefCountedSurface surface,
- std::vector< RefCountedFramebuffer >&& framebuffers,
- vk::SwapchainCreateInfoKHR createInfo,
- vk::SwapchainKHR vkHandle );
-
-private:
- Graphics* mGraphics;
- Queue* mQueue;
- RefCountedSurface mSurface;
-
- uint32_t mSwapchainImageIndex; ///< Swapchain image index returned by vkAcquireNextImageKHR
-
- vk::SwapchainKHR mSwapchainKHR;
- vk::SwapchainCreateInfoKHR mSwapchainCreateInfoKHR;
-
- /*
- * Framebuffer object associated with the buffer
- */
- std::vector<RefCountedFramebuffer> mFramebuffers;
-
- /**
- * Array of swapchain buffers
- */
- std::vector<std::unique_ptr<SwapchainBuffer>> mSwapchainBuffers;
-
- RefCountedFence mBetweenRenderPassFence;
-
- uint32_t mFrameCounter { 0u }; ///< Current frame number
-
- bool mIsValid; // indicates whether the swapchain is still valid or requires to be recreated
-};
-
-} // namespace Vulkan
-} // namespace Graphics
-} // namespace Dali
-#endif //DALI_GRAPHICS_VULKAN_SWAPCHAIN_H
+++ /dev/null
-#ifndef DALI_GRAPHICS_VULKAN_TYPES
-#define DALI_GRAPHICS_VULKAN_TYPES
-
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// EXTERNAL INCLUDES
-#include <atomic>
-#include <unordered_map>
-#include <memory>
-#include <bitset>
-
-#include <dali/integration-api/graphics/vulkan/vulkan-hpp-wrapper.h>
-
-namespace Dali
-{
-namespace Graphics
-{
-
-namespace
-{
-// Default value use to clear the stencil buffer
-constexpr auto STENCIL_DEFAULT_CLEAR_VALUE = 255u;
-}
-
-template< typename T, typename... Args >
-std::unique_ptr< T > MakeUnique( Args&& ... args )
-{
- return std::unique_ptr< T >( new T( std::forward< Args >( args )... ) );
-}
-
-namespace Vulkan
-{
-
-/**
- * Forward class declarations
- */
-class Graphics;
-
-class Surface;
-
-class Queue;
-
-/**
- * Unique pointers to Vulkan types
- */
-using UniqueQueue = std::unique_ptr< Queue >;
-
-/**
- * Reference wrappers
- */
-using QueueRef = std::reference_wrapper< Queue >;
-
-template< typename T >
-T VkAssert( const vk::ResultValue< T >& result, vk::Result expected = vk::Result::eSuccess )
-{
- assert( result.result == expected );
- return result.value;
-}
-
-inline vk::Result VkAssert( vk::Result result, vk::Result expected = vk::Result::eSuccess )
-{
- assert( result == expected );
- return result;
-}
-
-inline vk::Result VkTest( vk::Result result, vk::Result expected = vk::Result::eSuccess )
-{
- // todo: log if result different than expected?
- return result;
-}
-
-template< typename T >
-inline uint32_t U32( T value )
-{
- return static_cast< uint32_t >(value);
-}
-
-template <typename T>
-inline int32_t I32( T value )
-{
- return static_cast< int32_t >( value );
-}
-
-template <typename T>
-inline float F32( T value )
-{
- return static_cast< float >( value );
-}
-
-template <typename T>
-inline double F64( T value )
-{
- return static_cast< double >( value );
-}
-
-/**
- * Vulkan object handle
- * @tparam T
- */
-template< class T >
-class Handle
-{
-public:
-
- Handle();
-
- explicit Handle( T* object );
-
- Handle( const Handle& handle );
-
- Handle& operator=( const Handle& handle );
-
- Handle& operator=( Handle&& handle );
-
- Handle( Handle&& handle ) noexcept;
-
- ~Handle();
-
- operator bool() const;
-
- T* operator->() const
- {
- return mObject;
- }
-
- uint32_t GetRefCount() const
- {
- return mObject->GetRefCount();
- }
-
- T& operator*() const
- {
- return *mObject;
- }
-
- template< class K >
- Handle< K > StaticCast()
- {
- return Handle< K >( static_cast<K*>(mObject) );
- }
-
- template< class K >
- bool operator==( const Handle< K >& object ) const
- {
- return mObject == &*object;
- }
-
- template< class K >
- bool operator!=( const Handle< K >& object ) const
- {
- return !(mObject == &*object);
- }
-
- template< class K >
- Handle< K > DynamicCast();
-
- void Reset()
- {
- if( mObject )
- {
- mObject->Release();
- mObject = nullptr;
- }
- }
-
-private:
-
- T* mObject{ nullptr };
-};
-
-template< class K, class T >
-static Handle< K > VkTypeCast( const Handle< T >& inval )
-{
- return Handle< K >( static_cast<K*>(&*inval) );
-}
-
-template< class T >
-Handle< T >::Handle( T* object )
- : mObject( object )
-{
- if( mObject )
- {
- mObject->Retain();
- }
-}
-
-template< class T >
-Handle< T >::Handle()
- : mObject( nullptr )
-{
-}
-
-template< class T >
-Handle< T >::Handle( const Handle& handle )
-{
- mObject = handle.mObject;
- if( mObject )
- {
- mObject->Retain();
- }
-}
-
-template< class T >
-Handle< T >::Handle( Handle&& handle ) noexcept
-{
- mObject = handle.mObject;
- handle.mObject = nullptr;
-}
-
-template< class T >
-Handle< T >::operator bool() const
-{
- return mObject != nullptr;
-}
-
-template< class T >
-Handle< T >& Handle< T >::operator=( Handle&& handle )
-{
- if( mObject )
- {
- mObject->Release();
- }
- mObject = handle.mObject;
- handle.mObject = nullptr;
- return *this;
-}
-
-template< class T >
-Handle< T >& Handle< T >::operator=( const Handle< T >& handle )
-{
- mObject = handle.mObject;
- if( mObject )
- {
- mObject->Retain();
- }
- return *this;
-}
-
-template< class T >
-Handle< T >::~Handle()
-{
- if( mObject )
- {
- mObject->Release();
- }
-}
-
-template< class T >
-template< class K >
-Handle< K > Handle< T >::DynamicCast()
-{
- auto val = dynamic_cast<K*>(mObject);
- if( val )
- {
- return Handle< K >( val );
- }
- return Handle< K >();
-}
-
-template< typename T, typename... Args >
-Handle< T > MakeRef( Args&& ... args )
-{
- return Handle< T >( new T( std::forward< Args >( args )... ) );
-}
-
-template< typename T, typename... Args >
-Handle< T > NewRef( Args&& ... args )
-{
- return Handle< T >( T::New( std::forward< Args >( args )... ) );
-}
-
-
-class VkManaged
-{
-public:
-
- VkManaged() = default;
-
- virtual ~VkManaged() = default;
-
- void Release()
- {
- OnRelease( --mRefCount );
-
- if( mRefCount == 0 )
- {
- // orphaned
- if( !Destroy() )
- {
- delete this;
- }
- }
- }
-
- void Retain()
- {
- OnRetain( ++mRefCount );
- }
-
- uint32_t GetRefCount()
- {
- return mRefCount;
- }
-
- virtual bool Destroy()
- {
- return OnDestroy();
- }
-
- virtual void OnRetain( uint32_t refcount )
- {
- }
-
- virtual void OnRelease( uint32_t refcount )
- {
- }
-
- virtual bool OnDestroy()
- {
- return false;
- }
-
-private:
-
- std::atomic_uint mRefCount{ 0u };
-};
-
-using FBID = int32_t;
-
-enum class BufferType
-{
- VERTEX,
- INDEX,
- UNIFORM,
- SHADER_STORAGE
-};
-
-enum class Platform
-{
- UNDEFINED,
- XLIB,
- XCB,
- WAYLAND,
-};
-
-struct FormatInfo
-{
- bool packed { false };
- bool compressed { false };
- unsigned int paletteSizeInBits { 0u };
- unsigned int blockSizeInBits { 0u };
- unsigned int blockWidth { 0u };
- unsigned int blockHeight { 0u };
- unsigned int blockDepth { 0u };
-};
-
-enum class DescriptorType : size_t
-{
- STORAGE_IMAGE = 0,
- SAMPLER = 1,
- SAMPLED_IMAGE = 2,
- COMBINED_IMAGE_SAMPLER = 3,
- UNIFORM_TEXEL_BUFFER = 4,
- STORAGE_TEXEL_BUFFER = 5,
- UNIFORM_BUFFER = 6,
- STORAGE_BUFFER = 7,
- DYNAMIC_UNIFORM_BUFFER = 8,
- DYNAMIC_STORAGE_BUFFER = 9,
- INPUT_ATTACHMENT = 10,
- DESCRIPTOR_TYPE_COUNT = 11,
-};
-
-template< size_t valueSizeInBits, typename EnumT, size_t enumVariantCount >
-class TypeValueEncoder final
-{
-private: // Compile time constants
- static constexpr size_t bitsetSize = enumVariantCount + valueSizeInBits * enumVariantCount;
-
-public:
-
- TypeValueEncoder()
- {
- static_assert( std::is_same< size_t, UnderlyingEnumType >::value, "Enum class underlying type must be size_t." );
- }
-
- bool Contains( EnumT enumVariant ) const
- {
- return mMask.test( ToIntegral( enumVariant ) );
- }
-
- uint64_t GetValueFor( EnumT enumVariant ) const
- {
- return ( ( mMask >> ( enumVariantCount +
- ToIntegral( enumVariant ) * valueSizeInBits ) ) &
- std::bitset< bitsetSize >( std::bitset< valueSizeInBits >().flip().to_ulong() ) ).to_ulong();
- }
-
- TypeValueEncoder& EncodeValue( size_t count, EnumT type )
- {
- mMask.set( ToIntegral( type ) );
- EncodeCount( count, type );
-
- return *this;
- }
-
- std::vector< std::tuple< EnumT, uint64_t > > Decode() const
- {
- auto result = std::vector< std::tuple< EnumT, uint64_t > >{};
-
- for( auto i = 0u; i < enumVariantCount; ++i)
- {
- if( mMask.test( i ) )
- {
- auto castEnum = static_cast< EnumT >( i );
- auto value = GetValueFor( castEnum );
-
- result.emplace_back( castEnum, value );
- }
- }
-
- return result;
- };
-
-private: // Functions and aliases
-
- using UnderlyingEnumType = typename std::underlying_type< EnumT >::type;
-
- constexpr UnderlyingEnumType ToIntegral( EnumT descriptorType ) const
- {
- return static_cast< UnderlyingEnumType >( descriptorType );
- }
-
- void EncodeCount( size_t count, DescriptorType descriptorType )
- {
- assert(count <= std::bitset< valueSizeInBits >().flip().to_ulong()
- && "Cannot encode descriptor count. Maximum possible value exceeded.");
-
- mMask |= std::bitset< bitsetSize >( count ) << enumVariantCount
- + ToIntegral( descriptorType ) * valueSizeInBits;
- }
-
- template<size_t valueSizeInBits_, typename EnumT_, size_t enumVariantCount_>
- friend bool operator==(const TypeValueEncoder< valueSizeInBits_, EnumT_, enumVariantCount_ >& lhs,
- const TypeValueEncoder< valueSizeInBits_, EnumT_, enumVariantCount_ >& rhs);
-
- template<size_t valueSizeInBits_, typename EnumT_, size_t enumVariantCount_>
- friend bool operator!=(const TypeValueEncoder< valueSizeInBits_, EnumT_, enumVariantCount_ >& lhs,
- const TypeValueEncoder< valueSizeInBits_, EnumT_, enumVariantCount_ >& rhs);
-
- template<size_t valueSizeInBits_, typename EnumT_, size_t enumVariantCount_>
- friend std::ostream& operator<<( std::ostream& os,
- const TypeValueEncoder< valueSizeInBits_, EnumT_, enumVariantCount_ >& rhs );
-
-private: // Members
-
- std::bitset< bitsetSize > mMask;
-};
-
-template <size_t valueSizeInBits, typename EnumT, size_t enumVariantCount>
-bool operator==(const TypeValueEncoder< valueSizeInBits, EnumT, enumVariantCount >& lhs,
- const TypeValueEncoder< valueSizeInBits, EnumT, enumVariantCount >& rhs)
-{
- return lhs.mMask == rhs.mMask;
-}
-
-template <size_t valueSizeInBits, typename EnumT, size_t enumVariantCount>
-bool operator!=(const TypeValueEncoder< valueSizeInBits, EnumT, enumVariantCount >& lhs,
- const TypeValueEncoder< valueSizeInBits, EnumT, enumVariantCount >& rhs)
-{
- return lhs.mMask != rhs.mMask;
-}
-
-template<size_t valueSizeInBits, typename EnumT, size_t enumVariantCount>
-std::ostream& operator<<( std::ostream& os,
- const TypeValueEncoder< valueSizeInBits, EnumT, enumVariantCount >& rhs )
-{
- os << rhs.mMask.to_string();
- return os;
-}
-
-using DescriptorSetLayoutSignature =
-TypeValueEncoder< 4, DescriptorType, static_cast< size_t >( DescriptorType::DESCRIPTOR_TYPE_COUNT ) >;
-
-/*
- * Forward declarations of reference types
- */
-using RefCountedShader = Handle< class Shader >;
-using RefCountedPipeline = Handle< class Pipeline >;
-using RefCountedFence = Handle< class Fence >;
-using RefCountedBuffer = Handle< class Buffer >;
-using RefCountedFramebuffer = Handle< class Framebuffer >;
-using RefCountedImage = Handle< class Image >;
-using RefCountedImageView = Handle< class ImageView >;
-using RefCountedDescriptorPool = Handle< class DescriptorPool >;
-using RefCountedCommandPool = Handle< class CommandPool >;
-using RefCountedCommandBuffer = Handle< class CommandBuffer >;
-using RefCountedGpuMemoryBlock = Handle< class GpuMemoryBlock >;
-using RefCountedDescriptorSet = Handle< class DescriptorSet >;
-using RefCountedSwapchain = Handle< class Swapchain >;
-using RefCountedSurface = Handle< class Surface >;
-using RefCountedSampler = Handle< class Sampler >;
-using RefCountedTexture = Handle< class Texture >;
-using RefCountedFramebufferAttachment = Handle< class FramebufferAttachment >;
-
-} // namespace Vulkan
-} // namespace Graphics
-} // namespace Dali
-
-#endif // DALI_GRAPHICS_VULKAN_TYPES
+++ /dev/null
-#ifndef DALI_GRAPHICS_VULKAN_UTILS
-#define DALI_GRAPHICS_VULKAN_UTILS
-
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics/vulkan/internal/vulkan-types.h>
-
-namespace Dali
-{
-
-namespace Graphics
-{
-
-namespace Vulkan
-{
-
-// Returns Vulkan vk::Format details
-static inline constexpr FormatInfo GetFormatInfo(const vk::Format format)
-{
- auto formatSize = FormatInfo{};
- auto vkFormat = static_cast<VkFormat>(format);
- switch ( vkFormat )
- {
- case VK_FORMAT_R4G4_UNORM_PACK8:
- formatSize.packed = true;
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 1 * 8;
- formatSize.blockWidth = 1;
- formatSize.blockHeight = 1;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_R4G4B4A4_UNORM_PACK16:
- case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
- case VK_FORMAT_R5G6B5_UNORM_PACK16:
- case VK_FORMAT_B5G6R5_UNORM_PACK16:
- case VK_FORMAT_R5G5B5A1_UNORM_PACK16:
- case VK_FORMAT_B5G5R5A1_UNORM_PACK16:
- case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
- formatSize.packed = true;
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 2 * 8;
- formatSize.blockWidth = 1;
- formatSize.blockHeight = 1;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_R8_UNORM:
- case VK_FORMAT_R8_SNORM:
- case VK_FORMAT_R8_USCALED:
- case VK_FORMAT_R8_SSCALED:
- case VK_FORMAT_R8_UINT:
- case VK_FORMAT_R8_SINT:
- case VK_FORMAT_R8_SRGB:
- formatSize.packed = false;
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 1 * 8;
- formatSize.blockWidth = 1;
- formatSize.blockHeight = 1;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_R8G8_UNORM:
- case VK_FORMAT_R8G8_SNORM:
- case VK_FORMAT_R8G8_USCALED:
- case VK_FORMAT_R8G8_SSCALED:
- case VK_FORMAT_R8G8_UINT:
- case VK_FORMAT_R8G8_SINT:
- case VK_FORMAT_R8G8_SRGB:
- formatSize.packed = false;
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 2 * 8;
- formatSize.blockWidth = 1;
- formatSize.blockHeight = 1;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_R8G8B8_UNORM:
- case VK_FORMAT_R8G8B8_SNORM:
- case VK_FORMAT_R8G8B8_USCALED:
- case VK_FORMAT_R8G8B8_SSCALED:
- case VK_FORMAT_R8G8B8_UINT:
- case VK_FORMAT_R8G8B8_SINT:
- case VK_FORMAT_R8G8B8_SRGB:
- case VK_FORMAT_B8G8R8_UNORM:
- case VK_FORMAT_B8G8R8_SNORM:
- case VK_FORMAT_B8G8R8_USCALED:
- case VK_FORMAT_B8G8R8_SSCALED:
- case VK_FORMAT_B8G8R8_UINT:
- case VK_FORMAT_B8G8R8_SINT:
- case VK_FORMAT_B8G8R8_SRGB:
- formatSize.packed = false;
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 3 * 8;
- formatSize.blockWidth = 1;
- formatSize.blockHeight = 1;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_R8G8B8A8_UNORM:
- case VK_FORMAT_R8G8B8A8_SNORM:
- case VK_FORMAT_R8G8B8A8_USCALED:
- case VK_FORMAT_R8G8B8A8_SSCALED:
- case VK_FORMAT_R8G8B8A8_UINT:
- case VK_FORMAT_R8G8B8A8_SINT:
- case VK_FORMAT_R8G8B8A8_SRGB:
- case VK_FORMAT_B8G8R8A8_UNORM:
- case VK_FORMAT_B8G8R8A8_SNORM:
- case VK_FORMAT_B8G8R8A8_USCALED:
- case VK_FORMAT_B8G8R8A8_SSCALED:
- case VK_FORMAT_B8G8R8A8_UINT:
- case VK_FORMAT_B8G8R8A8_SINT:
- case VK_FORMAT_B8G8R8A8_SRGB:
- formatSize.packed = false;
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 4 * 8;
- formatSize.blockWidth = 1;
- formatSize.blockHeight = 1;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
- case VK_FORMAT_A8B8G8R8_SNORM_PACK32:
- case VK_FORMAT_A8B8G8R8_USCALED_PACK32:
- case VK_FORMAT_A8B8G8R8_SSCALED_PACK32:
- case VK_FORMAT_A8B8G8R8_UINT_PACK32:
- case VK_FORMAT_A8B8G8R8_SINT_PACK32:
- case VK_FORMAT_A8B8G8R8_SRGB_PACK32:
- formatSize.packed = true;
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 4 * 8;
- formatSize.blockWidth = 1;
- formatSize.blockHeight = 1;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
- case VK_FORMAT_A2R10G10B10_SNORM_PACK32:
- case VK_FORMAT_A2R10G10B10_USCALED_PACK32:
- case VK_FORMAT_A2R10G10B10_SSCALED_PACK32:
- case VK_FORMAT_A2R10G10B10_UINT_PACK32:
- case VK_FORMAT_A2R10G10B10_SINT_PACK32:
- case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
- case VK_FORMAT_A2B10G10R10_SNORM_PACK32:
- case VK_FORMAT_A2B10G10R10_USCALED_PACK32:
- case VK_FORMAT_A2B10G10R10_SSCALED_PACK32:
- case VK_FORMAT_A2B10G10R10_UINT_PACK32:
- case VK_FORMAT_A2B10G10R10_SINT_PACK32:
- formatSize.packed = true;
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 4 * 8;
- formatSize.blockWidth = 1;
- formatSize.blockHeight = 1;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_R16_UNORM:
- case VK_FORMAT_R16_SNORM:
- case VK_FORMAT_R16_USCALED:
- case VK_FORMAT_R16_SSCALED:
- case VK_FORMAT_R16_UINT:
- case VK_FORMAT_R16_SINT:
- case VK_FORMAT_R16_SFLOAT:
- formatSize.packed = false;
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 2 * 8;
- formatSize.blockWidth = 1;
- formatSize.blockHeight = 1;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_R16G16_UNORM:
- case VK_FORMAT_R16G16_SNORM:
- case VK_FORMAT_R16G16_USCALED:
- case VK_FORMAT_R16G16_SSCALED:
- case VK_FORMAT_R16G16_UINT:
- case VK_FORMAT_R16G16_SINT:
- case VK_FORMAT_R16G16_SFLOAT:
- formatSize.packed = false;
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 4 * 8;
- formatSize.blockWidth = 1;
- formatSize.blockHeight = 1;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_R16G16B16_UNORM:
- case VK_FORMAT_R16G16B16_SNORM:
- case VK_FORMAT_R16G16B16_USCALED:
- case VK_FORMAT_R16G16B16_SSCALED:
- case VK_FORMAT_R16G16B16_UINT:
- case VK_FORMAT_R16G16B16_SINT:
- case VK_FORMAT_R16G16B16_SFLOAT:
- formatSize.packed = false;
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 6 * 8;
- formatSize.blockWidth = 1;
- formatSize.blockHeight = 1;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_R16G16B16A16_UNORM:
- case VK_FORMAT_R16G16B16A16_SNORM:
- case VK_FORMAT_R16G16B16A16_USCALED:
- case VK_FORMAT_R16G16B16A16_SSCALED:
- case VK_FORMAT_R16G16B16A16_UINT:
- case VK_FORMAT_R16G16B16A16_SINT:
- case VK_FORMAT_R16G16B16A16_SFLOAT:
- formatSize.packed = false;
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 8 * 8;
- formatSize.blockWidth = 1;
- formatSize.blockHeight = 1;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_R32_UINT:
- case VK_FORMAT_R32_SINT:
- case VK_FORMAT_R32_SFLOAT:
- formatSize.packed = false;
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 4 * 8;
- formatSize.blockWidth = 1;
- formatSize.blockHeight = 1;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_R32G32_UINT:
- case VK_FORMAT_R32G32_SINT:
- case VK_FORMAT_R32G32_SFLOAT:
- formatSize.packed = false;
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 8 * 8;
- formatSize.blockWidth = 1;
- formatSize.blockHeight = 1;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_R32G32B32_UINT:
- case VK_FORMAT_R32G32B32_SINT:
- case VK_FORMAT_R32G32B32_SFLOAT:
- formatSize.packed = false;
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 12 * 8;
- formatSize.blockWidth = 1;
- formatSize.blockHeight = 1;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_R32G32B32A32_UINT:
- case VK_FORMAT_R32G32B32A32_SINT:
- case VK_FORMAT_R32G32B32A32_SFLOAT:
- formatSize.packed = false;
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 16 * 8;
- formatSize.blockWidth = 1;
- formatSize.blockHeight = 1;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_R64_UINT:
- case VK_FORMAT_R64_SINT:
- case VK_FORMAT_R64_SFLOAT:
- formatSize.packed = false;
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 8 * 8;
- formatSize.blockWidth = 1;
- formatSize.blockHeight = 1;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_R64G64_UINT:
- case VK_FORMAT_R64G64_SINT:
- case VK_FORMAT_R64G64_SFLOAT:
- formatSize.packed = false;
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 16 * 8;
- formatSize.blockWidth = 1;
- formatSize.blockHeight = 1;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_R64G64B64_UINT:
- case VK_FORMAT_R64G64B64_SINT:
- case VK_FORMAT_R64G64B64_SFLOAT:
- formatSize.packed = false;
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 24 * 8;
- formatSize.blockWidth = 1;
- formatSize.blockHeight = 1;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_R64G64B64A64_UINT:
- case VK_FORMAT_R64G64B64A64_SINT:
- case VK_FORMAT_R64G64B64A64_SFLOAT:
- formatSize.packed = false;
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 32 * 8;
- formatSize.blockWidth = 1;
- formatSize.blockHeight = 1;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
- case VK_FORMAT_E5B9G9R9_UFLOAT_PACK32:
- formatSize.packed = true;
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 4 * 8;
- formatSize.blockWidth = 1;
- formatSize.blockHeight = 1;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_D16_UNORM:
- formatSize.packed = true;
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 2 * 8;
- formatSize.blockWidth = 1;
- formatSize.blockHeight = 1;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_X8_D24_UNORM_PACK32:
- formatSize.packed = true;
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 4 * 8;
- formatSize.blockWidth = 1;
- formatSize.blockHeight = 1;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_D32_SFLOAT:
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 4 * 8;
- formatSize.blockWidth = 1;
- formatSize.blockHeight = 1;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_S8_UINT:
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 1 * 8;
- formatSize.blockWidth = 1;
- formatSize.blockHeight = 1;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_D16_UNORM_S8_UINT:
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 3 * 8;
- formatSize.blockWidth = 1;
- formatSize.blockHeight = 1;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_D24_UNORM_S8_UINT:
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 4 * 8;
- formatSize.blockWidth = 1;
- formatSize.blockHeight = 1;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_D32_SFLOAT_S8_UINT:
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 8 * 8;
- formatSize.blockWidth = 1;
- formatSize.blockHeight = 1;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_BC1_RGB_UNORM_BLOCK:
- case VK_FORMAT_BC1_RGB_SRGB_BLOCK:
- case VK_FORMAT_BC1_RGBA_UNORM_BLOCK:
- case VK_FORMAT_BC1_RGBA_SRGB_BLOCK:
- formatSize.compressed = true;
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 8 * 8;
- formatSize.blockWidth = 4;
- formatSize.blockHeight = 4;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_BC2_UNORM_BLOCK:
- case VK_FORMAT_BC2_SRGB_BLOCK:
- case VK_FORMAT_BC3_UNORM_BLOCK:
- case VK_FORMAT_BC3_SRGB_BLOCK:
- case VK_FORMAT_BC4_UNORM_BLOCK:
- case VK_FORMAT_BC4_SNORM_BLOCK:
- case VK_FORMAT_BC5_UNORM_BLOCK:
- case VK_FORMAT_BC5_SNORM_BLOCK:
- case VK_FORMAT_BC6H_UFLOAT_BLOCK:
- case VK_FORMAT_BC6H_SFLOAT_BLOCK:
- case VK_FORMAT_BC7_UNORM_BLOCK:
- case VK_FORMAT_BC7_SRGB_BLOCK:
- formatSize.compressed = true;
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 16 * 8;
- formatSize.blockWidth = 4;
- formatSize.blockHeight = 4;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
- case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:
- case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK:
- case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:
- formatSize.compressed = true;
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 8 * 8;
- formatSize.blockWidth = 4;
- formatSize.blockHeight = 4;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK:
- case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK:
- case VK_FORMAT_EAC_R11_UNORM_BLOCK:
- case VK_FORMAT_EAC_R11_SNORM_BLOCK:
- case VK_FORMAT_EAC_R11G11_UNORM_BLOCK:
- case VK_FORMAT_EAC_R11G11_SNORM_BLOCK:
- formatSize.compressed = true;
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 16 * 8;
- formatSize.blockWidth = 4;
- formatSize.blockHeight = 4;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_ASTC_4x4_UNORM_BLOCK:
- case VK_FORMAT_ASTC_4x4_SRGB_BLOCK:
- formatSize.compressed = true;
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 16 * 8;
- formatSize.blockWidth = 4;
- formatSize.blockHeight = 4;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_ASTC_5x4_UNORM_BLOCK:
- case VK_FORMAT_ASTC_5x4_SRGB_BLOCK:
- formatSize.compressed = true;
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 16 * 8;
- formatSize.blockWidth = 5;
- formatSize.blockHeight = 4;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_ASTC_5x5_UNORM_BLOCK:
- case VK_FORMAT_ASTC_5x5_SRGB_BLOCK:
- formatSize.compressed = true;
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 16 * 8;
- formatSize.blockWidth = 5;
- formatSize.blockHeight = 5;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_ASTC_6x5_UNORM_BLOCK:
- case VK_FORMAT_ASTC_6x5_SRGB_BLOCK:
- formatSize.compressed = true;
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 16 * 8;
- formatSize.blockWidth = 6;
- formatSize.blockHeight = 5;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_ASTC_6x6_UNORM_BLOCK:
- case VK_FORMAT_ASTC_6x6_SRGB_BLOCK:
- formatSize.compressed = true;
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 16 * 8;
- formatSize.blockWidth = 6;
- formatSize.blockHeight = 6;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_ASTC_8x5_UNORM_BLOCK:
- case VK_FORMAT_ASTC_8x5_SRGB_BLOCK:
- formatSize.compressed = true;
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 16 * 8;
- formatSize.blockWidth = 8;
- formatSize.blockHeight = 5;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_ASTC_8x6_UNORM_BLOCK:
- case VK_FORMAT_ASTC_8x6_SRGB_BLOCK:
- formatSize.compressed = true;
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 16 * 8;
- formatSize.blockWidth = 8;
- formatSize.blockHeight = 6;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_ASTC_8x8_UNORM_BLOCK:
- case VK_FORMAT_ASTC_8x8_SRGB_BLOCK:
- formatSize.compressed = true;
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 16 * 8;
- formatSize.blockWidth = 8;
- formatSize.blockHeight = 8;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_ASTC_10x5_UNORM_BLOCK:
- case VK_FORMAT_ASTC_10x5_SRGB_BLOCK:
- formatSize.compressed = true;
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 16 * 8;
- formatSize.blockWidth = 10;
- formatSize.blockHeight = 5;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_ASTC_10x6_UNORM_BLOCK:
- case VK_FORMAT_ASTC_10x6_SRGB_BLOCK:
- formatSize.compressed = true;
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 16 * 8;
- formatSize.blockWidth = 10;
- formatSize.blockHeight = 6;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_ASTC_10x8_UNORM_BLOCK:
- case VK_FORMAT_ASTC_10x8_SRGB_BLOCK:
- formatSize.compressed = true;
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 16 * 8;
- formatSize.blockWidth = 10;
- formatSize.blockHeight = 8;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_ASTC_10x10_UNORM_BLOCK:
- case VK_FORMAT_ASTC_10x10_SRGB_BLOCK:
- formatSize.compressed = true;
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 16 * 8;
- formatSize.blockWidth = 10;
- formatSize.blockHeight = 10;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_ASTC_12x10_UNORM_BLOCK:
- case VK_FORMAT_ASTC_12x10_SRGB_BLOCK:
- formatSize.compressed = true;
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 16 * 8;
- formatSize.blockWidth = 12;
- formatSize.blockHeight = 10;
- formatSize.blockDepth = 1;
- break;
- case VK_FORMAT_ASTC_12x12_UNORM_BLOCK:
- case VK_FORMAT_ASTC_12x12_SRGB_BLOCK:
- formatSize.compressed = true;
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 16 * 8;
- formatSize.blockWidth = 12;
- formatSize.blockHeight = 12;
- formatSize.blockDepth = 1;
- break;
- default:
- formatSize.paletteSizeInBits = 0;
- formatSize.blockSizeInBits = 0 * 8;
- formatSize.blockWidth = 1;
- formatSize.blockHeight = 1;
- formatSize.blockDepth = 1;
- break;
- }
-
- return formatSize;
-}
-
-} // Namespace Vulkan
-
-} // Namespace Graphics
-
-} // Napespace Dali
-
-#endif // DALI_GRAPHICS_VULKAN_UTILS
+++ /dev/null
-#!/bin/bash
-
-if [ ! -e 'dali-core' ] ; then
-
- echo "Error: This script must be executed from the top-level directory where dali-core can be found!"
- exit 0
-
-fi
-
-d=dali-core/dali/graphics/vulkan/shaders
-outdir=dali-core/dali/graphics/vulkan/generated
-
-cd $d
-all_shaders=$(ls -1 *.{vert,frag})
-cd $OLDPWD
-
-for name in $all_shaders ; do
- echo "Compiling $name..."
- varname=$(echo "SHADER_$name" | tr [a-z] [A-Z] | sed -e 's/-/_/g;s/\./_/g;')
- glslangValidator -V1.0 $d/$name --vn $varname -o /tmp/spv.h
-
- newname=$(echo ${name} | sed -e 's/\./-/;')".h"
- echo Writing $newname
-
- cat /tmp/spv.h | sed -e 's/const uint32_t /std::vector<uint32_t> /g;s/\[\]//g;' | tail -n +3 > $outdir/$newname
- echo >> $outdir/$newname
-done
-
-echo "Generating cpp file..."
-echo "#include <cstdint>" > $outdir/builtin-shader-gen.cpp
-echo "#include <vector>" >> $outdir/builtin-shader-gen.cpp
-echo "#include <string>" >> $outdir/builtin-shader-gen.cpp
-echo -e "#include <map>\n" >> $outdir/builtin-shader-gen.cpp
-
-varnames=
-for name in $all_shaders ; do
- varname=$(echo "SHADER_$name" | tr [a-z] [A-Z] | sed -e 's/-/_/g;s/\./_/g;')
- newname=$(echo ${name} | sed -e 's/\./-/;')".h"
- varnames="${varnames} $varname"
- echo "#include \"$newname\"" >> $outdir/builtin-shader-gen.cpp
-done
-
-echo "static std::map<std::string, std::vector<uint32_t>> gGraphicsBuiltinShader = {" >> $outdir/builtin-shader-gen.cpp
-for var in ${varnames} ; do
- echo " { \"$var\", $var }," >> $outdir/builtin-shader-gen.cpp
-done
-echo -e "};\n" >> $outdir/builtin-shader-gen.cpp
-
-# generate graphics shader getter function
-cat >> $outdir/builtin-shader-gen.cpp << EOF
-extern "C" {
-
-#define IMPORT_API __attribute__ ((visibility ("default")))
-
-IMPORT_API std::vector<uint32_t> GraphicsGetBuiltinShader( const std::string& tag );
-
-std::vector<uint32_t> GraphicsGetBuiltinShader( const std::string& tag )
-{
- auto iter = gGraphicsBuiltinShader.find( tag );
- if( iter != gGraphicsBuiltinShader.end() )
- {
- return iter->second;
- }
- return {};
-}
-
-}
-EOF
-
-echo "Generating extern header file ( for external use )..."
-echo "#ifndef GRAPHICS_BUILTIN_SHADER_EXTERN_GEN_H" > $outdir/builtin-shader-extern-gen.h
-echo "#define GRAPHICS_BUILTIN_SHADER_EXTERN_GEN_H" >> $outdir/builtin-shader-extern-gen.h
-echo "#include <cstdint>" >> $outdir/builtin-shader-extern-gen.h
-echo "#include <vector>" >> $outdir/builtin-shader-extern-gen.h
-echo "#include <string>" >> $outdir/builtin-shader-extern-gen.h
-echo "" >> $outdir/builtin-shader-extern-gen.h
-
-for name in $all_shaders ; do
- varname=$(echo "SHADER_$name" | tr [a-z] [A-Z] | sed -e 's/-/_/g;s/\./_/g;')
- newname=$(echo ${name} | sed -e 's/\./-/;')".h"
- echo "extern std::vector<uint32_t> $varname;" >> $outdir/builtin-shader-extern-gen.h
-done
-cat >> $outdir/builtin-shader-extern-gen.h << EOF
-extern "C" std::vector<uint32_t> GraphicsGetBuiltinShader( const std::string& tag );
-#define GraphicsGetBuiltinShaderId( x ) GraphicsGetBuiltinShader( #x )
-EOF
-echo "#endif // GRAPHICS_BUILTIN_SHADER_EXTERN_GEN_H" >> $outdir/builtin-shader-extern-gen.h
\ No newline at end of file
+++ /dev/null
-#include <string>
-#include <vector>
-#include <vulkan/vulkan.hpp>
-
-#include <dali/graphics/vulkan/internal/vulkan-buffer.h>
-#include <dali/graphics/vulkan/internal/vulkan-command-buffer.h>
-#include <dali/graphics/vulkan/internal/vulkan-command-pool.h>
-#include <dali/graphics/vulkan/vulkan-graphics.h>
-#include <dali/graphics/vulkan/internal/vulkan-image.h>
-#include <dali/graphics/vulkan/internal/vulkan-fence.h>
-#include <dali/graphics/vulkan/internal/vulkan-queue.h>
-
-
-namespace VulkanTest
-{
-using namespace Dali::Graphics::Vulkan;
-
-struct Pixel
-{
- Pixel() = default;
-
- explicit Pixel( uint32_t _color )
- : color( _color )
- {
- }
-
- explicit Pixel( uint8_t _r, uint8_t _g, uint8_t _b, uint8_t _a )
- {
- r = _r;
- g = _g;
- b = _b;
- a = _a;
- }
-
- union
- {
- uint32_t color;
- struct
- {
- uint8_t r, g, b, a;
- };
- };
-};
-
-struct Pixmap
-{
- explicit Pixmap( std::vector< Pixel > _data, uint32_t _width, uint32_t _height ) :
- data( std::move( _data ) ),
- width( _width ),
- height( _height ),
- bytesPerPixel( 4 ),
- pixelFormat( vk::Format::eR8G8B8A8Unorm )
- {
- }
-
- std::vector< Pixel > data;
- uint32_t width;
- uint32_t height;
- uint32_t bytesPerPixel;
- vk::Format pixelFormat;
-};
-
-struct Texture
-{
- Texture( Graphics& graphics, Pixmap pixmap ) : mGraphics( graphics ), mPixmap( std::move( pixmap ) )
- {
- }
-
- bool Initialise()
- {
- // create image
- auto imageCreateInfo = vk::ImageCreateInfo{}
- .setFormat( mPixmap.pixelFormat )
- .setInitialLayout( vk::ImageLayout::ePreinitialized )
- .setSamples( vk::SampleCountFlagBits::e1 )
- .setSharingMode( vk::SharingMode::eExclusive )
- .setUsage( vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eTransferDst )
- .setExtent( { mPixmap.width, mPixmap.height, 1 } )
- .setArrayLayers( 1 )
- .setImageType( vk::ImageType::e2D )
- .setTiling( vk::ImageTiling::eOptimal )
- .setMipLevels( 1 );
-
- mImage = mGraphics.CreateImage( imageCreateInfo );
-
- auto& allocator = mGraphics
- .GetDeviceMemoryManager()
- .GetDefaultAllocator();
-
- mGraphics.BindImageMemory( mImage, allocator.Allocate( mImage, vk::MemoryPropertyFlagBits::eDeviceLocal ), 0 );
-
- // create transient buffer to copy data
- auto size = mPixmap.data.size() * sizeof( mPixmap.data[0] );
- auto buffer = Buffer::New( mGraphics,
- vk::BufferCreateInfo{}
- .setUsage( vk::BufferUsageFlagBits::eTransferSrc )
- .setSharingMode( vk::SharingMode::eExclusive )
- .setSize( size ) );
-
- buffer->BindMemory( allocator.Allocate( buffer, vk::MemoryPropertyFlagBits::eHostVisible ) );
-
- // copy pixels to the buffer
- auto ptr = buffer->GetMemoryHandle()->MapTyped< Pixel >();
- std::copy( mPixmap.data.begin(), mPixmap.data.end(), ptr );
- buffer->GetMemoryHandle()->Unmap();
-
- // record copy and layout change
- auto copy = vk::BufferImageCopy{}.setImageExtent( { mPixmap.width, mPixmap.height, 1 } )
- .setBufferImageHeight( mPixmap.height )
- .setBufferOffset( 0 )
- .setBufferRowLength( mPixmap.width )
- .setImageOffset( { 0, 0, 0 } )
- .setImageSubresource(
- vk::ImageSubresourceLayers{}
- .setMipLevel( 0 )
- .setAspectMask( vk::ImageAspectFlagBits::eColor )
- .setLayerCount( 1 )
- .setBaseArrayLayer( 0 )
- );
- mCommandPool = CommandPool::New( mGraphics );
- mCommandBuffer = mCommandPool->NewCommandBuffer( true );
- mCommandBuffer->Begin( vk::CommandBufferUsageFlagBits::eOneTimeSubmit );
-
- // change layout
- auto barrier = std::vector< vk::ImageMemoryBarrier >{
- mGraphics.CreateImageMemoryBarrier( mImage,
- vk::ImageLayout::ePreinitialized,
- vk::ImageLayout::eTransferDstOptimal )
- };
-
- // change layout to prepare image to transfer data
- mCommandBuffer->PipelineBarrier( vk::PipelineStageFlagBits::eTopOfPipe, vk::PipelineStageFlagBits::eTransfer,
- {}, {}, {}, { barrier } );
-
- // copy image
- mCommandBuffer->CopyBufferToImage( buffer, mImage, vk::ImageLayout::eTransferDstOptimal, { copy } );
-
- // change layout to shader read-only optimal
- mCommandBuffer->PipelineBarrier( vk::PipelineStageFlagBits::eVertexShader, vk::PipelineStageFlagBits::eVertexShader,
- {}, {}, {}, {
- mGraphics.CreateImageMemoryBarrier( mImage,
- vk::ImageLayout::eTransferDstOptimal,
- vk::ImageLayout::eShaderReadOnlyOptimal )
- } );
-
- mCommandBuffer->End();
-
- // submit and wait till image is uploaded so temporary buffer can be destroyed safely
- auto fence = mGraphics.CreateFence( {} );
-
- auto submissionData = SubmissionData{}.SetCommandBuffers( { mCommandBuffer } );
- mGraphics.Submit( mGraphics.GetGraphicsQueue( 0u ), { submissionData }, fence );
- mGraphics.WaitForFence( fence );
-
- }
-
- Graphics& mGraphics;
- RefCountedImage mImage;
- RefCountedImageView mImageView;
-
- RefCountedCommandPool mCommandPool;
- RefCountedCommandBuffer mCommandBuffer; // primary buffer, executed independent
-
- // layouts
- vk::ImageLayout mOldLayout{ vk::ImageLayout{} };
- vk::ImageLayout mNewLayout{ vk::ImageLayout{} };
-
- // Command pool
-
-
- Pixmap mPixmap;
-};
-
-/**
- * Generates a random pixmap
- * @param width
- * @param height
- * @return
- */
-Pixmap GenerateTexture32BPPRGBA( uint32_t width, uint32_t height )
-{
- std::vector< Pixel > data;
- data.resize( width * height );
-
- const Pixel WHITE{ 0xffffffff };
- const Pixel BLACK{ 0x000000ff };
- const Pixel RED{ 0xff0000ff };
- const Pixel GREEN{ 0x00ff00ff };
- const Pixel BLUE{ 0x0000ffff };
-
- const Pixel COLORS[] = { WHITE, BLACK, RED, GREEN, BLUE };
- const auto COLORS_COUNT = 5u;
-
- for( auto y = 0u; y < height; ++y )
- {
- for( auto x = 0u; x < width; ++x )
- {
- data[x + width * y] = COLORS[( ( x * x ) + ( y * y ) ) % COLORS_COUNT];
- }
- }
-
- return Pixmap{ data, width, height };
-}
-
-Pixmap LoadResourceImage( void* data, uint32_t width, uint32_t height, uint32_t bytesPerPixel )
-{
- // todo: create Pixmap object
-}
-
-Texture CreateTexture( Graphics& graphics, Pixmap pixmap )
-{
- return Texture( graphics, pixmap );
-}
-
-int TextureTestMain( Dali::Graphics::Vulkan::Graphics& graphics )
-{
- auto pixmap = GenerateTexture32BPPRGBA( 1024, 1024 );
- auto texture = Dali::Graphics::Vulkan::Texture::New( graphics, 1024, 1024, vk::Format::eR8G8B8A8Unorm );
-
- return 0;
-}
-
-} // namespace VulkanTest
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// INTERNAL INCLUDES
-#include <dali/graphics/vulkan/vulkan-graphics.h>
-#include <dali/graphics/vulkan/internal/vulkan-command-pool.h>
-#include <dali/graphics/vulkan/internal/vulkan-command-buffer.h>
-#include <dali/graphics/vulkan/internal/vulkan-queue.h>
-#include <dali/graphics/vulkan/internal/vulkan-surface.h>
-#include <dali/integration-api/graphics/vulkan/vk-surface-factory.h>
-
-#include <dali/graphics/vulkan/internal/vulkan-buffer.h>
-#include <dali/graphics/vulkan/internal/vulkan-image.h>
-#include <dali/graphics/vulkan/internal/vulkan-image-view.h>
-#include <dali/graphics/vulkan/internal/vulkan-shader.h>
-#include <dali/graphics/vulkan/internal/vulkan-framebuffer.h>
-#include <dali/graphics/vulkan/api/vulkan-api-controller.h>
-#include <dali/graphics/vulkan/internal/vulkan-sampler.h>
-#include <dali/graphics/vulkan/internal/vulkan-debug.h>
-#include <dali/graphics/vulkan/internal/vulkan-fence.h>
-#include <dali/graphics/vulkan/internal/vulkan-swapchain.h>
-#include <dali/graphics/vulkan/internal/vulkan-debug-allocator.h>
-
-#include <dali/graphics-api/graphics-api-controller.h>
-
-#ifndef VK_KHR_XLIB_SURFACE_EXTENSION_NAME
-#define VK_KHR_XLIB_SURFACE_EXTENSION_NAME "VK_KHR_xlib_surface"
-#endif
-
-#ifndef VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME
-#define VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME "VK_KHR_wayland_surface"
-#endif
-
-#ifndef VK_KHR_XCB_SURFACE_EXTENSION_NAME
-#define VK_KHR_XCB_SURFACE_EXTENSION_NAME "VK_KHR_xcb_surface"
-#endif
-
-#include <iostream>
-#include <utility>
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-
-const uint32_t INVALID_MEMORY_INDEX = -1u;
-
-/**
- * Helper function which returns GPU heap index that can be used to allocate
- * particular type of resource
- */
-uint32_t GetMemoryIndex( const vk::PhysicalDeviceMemoryProperties& memoryProperties,
- uint32_t memoryTypeBits, vk::MemoryPropertyFlags properties )
-{
- for( uint32_t i = 0; i < memoryProperties.memoryTypeCount; ++i )
- {
- if( ( memoryTypeBits & ( 1u << i ) ) &&
- ( ( memoryProperties.memoryTypes[i].propertyFlags & properties ) == properties ) )
- {
- return i;
- }
- }
- return INVALID_MEMORY_INDEX;
-}
-
-
-/********************************************************
- * Memory
- */
-
-Memory::Memory( Graphics* _graphics, vk::DeviceMemory deviceMemory, size_t memSize, size_t memAlign, bool isHostVisible )
-: graphics( _graphics ),
- memory( deviceMemory ),
- size( memSize ),
- alignment( memAlign ),
- mappedPtr( nullptr ),
- mappedSize( 0u ),
- hostVisible( isHostVisible )
-{
-}
-
-Memory::~Memory()
-{
- // free memory
- if( memory )
- {
- auto device = graphics->GetDevice();
- auto allocator = &graphics->GetAllocator();
- auto deviceMemory = memory;
-
- // Discard unused descriptor set layouts
- graphics->DiscardResource( [ device, deviceMemory, allocator ]() {
- // free memory
- device.freeMemory( deviceMemory, allocator );
- } );
- }
-}
-
-void* Memory::Map( uint32_t offset, uint32_t requestedMappedSize )
-{
- if( !memory )
- {
- return nullptr;
- }
-
- if( mappedPtr )
- {
- return mappedPtr;
- }
- mappedPtr = graphics->GetDevice().mapMemory( memory, offset, requestedMappedSize ? requestedMappedSize : VK_WHOLE_SIZE ).value;
- mappedSize = requestedMappedSize;
- return mappedPtr;
-}
-
-void* Memory::Map()
-{
- return Map( 0u, 0u );
-}
-
-void Memory::Unmap()
-{
- if( memory && mappedPtr )
- {
- graphics->GetDevice().unmapMemory( memory );
- mappedPtr = nullptr;
- }
-}
-
-vk::DeviceMemory Memory::ReleaseVkObject()
-{
- auto retval = memory;
- memory = nullptr;
- return retval;
-}
-
-void Memory::Flush()
-{
- graphics->GetDevice().flushMappedMemoryRanges( { vk::MappedMemoryRange{}
- .setSize( mappedSize )
- .setMemory( memory )
- .setOffset( 0u )
- } );
-}
-
-vk::DeviceMemory Memory::GetVkHandle() const
-{
- return memory;
-}
-
-
-/********************************************************/
-auto reqLayers = std::vector< const char* >{
- //"VK_LAYER_LUNARG_screenshot", // screenshot
- //"VK_LAYER_LUNARG_parameter_validation", // parameter
- //"VK_LAYER_LUNARG_vktrace", // vktrace ( requires vktrace connection )
- //"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_LUNARG_standard_validation", // standard
- // Don't add VK_LAYER_RENDERDOC_Capture, set ENABLE_VULKAN_RENDERDOC_CAPTURE=1 environment variable
-};
-
-Graphics::Graphics()
-{
- // set up debug allocation callbacks if needed
-#if defined(DEBUG_MEMORY_ALLOCATOR)
- mAllocator.reset( new vk::AllocationCallbacks( *GetDebugAllocator() ) );
-#endif
-}
-
-Graphics::~Graphics()
-{
- mGfxController.reset( nullptr );
-
- // Wait for everything to finish on the GPU
- DeviceWaitIdle();
-
- // Manually resetting unique pointer here because we need to control the order of destruction.
- // This defeats the purpose of unique pointers and we might as well use raw pointers. But a unique ptr
- // communicates ownership more clearly (e.g by not allowing copies).
- mGfxController.reset( nullptr );
- mSurfaceFBIDMap.clear();
-
- mCommandPools.clear();
-
- DALI_LOG_STREAM( gVulkanFilter, Debug::General, "DESTROYING GRAPHICS CONTEXT--------------------------------\n" );
-
- // Kill pipeline cache
- mDevice.destroyPipelineCache( mVulkanPipelineCache, mAllocator.get() );
-
- // Collect the garbage ( for each buffer index ) and shut down gracefully...
- CollectGarbage();
- SwapBuffers();
- CollectGarbage();
-
- // We are done with all resources (technically... . If not we will get a ton of validation layer errors)
- // Kill the Vulkan logical device
- mDevice.destroy( mAllocator.get() );
-
- // Kill the Vulkan instance
- DestroyInstance();
-}
-
-// Create methods -----------------------------------------------------------------------------------------------
-void Graphics::Create()
-{
- const char* enable_extmem = std::getenv("DALI_VULKAN_EXTERNAL_MEMORY_EXTENSION");
-
- int intValue = enable_extmem ? std::atoi(enable_extmem) : 1;
- if ( intValue )
- {
- mDisableNativeImage = false;
- }
- else
- {
- mDisableNativeImage = true;
- }
-
- auto extensions = PrepareDefaultInstanceExtensions();
-
- auto layers = vk::enumerateInstanceLayerProperties();
-
- const char* envRenderdoc = std::getenv( "ENABLE_VULKAN_RENDERDOC_CAPTURE" );
- int enableRDC = envRenderdoc ? std::atoi(envRenderdoc) : 0;
-
- if ( enableRDC )
- {
- reqLayers.clear();
- reqLayers.push_back( "VK_LAYER_RENDERDOC_Capture" );
- }
-
- std::vector< const char* > validationLayers;
- for( auto&& reqLayer : reqLayers )
- {
- for( auto&& prop : layers.value )
- {
- DALI_LOG_STREAM( gVulkanFilter, Debug::General, prop.layerName );
- if( std::string( prop.layerName ) == reqLayer )
- {
- validationLayers.push_back( reqLayer );
- }
- }
- }
-
- CreateInstance( extensions, validationLayers );
- PreparePhysicalDevice();
-}
-
-void Graphics::CreateDevice()
-{
- auto queueInfos = GetQueueCreateInfos();
- {
- auto maxQueueCountPerFamily = 0u;
- for( auto&& info : queueInfos )
- {
- maxQueueCountPerFamily = std::max( info.queueCount, maxQueueCountPerFamily );
- }
-
- auto priorities = std::vector< float >( maxQueueCountPerFamily );
- std::fill( priorities.begin(), priorities.end(), 1.0f );
-
- for( auto& info : queueInfos )
- {
- info.setPQueuePriorities( priorities.data() );
- }
-
- std::vector< const char* > extensions{ VK_KHR_SWAPCHAIN_EXTENSION_NAME };
-
- /**
- * @todo Check these exist before using them for native image:
- * VK_KHR_SWAPCHAIN_EXTENSION_NAME
- * VK_EXT_IMAGE_DRM_FORMAT_MODIFIER_EXTENSION_NAME
- * VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME
- * VK_KHR_BIND_MEMORY_2_EXTENSION_NAME
- * VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME
- * VK_KHR_MAINTENANCE1_EXTENSION_NAME
- * VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME
- * VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME
- */
-
- vk::PhysicalDeviceFeatures featuresToEnable{};
-
- if( mPhysicalDeviceFeatures.fillModeNonSolid )
- {
- featuresToEnable.fillModeNonSolid = VK_TRUE;
- }
-
- if( mPhysicalDeviceFeatures.textureCompressionASTC_LDR )
- {
- featuresToEnable.textureCompressionASTC_LDR = VK_TRUE;
- }
-
- if( mPhysicalDeviceFeatures.textureCompressionETC2 )
- {
- featuresToEnable.textureCompressionETC2 = VK_TRUE;
- }
-
- auto info = vk::DeviceCreateInfo{};
- info.setEnabledExtensionCount( U32( extensions.size() ) )
- .setPpEnabledExtensionNames( extensions.data() )
- .setPEnabledFeatures( &featuresToEnable )
- .setPQueueCreateInfos( queueInfos.data() )
- .setQueueCreateInfoCount( U32( queueInfos.size() ) );
-
- mDevice = VkAssert( mPhysicalDevice.createDevice( info, *mAllocator ) );
- }
-
- // create Queue objects
- for( auto& queueInfo : queueInfos )
- {
- for( auto i = 0u; i < queueInfo.queueCount; ++i )
- {
- auto queue = mDevice.getQueue( queueInfo.queueFamilyIndex, i );
-
- // based on family push queue instance into right array
- auto flags = mQueueFamilyProperties[queueInfo.queueFamilyIndex].queueFlags;\
- auto queueWrapper = std::unique_ptr< Queue >( new Queue( *this, queue, queueInfo.queueFamilyIndex, i, flags ) );
- if( flags & vk::QueueFlagBits::eGraphics )
- {
- mGraphicsQueues.emplace_back( queueWrapper.get() );
- }
- if( flags & vk::QueueFlagBits::eTransfer )
- {
- mTransferQueues.emplace_back( queueWrapper.get() );
- }
- if( flags & vk::QueueFlagBits::eCompute )
- {
- mComputeQueues.emplace_back( queueWrapper.get() );
- }
- mAllQueues.emplace_back( std::move( queueWrapper ));
- // todo: present queue
- }
- }
-}
-
-FBID Graphics::CreateSurface( SurfaceFactory& surfaceFactory,
- const Integration::Graphics::GraphicsCreateInfo& createInfo )
-{
- auto vulkanSurfaceFactory = dynamic_cast<Dali::Integration::Graphics::Vulkan::VkSurfaceFactory*>( &surfaceFactory );
-
- if( !vulkanSurfaceFactory )
- {
- return -1; // fail
- }
-
- // create surface from the factory
- auto surface = new Surface( *this );
-
- surface->mSurface = vulkanSurfaceFactory->Create( mInstance,
- mAllocator.get(),
- mPhysicalDevice );
-
- if( !surface->mSurface )
- {
- return -1;
- }
-
- VkBool32 supported( VK_FALSE );
- for( auto i = 0u; i < mQueueFamilyProperties.size(); ++i )
- {
- mPhysicalDevice.getSurfaceSupportKHR( i, surface->mSurface, &supported );
- if( supported )
- {
- break;
- }
- }
-
- assert( supported && "There is no queue family supporting presentation!");
-
- surface->mCapabilities = VkAssert( mPhysicalDevice.getSurfaceCapabilitiesKHR( surface->mSurface ) );
-
- // If width (and height) equals the special value 0xFFFFFFFF, the size of the surface will be set by the swapchain
- if( surface->mCapabilities.currentExtent.width == std::numeric_limits< uint32_t >::max() )
- {
- surface->mCapabilities.currentExtent.width = std::max( surface->mCapabilities.minImageExtent.width,
- std::min( surface->mCapabilities.maxImageExtent.width, createInfo.surfaceWidth ) );
-
- surface->mCapabilities.currentExtent.height = std::max( surface->mCapabilities.minImageExtent.height,
- std::min( surface->mCapabilities.maxImageExtent.height, createInfo.surfaceHeight ) );
-
- }
-
- mSurfaceResized = false;
-
- // map surface to FBID
- auto fbid = ++mBaseFBID;
-
- mSurfaceFBIDMap[ fbid ] = SwapchainSurfacePair{ RefCountedSwapchain{}, RefCountedSurface( surface ) };
-
-
- if( createInfo.depthStencilMode == Integration::Graphics::DepthStencilMode::DEPTH_OPTIMAL ||
- createInfo.depthStencilMode == Integration::Graphics::DepthStencilMode::DEPTH_STENCIL_OPTIMAL )
- {
- mHasDepth = true;
- }
- else
- {
- mHasDepth = false;
- }
-
- if( createInfo.depthStencilMode == Integration::Graphics::DepthStencilMode::DEPTH_STENCIL_OPTIMAL )
- {
- mHasStencil = true;
- }
-
- return fbid;
-}
-
-RefCountedSwapchain Graphics::CreateSwapchainForSurface( RefCountedSurface surface )
-{
-
- auto surfaceCapabilities = surface->GetCapabilities();
-
- //TODO: propagate the format and presentation mode to higher layers to allow for more control?
- auto swapchain = CreateSwapchain( surface,
- vk::Format::eB8G8R8A8Unorm,
- vk::PresentModeKHR::eFifo,
- surfaceCapabilities.minImageCount,
- Dali::Graphics::Vulkan::RefCountedSwapchain() );
-
- // store swapchain in the correct pair
- for( auto&& val : mSurfaceFBIDMap )
- {
- if( val.second.surface == surface )
- {
- val.second.swapchain = swapchain;
- break;
- }
- }
-
- return swapchain;
-}
-
-void Graphics::InitialiseController()
-{
- mGfxController->Initialise();
-}
-
-RefCountedSwapchain Graphics::ReplaceSwapchainForSurface( RefCountedSurface surface, RefCountedSwapchain&& oldSwapchain )
-{
- auto surfaceCapabilities = surface->GetCapabilities();
-
- mSurfaceResized = false;
-
- auto swapchain = CreateSwapchain( surface,
- vk::Format::eB8G8R8A8Unorm,
- vk::PresentModeKHR::eFifo,
- surfaceCapabilities.minImageCount,
- std::move(oldSwapchain) );
-
-
- // store swapchain in the correct pair
- for( auto&& val : mSurfaceFBIDMap )
- {
- if( val.second.surface == surface )
- {
- val.second.swapchain = swapchain;
- break;
- }
- }
-
- return swapchain;
-}
-
-
-RefCountedFence Graphics::CreateFence( const vk::FenceCreateInfo& fenceCreateInfo )
-{
- auto fence = new Fence( *this );
-
- VkAssert( mDevice.createFence( &fenceCreateInfo, mAllocator.get(), &fence->mFence ) );
-
- auto refCountedFence = RefCountedFence( fence );
-
- return refCountedFence;
-}
-
-RefCountedBuffer Graphics::CreateBuffer( size_t size, vk::BufferUsageFlags usageFlags )
-{
- auto info = vk::BufferCreateInfo{};
- info.setSharingMode( vk::SharingMode::eExclusive );
- info.setSize( size );
- info.setUsage( usageFlags | vk::BufferUsageFlagBits::eTransferDst );
-
- auto buffer = new Buffer( *this, info );
-
- VkAssert( mDevice.createBuffer( &info, mAllocator.get(), &buffer->mBuffer ) );
-
- auto refCountedBuffer = RefCountedBuffer( buffer );
-
- return refCountedBuffer;
-}
-
-RefCountedBuffer Graphics::CreateBuffer( const vk::BufferCreateInfo& bufferCreateInfo )
-{
- auto buffer = new Buffer( *this, bufferCreateInfo );
-
- VkAssert( mDevice.createBuffer( &bufferCreateInfo, mAllocator.get(), &buffer->mBuffer ) );
-
- auto refCountedBuffer = RefCountedBuffer( buffer );
-
- return refCountedBuffer;
-}
-
-vk::RenderPass Graphics::CreateCompatibleRenderPass(
- const std::vector< RefCountedFramebufferAttachment >& colorAttachments,
- RefCountedFramebufferAttachment depthAttachment,
- std::vector<vk::ImageView>& attachments
-)
-{
- auto hasDepth = false;
- if( depthAttachment )
- {
- hasDepth = depthAttachment->IsValid();
- assert( hasDepth && "Invalid depth attachment! The attachment has no ImageView" );
- }
-
- // The total number of attachments
- auto totalAttachmentCount = hasDepth ? colorAttachments.size() + 1 : colorAttachments.size();
-
- attachments.clear();
- attachments.reserve( totalAttachmentCount );
-
- // This vector stores the attachment references
- auto colorAttachmentReferences = std::vector< vk::AttachmentReference >{};
- colorAttachmentReferences.reserve( colorAttachments.size() );
-
- // This vector stores the attachment descriptions
- auto attachmentDescriptions = std::vector< vk::AttachmentDescription >{};
- attachmentDescriptions.reserve( totalAttachmentCount );
-
- // For each color attachment...
- for( auto i = 0u; i < colorAttachments.size(); ++i )
- {
- // Get the image layout
- auto imageLayout = colorAttachments[i]->GetImageView()->GetImage()->GetImageLayout();
-
- // If the layout is undefined...
- if( imageLayout == vk::ImageLayout::eUndefined )
- {
- // Set it to color attachment optimal
- imageLayout = vk::ImageLayout::eColorAttachmentOptimal;
- }
-
- // Any other case should be invalid
- assert( imageLayout == vk::ImageLayout::eColorAttachmentOptimal );
-
- // Add a reference and a descriptions and image views to their respective vectors
- colorAttachmentReferences.push_back( vk::AttachmentReference{}.setLayout( imageLayout )
- .setAttachment( U32( i ) ) );
-
- attachmentDescriptions.push_back( colorAttachments[i]->GetDescription() );
-
- attachments.push_back( colorAttachments[i]->GetImageView()->GetVkHandle() );
- }
-
-
- // Follow the exact same procedure as color attachments
- auto depthAttachmentReference = vk::AttachmentReference{};
- if( hasDepth )
- {
- auto imageLayout = depthAttachment->GetImageView()->GetImage()->GetImageLayout();
-
- if( imageLayout == vk::ImageLayout::eUndefined )
- {
- imageLayout = vk::ImageLayout::eDepthStencilAttachmentOptimal;
- }
-
- assert( imageLayout == vk::ImageLayout::eDepthStencilAttachmentOptimal );
-
- depthAttachmentReference.setLayout( imageLayout );
- depthAttachmentReference.setAttachment( U32( colorAttachmentReferences.size() ) );
-
- attachmentDescriptions.push_back( depthAttachment->GetDescription() );
-
- attachments.push_back( depthAttachment->GetImageView()->GetVkHandle() );
- }
-
- // Creating a single subpass per framebuffer
- auto subpassDesc = vk::SubpassDescription{};
- subpassDesc.setPipelineBindPoint( vk::PipelineBindPoint::eGraphics );
- subpassDesc.setColorAttachmentCount( U32( colorAttachments.size()));
- if( hasDepth )
- {
- subpassDesc.setPDepthStencilAttachment( &depthAttachmentReference );
- }
- subpassDesc.setPColorAttachments( colorAttachmentReferences.data() );
-
- // Creating 2 subpass dependencies using VK_SUBPASS_EXTERNAL to leverage the implicit image layout
- // transitions provided by the driver
- std::array< vk::SubpassDependency, 2 > subpassDependencies{
-
- vk::SubpassDependency{}.setSrcSubpass( VK_SUBPASS_EXTERNAL )
- .setDstSubpass( 0 )
- .setSrcStageMask( vk::PipelineStageFlagBits::eBottomOfPipe )
- .setDstStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput )
- .setSrcAccessMask( vk::AccessFlagBits::eMemoryRead )
- .setDstAccessMask( vk::AccessFlagBits::eColorAttachmentRead |
- vk::AccessFlagBits::eColorAttachmentWrite )
- .setDependencyFlags( vk::DependencyFlagBits::eByRegion ),
-
- vk::SubpassDependency{}.setSrcSubpass( 0 )
- .setDstSubpass( VK_SUBPASS_EXTERNAL )
- .setSrcStageMask( vk::PipelineStageFlagBits::eColorAttachmentOutput )
- .setDstStageMask( vk::PipelineStageFlagBits::eBottomOfPipe )
- .setSrcAccessMask( vk::AccessFlagBits::eColorAttachmentRead |
- vk::AccessFlagBits::eColorAttachmentWrite )
- .setDstAccessMask( vk::AccessFlagBits::eMemoryRead )
- .setDependencyFlags( vk::DependencyFlagBits::eByRegion )
-
- };
-
-
- // Create the render pass
- auto renderPassCreateInfo = vk::RenderPassCreateInfo{}.setAttachmentCount( U32( attachmentDescriptions.size() ) )
- .setPAttachments( attachmentDescriptions.data() )
- .setPSubpasses( &subpassDesc )
- .setSubpassCount( 1 )
- .setPDependencies( subpassDependencies.data() );
-
-
- return VkAssert( mDevice.createRenderPass( renderPassCreateInfo, mAllocator.get() ) );
-}
-
-RefCountedFramebuffer Graphics::CreateFramebuffer(
- const std::vector< RefCountedFramebufferAttachment >& colorAttachments,
- RefCountedFramebufferAttachment depthAttachment,
- uint32_t width,
- uint32_t height,
- vk::RenderPass externalRenderPass )
-{
- assert( ( !colorAttachments.empty() || depthAttachment )
- && "Cannot create framebuffer. Please provide at least one attachment" );
-
- auto colorAttachmentsValid = true;
- for( auto& attachment : colorAttachments )
- {
- if( !attachment->IsValid() )
- {
- colorAttachmentsValid = false;
- break;
- }
- }
-
- assert( colorAttachmentsValid && "Invalid color attachment! The attachment has no ImageView" );
-
- // Flag that indicates if the framebuffer has a depth attachment
- auto hasDepth = false;
- if( depthAttachment )
- {
- hasDepth = depthAttachment->IsValid();
- assert( hasDepth && "Invalid depth attachment! The attachment has no ImageView" );
- }
-
- auto renderPass = externalRenderPass;
-
- // Flag that indicates if the render pass is externally provided
- auto isRenderPassExternal = externalRenderPass != vk::RenderPass{};
-
- // This vector stores the attachments (vk::ImageViews)
- auto attachments = std::vector< vk::ImageView >{};
-
- // If no external render pass was provided, create one internally
- if( !isRenderPassExternal )
- {
- renderPass = CreateCompatibleRenderPass( colorAttachments, depthAttachment, attachments );
- }
-
- // Finally create the framebuffer
- auto framebufferCreateInfo = vk::FramebufferCreateInfo{}.setRenderPass( renderPass )
- .setPAttachments( attachments.data() )
- .setLayers( 1 )
- .setWidth( width )
- .setHeight( height )
- .setAttachmentCount( U32( attachments.size() ) );
-
- auto framebuffer = VkAssert( mDevice.createFramebuffer( framebufferCreateInfo, mAllocator.get() ) );
-
- return RefCountedFramebuffer( new Framebuffer( *this,
- colorAttachments,
- depthAttachment,
- framebuffer,
- renderPass,
- width,
- height,
- isRenderPassExternal ) );
-}
-
-RefCountedImage Graphics::CreateImage( const vk::ImageCreateInfo& imageCreateInfo )
-{
- auto image = new Image( *this, imageCreateInfo );
-
- VkAssert( mDevice.createImage( &imageCreateInfo, &GetAllocator("IMAGE"), &image->mImage ) );
-
- auto refCountedImage = RefCountedImage( image );
-
- return refCountedImage;
-}
-
-RefCountedImage Graphics::CreateImageFromExternal( vk::Image externalImage,
- vk::Format imageFormat,
- vk::Extent2D extent )
-{
- auto imageCreateInfo = vk::ImageCreateInfo{}
- .setFormat( imageFormat )
- .setSamples( vk::SampleCountFlagBits::e1 )
- .setInitialLayout( vk::ImageLayout::eUndefined )
- .setSharingMode( vk::SharingMode::eExclusive )
- .setUsage( vk::ImageUsageFlagBits::eColorAttachment )
- .setExtent( { extent.width, extent.height, 1 } )
- .setArrayLayers( 1 )
- .setImageType( vk::ImageType::e2D )
- .setTiling( vk::ImageTiling::eOptimal )
- .setMipLevels( 1 );
-
- return RefCountedImage(new Image( *this, imageCreateInfo, externalImage ) );
-}
-
-RefCountedImageView Graphics::CreateImageView( const vk::ImageViewCreateFlags& flags,
- const RefCountedImage& image,
- vk::ImageViewType viewType,
- vk::Format format,
- vk::ComponentMapping components,
- vk::ImageSubresourceRange subresourceRange )
-{
- auto imageViewCreateInfo = vk::ImageViewCreateInfo{}
- .setFlags( flags )
- .setImage( image->GetVkHandle() )
- .setViewType( viewType )
- .setFormat( format )
- .setComponents( components )
- .setSubresourceRange( std::move( subresourceRange ) );
-
- auto imageView = new ImageView( *this, image, imageViewCreateInfo );
-
- VkAssert( mDevice.createImageView( &imageViewCreateInfo, &GetAllocator("IMAGEVIEW"), &imageView->mImageView ) );
-
- auto refCountedImageView = RefCountedImageView( imageView );
-
- return refCountedImageView;
-}
-
-RefCountedImageView Graphics::CreateImageView( RefCountedImage image )
-{
- vk::ComponentMapping componentsMapping = { vk::ComponentSwizzle::eR,
- vk::ComponentSwizzle::eG,
- vk::ComponentSwizzle::eB,
- vk::ComponentSwizzle::eA };
-
-
- auto subresourceRange = vk::ImageSubresourceRange{}
- .setAspectMask( image->GetAspectFlags() )
- .setBaseArrayLayer( 0 )
- .setBaseMipLevel( 0 )
- .setLevelCount( image->GetMipLevelCount() )
- .setLayerCount( image->GetLayerCount() );
-
- auto refCountedImageView = CreateImageView( {},
- image,
- vk::ImageViewType::e2D,
- image->GetFormat(),
- componentsMapping,
- subresourceRange );
-
- return refCountedImageView;
-}
-
-RefCountedSampler Graphics::CreateSampler( const vk::SamplerCreateInfo& samplerCreateInfo )
-{
- auto sampler = new Sampler( *this, samplerCreateInfo );
-
- VkAssert( mDevice.createSampler( &samplerCreateInfo, &GetAllocator("SAMPLER"), &sampler->mSampler ) );
-
- auto refCountedSampler = RefCountedSampler( sampler );
-
- return refCountedSampler;
-
-}
-
-RefCountedCommandBuffer Graphics::CreateCommandBuffer( bool primary )
-{
- auto commandPool = GetCommandPool( std::this_thread::get_id() );
-
- return commandPool->NewCommandBuffer( primary );
-}
-
-vk::ImageMemoryBarrier Graphics::CreateImageMemoryBarrier( RefCountedImage image,
- vk::ImageLayout oldLayout,
- vk::ImageLayout newLayout )
-{
- // This function assumes that all images have 1 mip level and 1 layer
- auto barrier = vk::ImageMemoryBarrier{}
- .setOldLayout( oldLayout )
- .setNewLayout( newLayout )
- .setSrcQueueFamilyIndex( VK_QUEUE_FAMILY_IGNORED )
- .setDstQueueFamilyIndex( VK_QUEUE_FAMILY_IGNORED )
- .setImage( image->GetVkHandle() )
- .setSubresourceRange( vk::ImageSubresourceRange{}.setBaseMipLevel( 0 )
- .setLevelCount( 1 )
- .setBaseArrayLayer( 0 )
- .setLayerCount( 1 ) );
-
- barrier.subresourceRange.aspectMask = image->GetAspectFlags();
-
- // The srcAccessMask of the image memory barrier shows which operation
- // must be completed using the old layout, before the transition to the
- // new one happens.
- switch( oldLayout )
- {
- case vk::ImageLayout::eUndefined:
- barrier.srcAccessMask = vk::AccessFlags{};
- break;
- case vk::ImageLayout::ePreinitialized:
- barrier.srcAccessMask = vk::AccessFlagBits::eHostWrite;
- break;
- case vk::ImageLayout::eColorAttachmentOptimal:
- barrier.srcAccessMask = vk::AccessFlagBits::eColorAttachmentWrite;
- break;
- case vk::ImageLayout::eDepthStencilAttachmentOptimal:
- barrier.srcAccessMask = vk::AccessFlagBits::eDepthStencilAttachmentWrite;
- break;
- case vk::ImageLayout::eTransferSrcOptimal:
- barrier.srcAccessMask = vk::AccessFlagBits::eTransferRead;
- break;
- case vk::ImageLayout::eTransferDstOptimal:
- barrier.srcAccessMask = vk::AccessFlagBits::eTransferWrite;
- break;
- case vk::ImageLayout::eShaderReadOnlyOptimal:
- barrier.srcAccessMask = vk::AccessFlagBits::eShaderRead;
- break;
- default:
- assert( false && "Image layout transition failed: Initial layout not supported." );
- }
-
- // Destination access mask controls the dependency for the new image layout
- switch( newLayout )
- {
- case vk::ImageLayout::eTransferDstOptimal:
- barrier.dstAccessMask = vk::AccessFlagBits::eTransferWrite;
- break;
- case vk::ImageLayout::eTransferSrcOptimal:
- barrier.dstAccessMask = vk::AccessFlagBits::eTransferRead;
- break;
- case vk::ImageLayout::eColorAttachmentOptimal:
- barrier.dstAccessMask = vk::AccessFlagBits::eColorAttachmentWrite;
- break;
- case vk::ImageLayout::eDepthStencilAttachmentOptimal:
- barrier.dstAccessMask = vk::AccessFlagBits::eDepthStencilAttachmentWrite;
- break;
- case vk::ImageLayout::eShaderReadOnlyOptimal:
- if( barrier.srcAccessMask == vk::AccessFlags{} )
- {
- barrier.srcAccessMask = vk::AccessFlagBits::eHostWrite | vk::AccessFlagBits::eTransferWrite;
- }
-
- barrier.dstAccessMask = vk::AccessFlagBits::eShaderRead;
- break;
- default:
- assert( false && "Image layout transition failed: Target layout not supported." );
- }
-
- return barrier;
-}
-
-RefCountedSwapchain Graphics::CreateSwapchain( RefCountedSurface surface,
- vk::Format requestedFormat,
- vk::PresentModeKHR presentMode,
- uint32_t bufferCount,
- RefCountedSwapchain&& oldSwapchain )
-{
- // obtain supported image format
- auto supportedFormats = VkAssert( mPhysicalDevice.getSurfaceFormatsKHR( surface->GetVkHandle() ) );
-
- vk::Format swapchainImageFormat{};
- vk::ColorSpaceKHR swapchainColorSpace{};
-
- // If the surface format list only includes one entry with VK_FORMAT_UNDEFINED,
- // there is no preferred format, so we assume vk::Format::eB8G8R8A8Unorm
- if( supportedFormats.size() == 1 && supportedFormats[0].format == vk::Format::eUndefined )
- {
- swapchainColorSpace = supportedFormats[0].colorSpace;
- swapchainImageFormat = vk::Format::eB8G8R8A8Unorm;
- }
- else // Try to find the requested format in the list
- {
- auto found = std::find_if( supportedFormats.begin(),
- supportedFormats.end(),
- [ & ]( vk::SurfaceFormatKHR supportedFormat ) {
- return requestedFormat == supportedFormat.format;
- } );
-
- // If found assign it.
- if( found != supportedFormats.end() )
- {
- auto surfaceFormat = *found;
- swapchainColorSpace = surfaceFormat.colorSpace;
- swapchainImageFormat = surfaceFormat.format;
- }
- else // Requested format not found...attempt to use the first one on the list
- {
- auto surfaceFormat = supportedFormats[0];
- swapchainColorSpace = surfaceFormat.colorSpace;
- swapchainImageFormat = surfaceFormat.format;
- }
-
- }
-
- assert( swapchainImageFormat != vk::Format::eUndefined && "Could not find a supported swap chain image format." );
-
- // Get the surface capabilities to determine some settings of the swap chain
- auto surfaceCapabilities = surface->GetCapabilities();
-
- // Determine the swap chain extent
- auto swapchainExtent = surfaceCapabilities.currentExtent;
-
- // Find a supported composite alpha format (not all devices support alpha opaque)
- auto compositeAlpha = vk::CompositeAlphaFlagBitsKHR{};
-
- // Simply select the first composite alpha format available
- auto compositeAlphaFlags = std::vector< vk::CompositeAlphaFlagBitsKHR >{
- vk::CompositeAlphaFlagBitsKHR::eOpaque,
- vk::CompositeAlphaFlagBitsKHR::ePreMultiplied,
- vk::CompositeAlphaFlagBitsKHR::ePostMultiplied,
- vk::CompositeAlphaFlagBitsKHR::eInherit
- };
-
-
- for( const auto& compositeAlphaFlag : compositeAlphaFlags )
- {
-
- if( surfaceCapabilities.supportedCompositeAlpha & compositeAlphaFlag )
- {
- compositeAlpha = compositeAlphaFlag;
- break;
- }
-
- }
-
- // Determine the number of images
- if (surfaceCapabilities.minImageCount > 0 &&
- bufferCount > surfaceCapabilities.minImageCount )
- {
- bufferCount = surfaceCapabilities.minImageCount;
- }
-
- // Find the transformation of the surface
- vk::SurfaceTransformFlagBitsKHR preTransform;
- if( surfaceCapabilities.supportedTransforms & vk::SurfaceTransformFlagBitsKHR::eIdentity )
- {
- // We prefer a non-rotated transform
- preTransform = vk::SurfaceTransformFlagBitsKHR::eIdentity;
- }
- else
- {
- preTransform = surfaceCapabilities.currentTransform;
- }
-
-
- // Check if the requested present mode is supported
- auto presentModes = mPhysicalDevice.getSurfacePresentModesKHR( surface->GetVkHandle() ).value;
-
- auto found = std::find_if( presentModes.begin(),
- presentModes.end(),
- [ & ]( vk::PresentModeKHR mode ) {
- return presentMode == mode;
- } );
-
- if( found == presentModes.end() )
- {
- // Requested present mode not supported. Default to FIFO. FIFO is always supported as per spec.
- presentMode = vk::PresentModeKHR::eFifo;
- }
-
- // Creation settings have been determined. Fill in the create info struct.
- auto swapChainCreateInfo = vk::SwapchainCreateInfoKHR{}.setSurface( surface->GetVkHandle() )
- .setPreTransform( preTransform )
- .setPresentMode( presentMode )
- .setOldSwapchain( oldSwapchain ? oldSwapchain->GetVkHandle()
- : vk::SwapchainKHR{} )
- .setMinImageCount( bufferCount )
- .setImageUsage( vk::ImageUsageFlagBits::eColorAttachment )
- .setImageSharingMode( vk::SharingMode::eExclusive )
- .setImageArrayLayers( 1 )
- .setImageColorSpace( swapchainColorSpace )
- .setImageFormat( swapchainImageFormat )
- .setImageExtent( swapchainExtent )
- .setCompositeAlpha( compositeAlpha )
- .setClipped( static_cast<vk::Bool32>(true) )
- .setQueueFamilyIndexCount( 0 )
- .setPQueueFamilyIndices( nullptr );
-
-
- // Create the swap chain
- auto swapChainVkHandle = VkAssert( mDevice.createSwapchainKHR( swapChainCreateInfo, mAllocator.get() ) );
-
- if( oldSwapchain )
- {
- for( auto&& i : mSurfaceFBIDMap )
- {
- if( i.second.swapchain == oldSwapchain )
- {
- i.second.swapchain = RefCountedSwapchain();
- break;
- }
- }
- }
-
- if( oldSwapchain )
- {
- // prevent destroying the swapchain as it is handled automatically
- // during replacing the swapchain
- auto khr = oldSwapchain->mSwapchainKHR;
- oldSwapchain->mSwapchainKHR = nullptr;
- oldSwapchain.Reset();
-
- mDevice.destroySwapchainKHR( khr, *mAllocator );
- }
-
- // pull images and create Framebuffers
- auto images = VkAssert( mDevice.getSwapchainImagesKHR( swapChainVkHandle ) );
-
- // number of images must match requested buffering mode
- if( images.size() < surfaceCapabilities.minImageCount )
- {
- DALI_LOG_STREAM( gVulkanFilter,
- Debug::General,
- "Swapchain creation failed: Swapchain images are less than the requested amount" );
- mDevice.destroySwapchainKHR( swapChainVkHandle );
- return RefCountedSwapchain();
- }
-
- auto framebuffers = std::vector< RefCountedFramebuffer >{};
- framebuffers.reserve( images.size() );
-
- auto clearColor = vk::ClearColorValue{}.setFloat32( { 0.0f, 0.0f, 0.0f, 0.0f } );
-
- /*
- * CREATE FRAMEBUFFERS
- */
- for( auto&& image : images )
- {
- auto colorImageView = CreateImageView( CreateImageFromExternal( image, swapchainImageFormat, swapchainExtent ) );
-
- // A new color attachment for each framebuffer
- auto colorAttachment = FramebufferAttachment::NewColorAttachment( colorImageView,
- clearColor,
- true /* presentable */ );
-
- framebuffers.push_back( CreateFramebuffer( { colorAttachment },
- RefCountedFramebufferAttachment{},
- swapchainExtent.width,
- swapchainExtent.height ) );
- }
-
- return RefCountedSwapchain( new Swapchain( *this,
- GetPresentQueue(),
- surface,
- std::move(framebuffers),
- swapChainCreateInfo,
- swapChainVkHandle ) );
-}
-// --------------------------------------------------------------------------------------------------------------
-
-// Actions ------------------------------------------------------------------------------------------------------
-vk::Result Graphics::WaitForFence( RefCountedFence fence, uint32_t timeout )
-{
- return mDevice.waitForFences( 1, &fence->mFence, VK_TRUE, timeout );
-}
-
-vk::Result Graphics::ResetFence( RefCountedFence fence )
-{
- return mDevice.resetFences( 1, &fence->mFence );
-}
-
-vk::Result Graphics::ResetFences( const std::vector< RefCountedFence >& fences )
-{
- std::vector< vk::Fence > vkFenceHandles{};
- std::transform( fences.begin(),
- fences.end(),
- std::back_inserter( vkFenceHandles ),
- []( RefCountedFence entry ) { return entry->mFence; } );
-
- return mDevice.resetFences( vkFenceHandles );
-}
-
-vk::Result Graphics::BindImageMemory( RefCountedImage image, std::unique_ptr<Memory> memory, uint32_t offset )
-{
- auto result = VkAssert( mDevice.bindImageMemory( image->mImage, memory->memory, offset ) );
- image->mDeviceMemory = std::move(memory);
- return result;
-}
-
-vk::Result Graphics::BindBufferMemory( RefCountedBuffer buffer, std::unique_ptr<Memory> memory, uint32_t offset )
-{
- assert( buffer->mBuffer && "Buffer not initialised!" );
- auto result = VkAssert( mDevice.bindBufferMemory( buffer->mBuffer, memory->memory, offset ) );
- buffer->mDeviceMemory = std::move(memory);
- return result;
-}
-
-void* Graphics::MapMemory( Memory* memory ) const
-{
- return memory->Map();
-}
-
-void* Graphics::MapMemory( Memory* memory, uint32_t size, uint32_t offset ) const
-{
- return memory->Map( offset, size );
-}
-
-void Graphics::UnmapMemory( Memory* memory ) const
-{
- memory->Unmap();
-}
-
-std::unique_ptr<Memory> Graphics::AllocateMemory( RefCountedBuffer buffer, vk::MemoryPropertyFlags memoryProperties )
-{
- auto requirements = mDevice.getBufferMemoryRequirements( buffer->GetVkHandle() );
- auto memoryTypeIndex = GetMemoryIndex( GetMemoryProperties(),
- requirements.memoryTypeBits,
- memoryProperties );
-
- vk::DeviceMemory memory{};
-
- auto allocateInfo = vk::MemoryAllocateInfo{}
- .setMemoryTypeIndex( memoryTypeIndex )
- .setAllocationSize( requirements.size );
-
- auto result = GetDevice().allocateMemory( &allocateInfo, &GetAllocator("DEVICEMEMORY"), &memory );
-
- if( result != vk::Result::eSuccess )
- {
- DALI_LOG_INFO( gVulkanFilter, Debug::General, "Unable to allocate memory for the buffer of size %d!", int(requirements.size) );
- return nullptr;
- }
-
- return std::unique_ptr<Memory>(
- new Memory( this,
- memory,
- uint32_t(requirements.size),
- uint32_t(requirements.alignment),
- ((memoryProperties & vk::MemoryPropertyFlagBits::eHostVisible) == vk::MemoryPropertyFlagBits::eHostVisible) )
- );
-}
-
-std::unique_ptr<Memory> Graphics::AllocateMemory( RefCountedImage image, vk::MemoryPropertyFlags memoryProperties )
-{
- auto requirements = mDevice.getImageMemoryRequirements( image->GetVkHandle() );
- auto memoryTypeIndex = GetMemoryIndex( GetMemoryProperties(),
- requirements.memoryTypeBits,
- memoryProperties );
-
- vk::DeviceMemory memory{};
-
- auto allocateInfo = vk::MemoryAllocateInfo{}
- .setMemoryTypeIndex( memoryTypeIndex )
- .setAllocationSize( requirements.size );
-
- auto result = GetDevice().allocateMemory( &allocateInfo, &GetAllocator("DEVICEMEMORY"), &memory );
-
- if( result != vk::Result::eSuccess )
- {
- DALI_LOG_INFO( gVulkanFilter, Debug::General, "Unable to allocate memory for the image of size %d!", int(requirements.size) );
- return nullptr;
- }
-
- return std::unique_ptr<Memory>(
- new Memory( this,
- memory,
- uint32_t(requirements.size),
- uint32_t(requirements.alignment),
- ((memoryProperties & vk::MemoryPropertyFlagBits::eHostVisible) == vk::MemoryPropertyFlagBits::eHostVisible) )
- );
-}
-
-vk::Result Graphics::Submit( Queue& queue, const std::vector< SubmissionData >& submissionData, RefCountedFence fence )
-{
- auto lock( queue.Lock() );
-
- auto submitInfos = std::vector< vk::SubmitInfo >{};
- submitInfos.reserve( submissionData.size() );
- auto commandBufferHandles = std::vector< vk::CommandBuffer >{};
-
- // prepare memory
- auto bufferSize = 0u;
- for( auto& data : submissionData )
- {
- bufferSize += uint32_t( data.commandBuffers.size() );
- }
- commandBufferHandles.reserve( bufferSize );
-
- // Transform SubmissionData to vk::SubmitInfo
- for( const auto& subData : submissionData )
- {
- auto currentBufferIndex = commandBufferHandles.size();
-
- //Extract the command buffer handles
- std::transform( subData.commandBuffers.cbegin(),
- subData.commandBuffers.cend(),
- std::back_inserter( commandBufferHandles ),
- [ & ]( const RefCountedCommandBuffer& entry ) {
- return entry->GetVkHandle();
- } );
-
- auto retval = vk::SubmitInfo().setWaitSemaphoreCount( U32( subData.waitSemaphores.size() ) )
- .setPWaitSemaphores( subData.waitSemaphores.data() )
- .setPWaitDstStageMask( &subData.waitDestinationStageMask )
- .setCommandBufferCount( U32( subData.commandBuffers.size() ) )
- .setPCommandBuffers( &commandBufferHandles[currentBufferIndex] )
- .setSignalSemaphoreCount( U32( subData.signalSemaphores.size() ) )
- .setPSignalSemaphores( subData.signalSemaphores.data() );
-
- submitInfos.push_back( retval );
- }
-
- return VkAssert( queue.mQueue.submit( submitInfos, fence ? fence->GetVkHandle() : vk::Fence{} ) );
-}
-
-vk::Result Graphics::Present( Queue& queue, vk::PresentInfoKHR presentInfo )
-{
- auto lock( queue.Lock() );
- return queue.mQueue.presentKHR( &presentInfo );
-}
-
-vk::Result Graphics::QueueWaitIdle( Queue& queue )
-{
- auto lock( queue.Lock() );
- return queue.mQueue.waitIdle();
-}
-
-vk::Result Graphics::DeviceWaitIdle()
-{
- return mDevice.waitIdle();
-}
-
-void Graphics::SurfaceResized( unsigned int width, unsigned int height )
-{
- // Get surface with FBID "0"
- // At first, check to empty about mSurfaceFBIDMap
- if ( !mSurfaceFBIDMap.empty() )
- {
- auto surface = mSurfaceFBIDMap.begin()->second.surface;
- if (surface)
- {
- auto surfaceCapabilities = surface->GetCapabilities();
- if ( surfaceCapabilities.currentExtent.width != width
- || surfaceCapabilities.currentExtent.height != height )
- {
- surface->UpdateSize( width, height );
- mSurfaceResized = true;
- }
- }
- }
-}
-
-// --------------------------------------------------------------------------------------------------------------
-
-// Getters ------------------------------------------------------------------------------------------------------
-RefCountedSurface 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
- .surface;
- }
- return mSurfaceFBIDMap[surfaceId].surface;
-}
-
-RefCountedSwapchain Graphics::GetSwapchainForSurface( RefCountedSurface surface )
-{
- for( auto&& val : mSurfaceFBIDMap )
- {
- if( val.second
- .surface == surface )
- {
- return val.second
- .swapchain;
- }
- }
- return RefCountedSwapchain();
-}
-
-RefCountedSwapchain Graphics::GetSwapchainForFBID( FBID surfaceId )
-{
- if( surfaceId == 0 )
- {
- return mSurfaceFBIDMap.begin()
- ->second
- .swapchain;
- }
- return mSurfaceFBIDMap[surfaceId].swapchain;
-}
-
-vk::Device Graphics::GetDevice() const
-{
- return mDevice;
-}
-
-vk::PhysicalDevice Graphics::GetPhysicalDevice() const
-{
- return mPhysicalDevice;
-}
-
-vk::Instance Graphics::GetInstance() const
-{
- return mInstance;
-}
-
-const vk::AllocationCallbacks& Graphics::GetAllocator( const char* tag )
-{
- if( mAllocator )
- {
- mAllocator->setPUserData( CreateMemoryAllocationTag( tag ) );
- }
- return *mAllocator;
-}
-
-const vk::PhysicalDeviceMemoryProperties& Graphics::GetMemoryProperties() const
-{
- return mPhysicalDeviceMemoryProperties;
-}
-
-Queue& Graphics::GetGraphicsQueue( uint32_t index ) const
-{
- // todo: at the moment each type of queue may use only one, indices greater than 0 are invalid
- // this will change in the future
- assert( index == 0u && "Each type of queue may use only one, indices greater than 0 are invalid!" );
-
- return *mGraphicsQueues[0]; // will be mGraphicsQueues[index]
-}
-
-Queue& Graphics::GetTransferQueue( uint32_t index ) const
-{
- // todo: at the moment each type of queue may use only one, indices greater than 0 are invalid
- // this will change in the future
- assert( index == 0u && "Each type of queue may use only one, indices greater than 0 are invalid!" );
-
- return *mTransferQueues[0]; // will be mGraphicsQueues[index]
-}
-
-Queue& Graphics::GetComputeQueue( uint32_t index ) const
-{
- // todo: at the moment each type of queue may use only one, indices greater than 0 are invalid
- // this will change in the future
- assert( index == 0u && "Each type of queue may use only one, indices greater than 0 are invalid!" );
-
- return *mComputeQueues[0]; // will be mGraphicsQueues[index]
-}
-
-Queue& Graphics::GetPresentQueue() const
-{
- // fixme: should be a dedicated presentation queue
- return GetGraphicsQueue( 0 );
-}
-
-Platform Graphics::GetDefaultPlatform() const
-{
-#ifdef VK_USE_PLATFORM_WAYLAND_KHR
- mPlatform = Platform::WAYLAND;
-#elif VK_USE_PLATFORM_XCB_KHR
- mPlatform = Platform::XCB;
-#elif VK_USE_PLATFORM_XLIB_KHR
- mPlatform = Platform::XLIB;
-#else
- return mPlatform;
-#endif
-}
-
-Dali::Graphics::API::Controller& Graphics::GetController()
-{
- if( !mGfxController )
- {
- mGfxController = Dali::Graphics::VulkanAPI::Controller::New( *this );
- }
-
- return *mGfxController;
-}
-
-bool Graphics::IsSurfaceResized() const
-{
- return mSurfaceResized;
-}
-
-// --------------------------------------------------------------------------------------------------------------
-// Depth/stencil
-bool Graphics::HasDepthEnabled() const
-{
- return mHasDepth;
-}
-
-bool Graphics::HasStencilEnabled() const
-{
- return mHasStencil;
-}
-
-// Vulkan pipeline cache
-const vk::PipelineCache& Graphics::GetVulkanPipelineCache()
-{
- if( !mVulkanPipelineCache )
- {
- mVulkanPipelineCache = mDevice.createPipelineCache( vk::PipelineCacheCreateInfo{}, GetAllocator() ).value;
- }
-
- return mVulkanPipelineCache;
-}
-
-void Graphics::AddCommandPool( RefCountedCommandPool pool )
-{
- std::lock_guard< std::mutex > lock{ mMutex };
- mCommandPools[ std::this_thread::get_id() ] = std::move(pool);
-}
-
-void Graphics::CollectGarbage()
-{
- std::lock_guard< std::mutex > lock{ mMutex };
- auto bufferIndex = (mCurrentBufferIndex+1)&1;
-
- DALI_LOG_STREAM( gVulkanFilter, Debug::General,
- "Beginning graphics garbage collection---------------------------------------" );
- DALI_LOG_INFO( gVulkanFilter, Debug::General, "Discard queue size: %ld\n", mDiscardQueue[bufferIndex].size() );
-
- // swap buffer
- if( mDiscardQueue[bufferIndex].empty() )
- {
- return;
- }
-
- for( const auto& deleter : mDiscardQueue[bufferIndex] )
- {
- deleter();
- }
- // collect what's in the queue
- mDiscardQueue[bufferIndex].clear();
-
- DALI_LOG_STREAM( gVulkanFilter, Debug::General,
- "Graphics garbage collection complete---------------------------------------" )
-}
-
-void Graphics::DiscardResource( std::function< void() > deleter )
-{
- std::lock_guard< std::mutex > lock( mMutex );
- mDiscardQueue[mCurrentBufferIndex].push_back( std::move( deleter ) );
-}
-
-const DiscardQueue& Graphics::GetDiscardQueue( uint32_t bufferIndex ) const
-{
- return mDiscardQueue[bufferIndex];
-}
-
-uint32_t Graphics::SwapBuffers()
-{
- mCurrentBufferIndex = (mCurrentBufferIndex+1)&1;
- return mCurrentBufferIndex;
-}
-
-uint32_t Graphics::GetCurrentBufferIndex()
-{
- return mCurrentBufferIndex;
-}
-
-void Graphics::CreateInstance( const std::vector< const char* >& extensions,
- const std::vector< const char* >& validationLayers )
-{
- auto info = vk::InstanceCreateInfo{};
-
- info.setEnabledExtensionCount( U32( extensions.size() ) )
- .setPpEnabledExtensionNames( extensions.data() )
- .setEnabledLayerCount( U32( validationLayers.size() ) )
- .setPpEnabledLayerNames( validationLayers.data() );
-
- const char* log_level = std::getenv( "LOG_VULKAN" );
- int intValue = log_level ? std::atoi(log_level) : 0;
- if ( !intValue )
- {
- info.setEnabledLayerCount( 0 );
- }
-
-
- mInstance = VkAssert( vk::createInstance( info, *mAllocator ) );
-}
-
-void Graphics::DestroyInstance()
-{
- if( mInstance )
- {
- mInstance.destroy( *mAllocator );
- mInstance = nullptr;
- }
-}
-
-void Graphics::PreparePhysicalDevice()
-{
- auto devices = VkAssert( mInstance.enumeratePhysicalDevices() );
- assert( !devices.empty() && "No Vulkan supported device found!" );
-
- // if only one, pick first
- mPhysicalDevice = nullptr;
- if( devices.size() == 1 )
- {
- mPhysicalDevice = devices[0];
- }
- else // otherwise look for one which is a graphics device
- {
- for( auto& device : devices )
- {
- auto properties = device.getProperties();
- if( properties.deviceType == vk::PhysicalDeviceType::eDiscreteGpu ||
- properties.deviceType == vk::PhysicalDeviceType::eIntegratedGpu )
- {
- mPhysicalDevice = device;
- break;
- }
- }
- }
-
- assert( mPhysicalDevice && "No suitable Physical Device found!" );
-
- GetPhysicalDeviceProperties();
-
- GetQueueFamilyProperties();
-}
-
-void Graphics::GetPhysicalDeviceProperties()
-{
- mPhysicalDeviceProperties = mPhysicalDevice.getProperties();
- mPhysicalDeviceMemoryProperties = mPhysicalDevice.getMemoryProperties();
- mPhysicalDeviceFeatures = mPhysicalDevice.getFeatures();
-}
-
-void Graphics::GetQueueFamilyProperties()
-{
- mQueueFamilyProperties = mPhysicalDevice.getQueueFamilyProperties();
-}
-
-std::vector< vk::DeviceQueueCreateInfo > Graphics::GetQueueCreateInfos()
-{
- std::vector< vk::DeviceQueueCreateInfo > queueInfos{};
-
- constexpr uint8_t MAX_QUEUE_TYPES = 3;
-
-
- // find suitable family for each type of queue
- auto familyIndexTypes = std::array< uint32_t, MAX_QUEUE_TYPES >{};
- familyIndexTypes.fill( std::numeric_limits< uint32_t >::max() );
-
- // Graphics
- auto& graphicsFamily = familyIndexTypes[0];
-
- // Transfer
- auto& transferFamily = familyIndexTypes[1];
-
- // Present
- auto& presentFamily = familyIndexTypes[2];
-
- auto queueFamilyIndex = 0u;
- for( auto& prop : mQueueFamilyProperties )
- {
- if( ( prop.queueFlags & vk::QueueFlagBits::eGraphics ) && graphicsFamily == -1u )
- {
- graphicsFamily = queueFamilyIndex;
-
- //@todo: in case the graphics family cannot support presentation
- // we should find the right queue family with very first surface.
- // At this point all supported platforms have general purpose queues.
- presentFamily = queueFamilyIndex;
- }
- if( ( prop.queueFlags & vk::QueueFlagBits::eTransfer ) && transferFamily == -1u )
- {
- transferFamily = queueFamilyIndex;
- }
- ++queueFamilyIndex;
- }
-
- assert( graphicsFamily != std::numeric_limits< uint32_t >::max()
- && "No queue family that supports graphics operations!" );
- assert( transferFamily != std::numeric_limits< uint32_t >::max()
- && "No queue family that supports transfer operations!" );
-
- // todo: we may require that the family must be same for all type of operations, it makes
- // easier to handle synchronisation related issues.
-
- // sort queues
- std::sort( familyIndexTypes.begin(), familyIndexTypes.end() );
-
- // allocate all queues from graphics family
- auto prevQueueFamilyIndex = std::numeric_limits< uint32_t >::max();
-
- for( const auto& familyIndex : familyIndexTypes )
- {
- if( prevQueueFamilyIndex == familyIndex )
- {
- continue;
- }
-
- auto& queueCount = mQueueFamilyProperties[familyIndex].queueCount;
-
- // fill queue create info for the family.
- // note the priorities are not being set as local pointer will out of scope, this
- // will be fixed by the caller function
- auto info = vk::DeviceQueueCreateInfo{}
- .setPQueuePriorities( nullptr )
- .setQueueCount( queueCount )
- .setQueueFamilyIndex( familyIndex );
- queueInfos.push_back( info );
- prevQueueFamilyIndex = familyIndex;
- }
-
- return queueInfos;
-}
-
-std::vector< const char* > Graphics::PrepareDefaultInstanceExtensions()
-{
- auto extensions = vk::enumerateInstanceExtensionProperties();
-
- std::string extensionName;
-
- bool xlibAvailable{ false };
- bool xcbAvailable{ false };
- bool waylandAvailable{ false };
-
- for( auto&& ext : extensions.value )
- {
- extensionName = ext.extensionName;
- if( extensionName == VK_KHR_XCB_SURFACE_EXTENSION_NAME )
- {
- xcbAvailable = true;
- }
- else if( extensionName == VK_KHR_XLIB_SURFACE_EXTENSION_NAME )
- {
- xlibAvailable = true;
- }
- else if( extensionName == VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME )
- {
- waylandAvailable = true;
- }
- }
-
- std::vector< const char* > retval{};
-
- // depending on the platform validate extensions
- auto platform = GetDefaultPlatform();
-
- if( platform != Platform::UNDEFINED )
- {
- if( platform == Platform::XCB && xcbAvailable )
- {
- retval.push_back( VK_KHR_XCB_SURFACE_EXTENSION_NAME );
- }
- else if( platform == Platform::XLIB && xlibAvailable )
- {
- retval.push_back( VK_KHR_XLIB_SURFACE_EXTENSION_NAME );
- }
- else if( platform == Platform::WAYLAND && waylandAvailable )
- {
- retval.push_back( VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME );
- /* For native image, check these exist first:
- * VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME
- * VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME
- */
- }
- }
- else // try to determine the platform based on available extensions
- {
- if( xcbAvailable )
- {
- mPlatform = Platform::XCB;
- retval.push_back( VK_KHR_XCB_SURFACE_EXTENSION_NAME );
- }
- else if( xlibAvailable )
- {
- mPlatform = Platform::XLIB;
- retval.push_back( VK_KHR_XLIB_SURFACE_EXTENSION_NAME );
- }
- else if( waylandAvailable )
- {
- mPlatform = Platform::WAYLAND;
- retval.push_back( VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME );
- /* For native image, check these exist first:
- * VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME
- * VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME
- */
- }
- else
- {
- // can't determine the platform!
- mPlatform = Platform::UNDEFINED;
- }
- }
-
- // other essential extensions
- retval.push_back( VK_KHR_SURFACE_EXTENSION_NAME );
- retval.push_back( VK_EXT_DEBUG_REPORT_EXTENSION_NAME );
-
- return retval;
-}
-
-RefCountedCommandPool Graphics::GetCommandPool( std::thread::id threadId )
-{
- auto commandPool = RefCountedCommandPool{};
-
- {
- std::lock_guard< std::mutex > lock{ mMutex };
- commandPool = mCommandPools.find( threadId ) == mCommandPools.end() ? RefCountedCommandPool()
- : mCommandPools[threadId];
- }
-
- if( !commandPool )
- {
- auto createInfo = vk::CommandPoolCreateInfo{}.setFlags( vk::CommandPoolCreateFlagBits::eResetCommandBuffer );
- commandPool = CommandPool::New( *this, createInfo );
- }
-
- return commandPool;
-}
-
-} // namespace Vulkan
-} // namespace Graphics
-} // namespace Dali
+++ /dev/null
-#ifndef DALI_GRAPHICS_VULKAN_GRAPHICS
-#define DALI_GRAPHICS_VULKAN_GRAPHICS
-
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef VULKAN_HPP_NO_EXCEPTIONS
-#define VULKAN_HPP_NO_EXCEPTIONS
-#endif
-
-// INTERNAL INCLUDES
-#include <dali/integration-api/graphics/surface-factory.h>
-#include <dali/graphics/vulkan/internal/vulkan-types.h>
-#include <dali/graphics/vulkan/internal/vulkan-queue.h>
-#include <dali/integration-api/graphics/graphics.h>
-
-#include <thread>
-#include <mutex>
-#include <map>
-#include <functional>
-
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace API
-{
-class Controller;
-}
-namespace VulkanAPI
-{
-class Controller;
-}
-
-namespace Vulkan
-{
-
-class Buffer;
-
-class Image;
-
-class Pipeline;
-
-class Shader;
-
-class Framebuffer;
-
-class Surface;
-
-class CommandPool;
-
-class GpuMemoryManager;
-
-class FramebufferAttachment;
-
-class Memory
-{
- friend class Graphics;
-
-private:
-
- Memory( Graphics* graphics, vk::DeviceMemory deviceMemory, size_t memSize, size_t memAlign, bool hostVisible );
-
-public:
-
- ~Memory();
-
- template<class T>
- T* MapTyped()
- {
- return reinterpret_cast<T*>(Map());
- }
-
- Memory(Memory&) = delete;
- Memory& operator=(Memory&) = delete;
-
- void* Map();
-
- void* Map( uint32_t offset, uint32_t size );
-
- void Unmap();
-
- void Flush();
-
- /**
- * Releases vk::DeviceMemory object so it can be deleted
- * externally
- * @return
- */
- vk::DeviceMemory ReleaseVkObject();
-
- vk::DeviceMemory GetVkHandle() const;
-
-private:
- Graphics* graphics;
- vk::DeviceMemory memory;
- size_t size;
- size_t alignment;
- void* mappedPtr;
- size_t mappedSize;
- bool hostVisible;
-};
-
-using Dali::Integration::Graphics::SurfaceFactory;
-using CommandPoolMap = std::unordered_map< std::thread::id, RefCountedCommandPool >;
-
-struct SwapchainSurfacePair
-{
- RefCountedSwapchain swapchain;
- RefCountedSurface surface;
-};
-
-using DiscardQueue = std::vector< std::function< void() > >;
-
-class Graphics
-{
-
-public:
- Graphics();
-
- Graphics( const Graphics& ) = delete;
-
- Graphics& operator=( const Graphics& ) = delete;
-
- ~Graphics();
-
-public: // Create methods
-
- void Create();
-
- void CreateDevice();
-
- void InitialiseController();
-
- FBID CreateSurface( SurfaceFactory& surfaceFactory,
- const Integration::Graphics::GraphicsCreateInfo& createInfo );
-
- RefCountedSwapchain CreateSwapchainForSurface( RefCountedSurface surface );
-
- RefCountedSwapchain ReplaceSwapchainForSurface( RefCountedSurface surface, RefCountedSwapchain&& oldSwapchain);
-
- RefCountedFence CreateFence( const vk::FenceCreateInfo& fenceCreateInfo );
-
- RefCountedBuffer CreateBuffer( size_t size, vk::BufferUsageFlags usageFlags );
-
- RefCountedBuffer CreateBuffer( const vk::BufferCreateInfo& bufferCreateInfo );
-
-
-
- RefCountedFramebuffer CreateFramebuffer( const std::vector< RefCountedFramebufferAttachment >& colorAttachments,
- RefCountedFramebufferAttachment depthAttachment,
- uint32_t width,
- uint32_t height,
- vk::RenderPass externalRenderPass = nullptr );
-
- RefCountedImage CreateImage( const vk::ImageCreateInfo& imageCreateInfo );
-
- RefCountedImage CreateImageFromExternal( vk::Image externalImage, vk::Format imageFormat, vk::Extent2D extent );
-
- RefCountedImageView CreateImageView( const vk::ImageViewCreateFlags& flags,
- const RefCountedImage& image,
- vk::ImageViewType viewType,
- vk::Format format,
- vk::ComponentMapping components,
- vk::ImageSubresourceRange subresourceRange );
-
- RefCountedImageView CreateImageView( RefCountedImage image );
-
- RefCountedSampler CreateSampler( const vk::SamplerCreateInfo& samplerCreateInfo );
-
- RefCountedCommandBuffer CreateCommandBuffer( bool primary );
-
- vk::ImageMemoryBarrier CreateImageMemoryBarrier( RefCountedImage image,
- vk::ImageLayout oldLayout,
- vk::ImageLayout newLayout );
-
- RefCountedSwapchain CreateSwapchain( RefCountedSurface surface, vk::Format requestedFormat,
- vk::PresentModeKHR presentMode,
- uint32_t bufferCount, RefCountedSwapchain&& oldSwapchain );
-
- vk::RenderPass CreateCompatibleRenderPass( const std::vector< RefCountedFramebufferAttachment >& colorAttachments,
- RefCountedFramebufferAttachment depthAttachment,
- std::vector<vk::ImageView>& attachments);
-
-public: // Actions
- vk::Result WaitForFence( RefCountedFence fence, uint32_t timeout = std::numeric_limits< uint32_t >::max() );
-
- vk::Result WaitForFences( const std::vector< RefCountedFence >& fences,
- bool waitAll = true,
- uint32_t timeout = std::numeric_limits< uint32_t >::max() );
-
- vk::Result ResetFence( RefCountedFence fence );
-
- vk::Result ResetFences( const std::vector< RefCountedFence >& fences );
-
- vk::Result BindImageMemory( RefCountedImage image,std::unique_ptr<Memory> memory, uint32_t offset );
-
- vk::Result BindBufferMemory( RefCountedBuffer buffer, std::unique_ptr<Memory> memory, uint32_t offset );
-
- void* MapMemory( Memory* memory ) const;
-
- void* MapMemory( Memory* memory, uint32_t size, uint32_t offset ) const;
-
- void UnmapMemory( Memory* memory ) const;
-
- template< typename T >
- T* MapMemoryTyped( Memory* memory ) const
- {
- return memory->MapTyped<T>();
- }
-
- std::unique_ptr<Memory> AllocateMemory( RefCountedBuffer buffer, vk::MemoryPropertyFlags memoryProperties );
-
- std::unique_ptr<Memory> AllocateMemory( RefCountedImage image, vk::MemoryPropertyFlags memoryProperties );
-
- vk::Result Submit( Queue& queue, const std::vector< SubmissionData >& submissionData, RefCountedFence fence );
-
- vk::Result Present( Queue& queue, vk::PresentInfoKHR presentInfo );
-
- vk::Result QueueWaitIdle( Queue& queue );
-
- vk::Result DeviceWaitIdle();
-
- void SurfaceResized( unsigned int width, unsigned int height );
-
-public: // Getters
- RefCountedSurface GetSurface( FBID surfaceId );
-
- RefCountedSwapchain GetSwapchainForSurface( RefCountedSurface surface );
-
- RefCountedSwapchain GetSwapchainForFBID( FBID surfaceId );
-
- vk::Device GetDevice() const;
-
- vk::PhysicalDevice GetPhysicalDevice() const;
-
- vk::Instance GetInstance() const;
-
- const vk::AllocationCallbacks& GetAllocator( const char* tag = nullptr );
-
- const vk::PhysicalDeviceMemoryProperties& GetMemoryProperties() const;
-
- Queue& GetGraphicsQueue( uint32_t index = 0u ) const;
-
- Queue& GetTransferQueue( uint32_t index = 0u ) const;
-
- Queue& GetComputeQueue( uint32_t index = 0u ) const;
-
- Queue& GetPresentQueue() const;
-
- Platform GetDefaultPlatform() const;
-
- Dali::Graphics::API::Controller& GetController();
-
- const vk::PipelineCache& GetVulkanPipelineCache();
-
- bool HasDepthEnabled() const;
-
- bool HasStencilEnabled() const;
-
- bool IsSurfaceResized() const;
-
-public: //Cache management methods
-
- void AddCommandPool( RefCountedCommandPool pool );
-
- void CollectGarbage();
-
- void DiscardResource( std::function< void() > deleter );
-
- const DiscardQueue& GetDiscardQueue( uint32_t bufferIndex ) const;
-
- uint32_t SwapBuffers();
-
- uint32_t GetCurrentBufferIndex();
-
-private: // Methods
-
- void CreateInstance( const std::vector< const char* >& extensions,
- const std::vector< const char* >& validationLayers );
-
- void DestroyInstance();
-
- void PreparePhysicalDevice();
-
- void GetPhysicalDeviceProperties();
-
- void GetQueueFamilyProperties();
-
- std::vector< vk::DeviceQueueCreateInfo > GetQueueCreateInfos();
-
- std::vector< const char* > PrepareDefaultInstanceExtensions();
-
- RefCountedCommandPool GetCommandPool( std::thread::id threadId );
-
-private: // Members
-
- // physical device
- vk::PhysicalDevice mPhysicalDevice;
-
- // logical device
- vk::Device mDevice;
-
- vk::Instance mInstance;
-
- // physical device properties
- vk::PhysicalDeviceProperties mPhysicalDeviceProperties;
- vk::PhysicalDeviceMemoryProperties mPhysicalDeviceMemoryProperties;
- vk::PhysicalDeviceFeatures mPhysicalDeviceFeatures;
-
- std::unique_ptr< vk::AllocationCallbacks > mAllocator{ nullptr };
-
- // queue family properties
- std::vector< vk::QueueFamilyProperties > mQueueFamilyProperties;
-
- // Sets of queues
- std::vector< std::unique_ptr< Queue > > mAllQueues;
- std::vector< Queue* > mGraphicsQueues;
- std::vector< Queue* > mTransferQueues;
- std::vector< Queue* > mComputeQueues;
-
- std::unordered_map< FBID, SwapchainSurfacePair > mSurfaceFBIDMap;
- FBID mBaseFBID{ 0u };
-
- Platform mPlatform{ Platform::UNDEFINED };
-
- std::mutex mMutex;
-
- std::unique_ptr< Dali::Graphics::VulkanAPI::Controller > mGfxController;
-
- // Command pool map using thread IDs as keys
- CommandPoolMap mCommandPools;
-
- DiscardQueue mDiscardQueue[2u];
-
- bool mHasDepth { false };
- bool mHasStencil { false };
-
- vk::PipelineCache mVulkanPipelineCache;
-
- bool mSurfaceResized { false };
-
- uint32_t mCurrentBufferIndex{ 0u };
-
- bool mDisableNativeImage { false };
-};
-
-} // namespace Vulkan
-} // namespace Graphics
-} // namespace Dali
-
-#endif // DALI_GRAPHICS_VULKAN_GRAPHICS
/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali/integration-api/events/event.h>
#include <dali/integration-api/debug.h>
#include <dali/integration-api/graphics/graphics-interface.h>
-#include <dali/integration-api/graphics/graphics.h>
#include <dali/internal/common/core-impl.h>
+using Dali::Integration::Graphics::GraphicsInterface;
+
namespace Dali
{
-
namespace Integration
{
Core* Core::New( RenderController& renderController,
PlatformAbstraction& platformAbstraction,
- Graphics::GraphicsInterface& graphics,
+ GraphicsInterface& graphics,
GestureManager& gestureManager,
ResourcePolicy::DataRetention policy,
RenderToFrameBuffer renderToFboEnabled,
Core* instance = new Core;
instance->mImpl = new Internal::Core( renderController,
platformAbstraction,
- static_cast<Integration::Graphics::Graphics&>(graphics),
+ graphics,
gestureManager,
policy,
renderToFboEnabled,
$(platform_abstraction_src_dir)/events/touch-event-combiner.h \
$(platform_abstraction_src_dir)/events/touch-event-integ.h
-graphics_integration_src_files = \
- $(platform_abstraction_src_dir)/graphics/graphics.cpp
-
graphics_integration_header_files = \
- $(platform_abstraction_src_dir)/graphics/graphics.h \
- $(platform_abstraction_src_dir)/graphics/graphics-interface.h \
- $(platform_abstraction_src_dir)/graphics/surface-factory.h
-
-graphics_vulkan_integration_header_files = \
- $(platform_abstraction_src_dir)/graphics/vulkan/vk-surface-factory.h \
- $(platform_abstraction_src_dir)/graphics/vulkan/vulkan-hpp-wrapper.h
+ $(platform_abstraction_src_dir)/graphics/graphics-interface.h
+++ /dev/null
-# Add graphics integration source files here
-
-graphics_integration_src_files = \
- $(graphics_integration_dir)/graphics.cpp
#define DALI_INTEGRATION_GRAPHICS_INTERFACE_H
/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali/public-api/common/dali-common.h>
#include <dali/integration-api/core-enumerations.h>
+#include <dali/graphics-api/graphics-api-controller.h>
namespace Dali
{
namespace Graphics
{
+enum class DepthStencilMode
+{
+ /**
+ * No depth/stencil at all
+ */
+ NONE,
+
+ /**
+ * Optimal depth ( chosen by the implementation )
+ */
+ DEPTH_OPTIMAL,
+
+ /**
+ * Optimal depth and stencil ( chosen by the implementation )
+ */
+ DEPTH_STENCIL_OPTIMAL,
+
+ /**
+ * Depth and stencil with explicit format set in depthStencilFormat
+ */
+ DEPTH_STENCIL_EXPLICIT,
+};
+
+enum class SwapchainBufferingMode
+{
+ OPTIMAL = 0,
+ DOUBLE_BUFFERING = 2,
+ TRIPLE_BUFFERING = 3,
+};
+
+struct GraphicsCreateInfo
+{
+ uint32_t surfaceWidth;
+ uint32_t surfaceHeight;
+ DepthStencilMode depthStencilMode;
+ SwapchainBufferingMode swapchainBufferingMode;
+};
+
+
/**
* Graphics interface
*/
/**
* Constructor
*/
- GraphicsInterface( Integration::DepthBufferAvailable depthBufferRequired,
+ GraphicsInterface( const GraphicsCreateInfo& info,
+ Integration::DepthBufferAvailable depthBufferRequired,
Integration::StencilBufferAvailable stencilBufferRequired )
- : mDepthBufferRequired( depthBufferRequired ),
+ : mCreateInfo( info ),
+ mDepthBufferRequired( depthBufferRequired ),
mStencilBufferRequired( stencilBufferRequired )
{
- };
+ }
+
/**
* Initialize the graphics interface
*/
virtual void PostRender() = 0;
+ /**
+ * Returns controller object
+ * @return
+ */
+ virtual Dali::Graphics::API::Controller& GetController() = 0;
+
+ /*
+ * Surface resized
+ */
+ virtual void SurfaceResized( unsigned int width, unsigned int height ) = 0;
+
/**
* Get whether the depth buffer is required
* @return TRUE if the depth buffer is required
protected:
// No destruction through this interface
- ~GraphicsInterface() = default;
+ virtual ~GraphicsInterface() = default;
protected:
+ GraphicsCreateInfo mCreateInfo;
const Integration::DepthBufferAvailable mDepthBufferRequired; ///< Whether the depth buffer is required
const Integration::StencilBufferAvailable mStencilBufferRequired; ///< Whether the stencil buffer is required
};
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/graphics/vulkan/internal/vulkan-types.h>
-#include <dali/graphics/vulkan/vulkan-graphics.h>
-#include <dali/graphics/vulkan/internal/vulkan-surface.h>
-#include <dali/graphics/vulkan/internal/vulkan-framebuffer.h>
-#include <dali/graphics-api/graphics-api-controller.h>
-#include <dali/integration-api/graphics/graphics.h>
-#include <dali/graphics/vulkan/internal/vulkan-swapchain.h>
-
-extern "C" std::vector<uint32_t> GraphicsGetBuiltinShader( const std::string& tag );
-
-namespace Dali
-{
-/// fixme: substituting directly the vulkan implementation
-namespace Graphics
-{
-using GraphicsImpl = Dali::Graphics::Vulkan::Graphics;
-}
-
-namespace Integration
-{
-namespace Graphics
-{
-
-Surface::Surface( Dali::Graphics::GraphicsImpl* graphicsImpl, Dali::Graphics::FBID fbid )
- : mGraphicsImpl( graphicsImpl ),
- frambufferId( fbid )
-{
-}
-
-Surface::~Surface()
-{
- if( auto surface = mGraphicsImpl->GetSurface( frambufferId ) )
- {
- mGraphicsImpl->DeviceWaitIdle();
- auto swapchain = mGraphicsImpl->GetSwapchainForFBID( frambufferId );
- swapchain->Destroy();
- surface->Destroy();
- mGraphicsImpl->CollectGarbage();
- }
-}
-
-using Dali::Integration::Graphics::SurfaceFactory;
-
-Graphics::Graphics( const GraphicsCreateInfo& info,
- Integration::DepthBufferAvailable depthBufferAvailable,
- Integration::StencilBufferAvailable stencilBufferRequired )
-: GraphicsInterface( depthBufferAvailable, stencilBufferRequired ),
- mCreateInfo( info )
-{
- // create device
- auto impl = Dali::Graphics::MakeUnique<Dali::Graphics::GraphicsImpl>();
-
- mGraphicsImpl = std::move(impl);
-}
-
-Graphics::~Graphics() = default;
-
-
-void Graphics::Initialize()
-{
-}
-
-void Graphics::Create()
-{
- mGraphicsImpl->Create();
-
- // create device
- mGraphicsImpl->CreateDevice();
-
- // initialise controller
- mGraphicsImpl->InitialiseController();
-}
-
-std::unique_ptr<Surface> Graphics::CreateSurface( SurfaceFactory& surfaceFactory)
-{
- // create surface ( also takes surface factory ownership )
- auto retval = mGraphicsImpl->CreateSurface( surfaceFactory, mCreateInfo );
-
- // create swapchain from surface
- auto surface = mGraphicsImpl->GetSurface( retval );
-
- // create swapchain
- mGraphicsImpl->CreateSwapchainForSurface( surface );
-
- return std::unique_ptr<Surface>( new Surface( mGraphicsImpl.get(), retval ) );
-}
-
-void Graphics::Destroy()
-{
-}
-
-void Graphics::Pause()
-{
- mGraphicsImpl->GetController().Pause();
-}
-
-void Graphics::Resume()
-{
- mGraphicsImpl->GetController().Resume();
-}
-
-void Graphics::PreRender()
-{
- auto swapchain = mGraphicsImpl->GetSwapchainForFBID( 0u );
- swapchain->AcquireNextFramebuffer();
-}
-
-void Graphics::PostRender()
-{
- auto swapchain = mGraphicsImpl->GetSwapchainForFBID( 0u );
- swapchain->Present();
-
- mGraphicsImpl->CollectGarbage();
-}
-
-Dali::Graphics::API::Controller& Graphics::GetController()
-{
- return mGraphicsImpl->GetController();
-}
-
-void Graphics::SurfaceResized( unsigned int width, unsigned int height )
-{
- mCreateInfo.surfaceWidth = width;
- mCreateInfo.surfaceHeight = height;
-
- mGraphicsImpl->SurfaceResized( width, height );
-}
-
-void IncludeThisLibrary()
-{
- // dummy function to create linker dependency
- //GraphicsGetBuiltinShader("");
-}
-
-} // Namespace Graphics
-} // Namespace Integration
-} // Namespace Dali
+++ /dev/null
-#ifndef DALI_INTEGRATION_GRAPHICS_H
-#define DALI_INTEGRATION_GRAPHICS_H
-
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// INTERNAL INCLUDES
-#include <dali/integration-api/graphics/graphics-interface.h>
-
-// EXTERNAL INCLUDES
-#include <memory>
-
-#define EXPORT_API __attribute__ ((visibility ("default")))
-
-namespace Dali
-{
-namespace Graphics
-{
-namespace API
-{
-class Controller;
-} // API
-
-// frame buffer id
-using FBID = int32_t;
-
-namespace Vulkan
-{
-class Graphics;
-} // Vulkan
-using GraphicsImpl = Vulkan::Graphics;
-
-} // Graphics
-
-namespace Integration
-{
-namespace Graphics
-{
-class SurfaceFactory;
-struct EXPORT_API Surface
-{
- Surface( Dali::Graphics::GraphicsImpl* graphicsImpl, Dali::Graphics::FBID fbid );
- ~Surface();
- Dali::Graphics::GraphicsImpl* mGraphicsImpl;
- Dali::Graphics::FBID frambufferId;
-};
-
-enum class DepthStencilMode
-{
- /**
- * No depth/stencil at all
- */
- NONE,
-
- /**
- * Optimal depth ( chosen by the implementation )
- */
- DEPTH_OPTIMAL,
-
- /**
- * Optimal depth and stencil ( chosen by the implementation )
- */
- DEPTH_STENCIL_OPTIMAL,
-
- /**
- * Depth and stencil with explicit format set in depthStencilFormat
- */
- DEPTH_STENCIL_EXPLICIT,
-};
-
-enum class SwapchainBufferingMode
-{
- OPTIMAL = 0,
-
- DOUBLE_BUFFERING = 2,
-
- TRIPLE_BUFFERING = 3,
-};
-
-struct GraphicsCreateInfo
-{
- uint32_t surfaceWidth;
- uint32_t surfaceHeight;
- DepthStencilMode depthStencilMode;
- SwapchainBufferingMode swapchainBufferingMode;
-};
-
-/**
- * Graphics implementation class
- */
-class EXPORT_API Graphics final : public GraphicsInterface
-{
-public:
-
- Graphics( const GraphicsCreateInfo& info,
- Integration::DepthBufferAvailable depthBufferAvailable,
- Integration::StencilBufferAvailable stencilBufferRequired );
-
- ~Graphics();
-
- void Initialize() override;
-
- /**
- *
- * @param surfaceFactory
- * @return
- */
- std::unique_ptr<Surface> CreateSurface( SurfaceFactory& surfaceFactory );
-
- /**
- * When creating Graphics at least one surfaceFactory must be supplied ( no headless mode )
- * @param surfaceFactory the surface factory.
- *
- * @note This should be called from the render thread
- */
- void Create() override;
-
- void Destroy() override;
-
- /**
- * Lifecycle event for pausing application
- */
- void Pause() override;
-
- /**
- * Lifecycle event for resuming application
- */
- void Resume() override;
-
- /**
- * Prerender
- */
- void PreRender() override;
-
- /*
- * Postrender
- */
- void PostRender() override;
-
- /**
- * Returns controller object
- * @return
- */
- Dali::Graphics::API::Controller& GetController();
-
- /*
- * Surface resized
- */
- void SurfaceResized( unsigned int width, unsigned int height );
-
- // this function is used only by the standalone test
- template <class T>
- T& GetImplementation() const
- {
- return static_cast<T&>(*mGraphicsImpl.get());
- }
-
- GraphicsCreateInfo& GetCreateInfo()
- {
- return mCreateInfo;
- }
-
-private:
- GraphicsCreateInfo mCreateInfo;
- std::unique_ptr<Dali::Graphics::GraphicsImpl> mGraphicsImpl;
-};
-
-namespace GraphicsFactory
-{
-/**
- * Creates new instance of Graphics integration object
- * @param info
- * @return
- */
-std::unique_ptr<Dali::Integration::Graphics::Graphics> Create( const GraphicsCreateInfo& info );
-}
-
-/**
- * fixme: dummy function to make sure the static library won't be discarded entirely during linking
- */
-EXPORT_API void IncludeThisLibrary();
-
-} // Namespace Graphics
-} // Namespace Integration
-} // Namespace Dali
-
-#endif // DALI_INTEGRATION_GRAPHICS_H
+++ /dev/null
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef DALI_INTEGRATION_GRAPHICS_SURFACE_FACTORY_H
-#define DALI_INTEGRATION_GRAPHICS_SURFACE_FACTORY_H
-
-namespace Dali
-{
-namespace Integration
-{
-namespace Graphics
-{
-
-class SurfaceFactory
-{
-public:
- SurfaceFactory() = default;
- virtual ~SurfaceFactory() = default;
-
- SurfaceFactory( const SurfaceFactory& ) = delete;
- SurfaceFactory& operator=( const SurfaceFactory& ) = delete;
-};
-
-} // Namespace Graphics
-} // Namespace Integration
-} // Namespace Dali
-
-#endif // DALI_INTEGRATION_GRAPHICS_SURFACE_FACTORY_H
+++ /dev/null
-#ifndef DALI_GRAPHICS_VULKAN_VKSURFACEFACTORY_H
-#define DALI_GRAPHICS_VULKAN_VKSURFACEFACTORY_H
-
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// EXTERNAL INCLUDES
-#include <dali/integration-api/graphics/vulkan/vulkan-hpp-wrapper.h>
-
-// INTERNAL INCLUDES
-#include <dali/integration-api/graphics/surface-factory.h>
-
-
-namespace Dali
-{
-namespace Integration
-{
-namespace Graphics
-{
-namespace Vulkan
-{
-
-class VkSurfaceFactory : public SurfaceFactory
-{
-public:
-
- VkSurfaceFactory() = default;
-
- virtual vk::SurfaceKHR Create( vk::Instance instance,
- const vk::AllocationCallbacks* allocCallbacks,
- vk::PhysicalDevice physicalDevice ) const = 0;
-};
-
-} // namespace Vulkan
-} // namespace Graphics
-} // namespace Integration
-} // namespace Dali
-
-#endif // DALI_GRAPHICS_VULKAN_VKSURFACEFACTORY_H
+++ /dev/null
-#ifndef DALI_GRAPHICS_VULKAN_HPP_WRAPPER_H
-#define DALI_GRAPHICS_VULKAN_HPP_WRAPPER_H
-
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// Vulkan without exceptions
-#ifndef VULKAN_HPP_NO_EXCEPTIONS
-#define VULKAN_HPP_NO_EXCEPTIONS
-#endif
-
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wfloat-equal"
-#pragma GCC diagnostic ignored "-Wswitch-enum"
-#include <vulkan/vulkan.hpp>
-#pragma GCC diagnostic pop
-
-#endif // DALI_GRAPHICS_VULKAN_HPP_WRAPPER_H
/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali/integration-api/core.h>
#include <dali/integration-api/debug.h>
#include <dali/integration-api/events/event.h>
-#include <dali/integration-api/graphics/graphics.h>
+#include <dali/integration-api/graphics/graphics-interface.h>
#include <dali/integration-api/platform-abstraction.h>
#include <dali/integration-api/render-controller.h>
#include <dali/integration-api/system-overlay.h>
using Integration::Event;
using Integration::UpdateStatus;
using Integration::RenderStatus;
-using Integration::Graphics::Graphics;
+using Integration::Graphics::GraphicsInterface;
Core::Core( RenderController& renderController,
PlatformAbstraction& platform,
- Graphics& graphics,
+ GraphicsInterface& graphics,
GestureManager& gestureManager,
ResourcePolicy::DataRetention dataRetentionPolicy,
Integration::RenderToFrameBuffer renderToFboEnabled,
mProcessingEvent(false),
mGraphics(graphics)
{
- // fixme: for now to ensure libgraphics.a won't be removed during linking due to being
- Integration::Graphics::IncludeThisLibrary();
-
// Create the thread local storage
CreateThreadLocalStorage();
#define DALI_INTERNAL_CORE_H
/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali/public-api/object/ref-object.h>
#include <dali/integration-api/core-enumerations.h>
+#include <dali/integration-api/graphics/graphics-interface.h>
#include <dali/integration-api/resource-policies.h>
#include <dali/internal/common/owner-pointer.h>
#include <dali/internal/event/animation/animation-playlist-declarations.h>
namespace Integration
{
-namespace Graphics
-{
-class Graphics;
-}
class Processor;
class RenderController;
class PlatformAbstraction;
*/
Core( Integration::RenderController& renderController,
Integration::PlatformAbstraction& platform,
- Integration::Graphics::Graphics& graphics,
+ Integration::Graphics::GraphicsInterface& graphics,
Integration::GestureManager& gestureManager,
ResourcePolicy::DataRetention dataRetentionPolicy,
Integration::RenderToFrameBuffer renderToFboEnabled,
OwnerPointer<EventProcessor> mEventProcessor; ///< The event processor
Dali::Vector<Integration::Processor*> mProcessors; ///< Registered processors (not owned)
- Integration::Graphics::Graphics& mGraphics; ///< Graphics object
+ Integration::Graphics::GraphicsInterface& mGraphics; ///< Graphics object
friend class ThreadLocalStorage;
#define DALI_INTERNAL_SAMPLER_H
/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali/internal/event/common/connectable.h> // Dali::Internal::Connectable
#include <dali/internal/event/common/object-connector.h> // Dali::Internal::ObjectConnector
#include <dali/internal/event/common/object-impl.h> // Dali::Internal::Object
-#include <dali/integration-api/graphics/graphics.h> // Graphics interface
namespace Dali
{
#include <dali/integration-api/core.h>
#include <dali/integration-api/debug.h>
#include <dali/integration-api/render-controller.h>
-#include <dali/integration-api/graphics/graphics.h>
+#include <dali/integration-api/graphics/graphics-interface.h>
#include <dali/devel-api/common/owner-container.h>
#include <dali/devel-api/threading/mutex.h>
using namespace Dali::Integration;
using Dali::Internal::Update::MessageQueue;
+using Dali::Integration::Graphics::GraphicsInterface;
namespace Dali
{
RenderController& renderController,
SceneGraphBuffers& sceneGraphBuffers,
RenderTaskProcessor& renderTaskProcessor,
- Integration::Graphics::Graphics& graphics )
+ GraphicsInterface& graphics )
: notificationManager( notificationManager ),
transformManager(),
animationPlaylist( animationPlaylist ),
RenderInstructionContainer renderInstructions; ///< List of current instructions per frame
RenderTaskProcessor& renderTaskProcessor; ///< Handles RenderTasks and RenderInstrucitons
- Integration::Graphics::Graphics& graphics; ///< Graphics
+ GraphicsInterface& graphics; ///< Graphics
Vector4 backgroundColor; ///< The glClear color used at the beginning of each frame.
DiscardQueue& discardQueue,
RenderController& controller,
RenderTaskProcessor& renderTaskProcessor,
- Integration::Graphics::Graphics& graphics )
+ GraphicsInterface& graphics )
: mImpl( new Impl( notificationManager,
animationFinishedNotifier,
propertyNotifier,
#define DALI_INTERNAL_SCENE_GRAPH_UPDATE_MANAGER_H
/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali/public-api/common/vector-wrapper.h>
#include <dali/devel-api/common/stage-devel.h>
+#include <dali/integration-api/graphics/graphics-interface.h>
#include <dali/internal/common/message.h>
namespace Integration
{
class RenderController;
-namespace Graphics
-{
-class Graphics;
-}
} // namespace Integration
namespace Internal
* @param[in] discardQueue Nodes are added here when disconnected from the scene-graph.
* @param[in] controller After messages are flushed, we request a render from the RenderController.
* @param[in] renderTaskProcessor Handles RenderTasks and RenderInstrucitons.
+ * @param[in] graphics The graphics backend
*/
UpdateManager( NotificationManager& notificationManager,
CompleteNotificationInterface& animationPlaylist,
DiscardQueue& discardQueue,
Integration::RenderController& controller,
RenderTaskProcessor& renderTaskProcessor,
- Dali::Integration::Graphics::Graphics& graphics);
+ Dali::Integration::Graphics::GraphicsInterface& graphics);
/**
* Destructor.
/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
FrameBuffer::~FrameBuffer() = default;
-void FrameBuffer::Initialize( Integration::Graphics::Graphics& graphics )
+void FrameBuffer::Initialize( Integration::Graphics::GraphicsInterface& graphics )
{
mGraphics = &graphics;
// Defer creation of framebuffer until a render instruction uses it
#define DALI_INTERNAL_SCENE_GRAPH_FRAME_BUFFER_H
/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* @param[in] graphics The Graphics API
*/
- void Initialize( Integration::Graphics::Graphics& graphics );
+ void Initialize( Integration::Graphics::GraphicsInterface& graphics );
/**
* @brief Attach a texture for color rendering. Valid only for Framebuffers with COLOR attachments.
void DestroyGraphicsObjects();
private:
- Integration::Graphics::Graphics* mGraphics; ///< Graphics interface object
+ Integration::Graphics::GraphicsInterface* mGraphics; ///< Graphics interface object
std::unique_ptr<Graphics::API::Framebuffer> mGraphicsFramebuffer;
struct Attachment
/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
{
}
-void Geometry::Initialize( Integration::Graphics::Graphics& graphics )
+void Geometry::Initialize( Integration::Graphics::GraphicsInterface& graphics )
{
mGraphics = &graphics;
}
#define DALI_INTERNAL_SCENE_GRAPH_GEOMETRY_H
/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali/public-api/rendering/geometry.h>
#include <dali/devel-api/common/owner-container.h>
#include <dali/graphics-api/graphics-api-controller.h>
-#include <dali/integration-api/graphics/graphics.h>
+#include <dali/integration-api/graphics/graphics-interface.h>
#include <dali/internal/common/message.h>
#include <dali/internal/common/owner-pointer.h>
#include <dali/internal/common/buffer-index.h>
*
* @param[in] graphics The Graphics API
*/
- void Initialize( Integration::Graphics::Graphics& graphics );
+ void Initialize( Integration::Graphics::GraphicsInterface& graphics );
/**
* Adds a property buffer to the geometry
}
private:
- Integration::Graphics::Graphics* mGraphics; ///< Graphics interface object
+ Integration::Graphics::GraphicsInterface* mGraphics; ///< Graphics interface object
// PropertyBuffers
Vector< SceneGraph::PropertyBuffer* > mVertexBuffers;
/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
{
}
-void PropertyBuffer::Initialize( Integration::Graphics::Graphics& graphics )
+void PropertyBuffer::Initialize( Integration::Graphics::GraphicsInterface& graphics )
{
mGraphics = &graphics;
}
#define DALI_INTERNAL_SCENE_GRAPH_PROPERTY_BUFFER_H
/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali/public-api/common/vector-wrapper.h>
#include <dali/public-api/rendering/sampler.h>
#include <dali/graphics-api/graphics-api-buffer.h>
-#include <dali/integration-api/graphics/graphics.h>
+#include <dali/integration-api/graphics/graphics-interface.h>
#include <dali/internal/common/message.h>
#include <dali/internal/common/owner-pointer.h>
#include <dali/internal/event/common/event-thread-services.h>
*
* @param[in] graphics The Graphics API
*/
- void Initialize( Integration::Graphics::Graphics& graphics );
+ void Initialize( Integration::Graphics::GraphicsInterface& graphics );
/**
* @brief Set the format of the buffer
}
private:
- Integration::Graphics::Graphics* mGraphics; ///< Graphics interface object
+ Integration::Graphics::GraphicsInterface* mGraphics; ///< Graphics interface object
OwnerPointer< PropertyBuffer::Format > mFormat; ///< Format of the buffer
OwnerPointer< Dali::Vector< uint8_t > > mData; ///< Data
/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
gRendererMemoryPool.FreeThreadSafe( static_cast<Renderer*>( ptr ) );
}
-void Renderer::Initialize( Integration::Graphics::Graphics& graphics )
+void Renderer::Initialize( Integration::Graphics::GraphicsInterface& graphics )
{
mGraphics = &graphics;
#define DALI_INTERNAL_SCENE_GRAPH_RENDERER_H
/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali/public-api/rendering/geometry.h>
#include <dali/public-api/rendering/renderer.h> // Dali::Renderer
-#include <dali/integration-api/graphics/graphics.h>
+#include <dali/integration-api/graphics/graphics-interface.h>
#include <dali/internal/common/blending-options.h>
#include <dali/internal/common/type-abstraction-enums.h>
#include <dali/internal/event/common/event-thread-services.h>
*
* @param[in] graphics The Graphics API
*/
- void Initialize( Integration::Graphics::Graphics& graphics );
+ void Initialize( Integration::Graphics::GraphicsInterface& graphics );
/**
* Set the texture set for the renderer
Renderer();
private:
- Integration::Graphics::Graphics* mGraphics; ///< Graphics interface object
+ Integration::Graphics::GraphicsInterface* mGraphics; ///< Graphics interface object
CollectedUniformMap mCollectedUniformMap[2]; ///< Uniform maps collected by the renderer
TextureSet* mTextureSet; ///< The texture set this renderer uses. (Not owned)
#define DALI_INTERNAL_SCENE_GRAPH_SAMPLER_H
/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali/internal/event/common/event-thread-services.h>
#include <dali/graphics-api/graphics-api-controller.h>
#include <dali/graphics-api/graphics-api-types.h>
-#include <dali/integration-api/graphics/graphics.h>
+#include <dali/integration-api/graphics/graphics-interface.h>
#include <memory>
return {};
}
- void Initialize( Integration::Graphics::Graphics& graphics )
+ void Initialize( Integration::Graphics::GraphicsInterface& graphics )
{
mGraphics = &graphics;
mGfxSampler.reset( nullptr );
);
}
- Integration::Graphics::Graphics* mGraphics; ///< Graphics interface
+ Integration::Graphics::GraphicsInterface* mGraphics; ///< Graphics interface
std::unique_ptr<Dali::Graphics::API::Sampler> mGfxSampler; ///< Graphics Sampler object, default sampler is nullptr
FilterMode mMinificationFilter : 4; ///< The minify filter
/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
mConnectionObservers.Destroy( *this );
}
-void Shader::Initialize( Integration::Graphics::Graphics& graphics, ShaderCache& shaderCache )
+void Shader::Initialize( Integration::Graphics::GraphicsInterface& graphics, ShaderCache& shaderCache )
{
mGraphics = &graphics;
mShaderCache = &shaderCache;
#define __DALI_INTERNAL_SCENE_GRAPH_SHADER_H__
/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali/graphics-api/graphics-api-controller.h>
#include <dali/graphics-api/graphics-api-shader.h>
-#include <dali/integration-api/graphics/graphics.h>
+#include <dali/integration-api/graphics/graphics-interface.h>
#include <dali/internal/common/message.h>
#include <dali/internal/common/shader-data.h>
* @param[in] graphics The Graphics API
* @param[in] shaderCache A cache
*/
- void Initialize( Integration::Graphics::Graphics& graphics, ShaderCache& shaderCache );
+ void Initialize( Integration::Graphics::GraphicsInterface& graphics, ShaderCache& shaderCache );
/**
* Query whether a shader hint is set.
void BuildReflection();
private: // Data
- Integration::Graphics::Graphics* mGraphics; ///< Graphics interface object
+ Integration::Graphics::GraphicsInterface* mGraphics; ///< Graphics interface object
Graphics::API::Shader* mGraphicsShader; ///< The graphics object ( owned by cache )
ShaderCache* mShaderCache;
Dali::Shader::Hint::Value mHints; ///< Hints for the shader
/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Texture::~Texture()
{}
-void Texture::Initialize( Integration::Graphics::Graphics& graphics )
+void Texture::Initialize( Integration::Graphics::GraphicsInterface& graphics )
{
mGraphics = &graphics;
}
#define DALI_INTERNAL_SCENE_GRAPH_TEXTURE_H
/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali/public-api/rendering/sampler.h>
#include <dali/public-api/rendering/texture.h>
#include <dali/graphics-api/graphics-api-texture.h>
-#include <dali/integration-api/graphics/graphics.h>
+#include <dali/integration-api/graphics/graphics-interface.h>
#include <dali/internal/common/message.h>
#include <dali/internal/event/rendering/texture-impl.h>
#include <dali/internal/update/rendering/scene-graph-sampler.h>
*
* @param[in] graphics The Graphics API
*/
- void Initialize( Integration::Graphics::Graphics& graphics );
+ void Initialize( Integration::Graphics::GraphicsInterface& graphics );
/**
* Retrieve wheter the texture has an alpha channel
void CreateTextureInternal( Usage usage, unsigned char* buffer, unsigned int bufferSize );
private:
- Integration::Graphics::Graphics* mGraphics; ///< Graphics interface object
+ Integration::Graphics::GraphicsInterface* mGraphics; ///< Graphics interface object
std::unique_ptr<Graphics::API::Texture> mGraphicsTexture; ///< Graphics texture
NativeImageInterfacePtr mNativeImage; ///< Pointer to native image
#define DALI_INTERNAL_UPDATE_RENDERING_SHADER_CACHE_H
/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* limitations under the License.
*/
-#include <dali/integration-api/graphics/graphics.h>
+#include <dali/integration-api/graphics/graphics-interface.h>
#include <dali/graphics-api/graphics-api-shader.h>
#include <dali/graphics-api/graphics-api-shader-details.h>