1 #ifndef DALI_GRAPHICS_API_RENDER_COMMAND_H
2 #define DALI_GRAPHICS_API_RENDER_COMMAND_H
5 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
27 #include <dali/graphics-api/graphics-api-shader-details.h>
28 #include <dali/graphics-api/graphics-api-accessor.h>
29 #include <dali/graphics-api/graphics-api-framebuffer.h>
30 #include <dali/graphics-api/graphics-api-buffer.h>
46 * @brief Interface class for RenderCommand types in the graphics API.
50 * skinparam defaultFontName Ubuntu Mono
51 * class RenderCommand {
53 * #VertexAttributeBufferBinding[] mVertexBufferBindings
54 * #UniformBufferBinding[] mUniformBufferBindings
55 * #TextureBinding[] mTextureBindings
56 * #SamplerBinding[] mSamplerBindings
57 * #IndexBufferBinding mIndexBufferBinding
58 * #RenderTargetBinding mRenderTargetBinding
59 * #DrawCommand mDrawCommand
60 * #PushConstantsBinding[] mPushConstantsBindings
61 * #RenderState mRenderState
64 * +RenderCommand& BindVertextBuffers()
65 * +RenderCommand& BindUniformBuffers()
66 * +RenderCommand& BindTextures()
67 * +RenderCommand& BindSamplers()
68 * +RenderCommand& PushConstants()
69 * +RenderCommand& BindRenderState()
70 * +RenderCommand& Draw()
71 * -- static API ( helper functions )--
72 * {static} NewVertexAttributeBufferBindings()
73 * {static} NewVertexAttributeBufferBindings()
74 * {static} NewVertexAttributeBufferBindings()
75 * {static} NewTextureBindings()
76 * {static} NewPushConstantsBindings()
79 * class VertexAttributeBufferBinding {
80 * Accessor<Buffer> buffer
84 * InputAttributeRate rate
88 * class UniformBufferBinding {
89 * #Accessor<Buffer> buffer
96 class IndexBufferBinding {
97 #Accessor<Buffer> buffer
103 class RenderTargetBinding {
104 #Accessor<Framebuffer> framebuffer
105 #std::vector<Framebuffer::ClearColor> clearColors
106 #Framebuffer::DepthStencilClearColor dsClearColor
112 #uint32_t firstVertex
114 #uint32_t vertexCount
115 #uint32_t indicesCount
116 #uint32_t firstInstance
117 #uint32_t instanceCount
121 class PushConstantsBinding {
129 #Accessor<Shader> shader
133 class TextureBinding {
134 #Accessor<Texture> texture
135 #Accessor<Sampler> sampler
140 class SamplerBinding {
141 #Accessor<Sampler> sampler
146 note as RenderStateWIP
147 Other render states like
148 blending etc. should be added
149 as public fields of this structure.
152 RenderStateWIP .. RenderState
155 * Each state is described as POD
156 * structure which is a Vulkan
161 * Field pNext may be used by the
162 * implementation to pass additional
166 * N2 .. VertexAttributeBufferBinding::pNext
167 * N1 .. VertexAttributeBufferBinding
168 * N1 .. UniformBufferBinding
169 * N1 .. IndexBufferBinding
170 * N1 .. RenderTargetBinding
174 * RenderCommand *-right- VertexAttributeBufferBinding
175 * RenderCommand *-right- UniformBufferBinding
176 * RenderCommand *-left- IndexBufferBinding
177 * RenderCommand *-left- RenderTargetBinding
178 * RenderCommand *-up- RenderState
179 * RenderCommand *-up- DrawCommand
180 * RenderCommand *-down- PushConstantsBinding
181 * RenderCommand *-down- SamplerBinding
182 * RenderCommand *-down- TextureBinding
189 static constexpr uint32_t BINDING_INDEX_DONT_CARE { 0xffffffff };
191 enum class InputAttributeRate
211 * Describes buffer attribute binding
214 struct VertexAttributeBufferBinding
216 VertexAttributeBufferBinding() = default;
218 Accessor<Buffer> buffer{ nullptr };
219 uint32_t location { 0u };
220 uint32_t offset { 0u };
221 uint32_t stride { 0u };
222 InputAttributeRate rate { InputAttributeRate::PER_VERTEX };
224 uint32_t binding { 0u };
225 void* pNext{ nullptr };
227 VertexAttributeBufferBinding& SetBuffer( Accessor<Buffer> value )
232 VertexAttributeBufferBinding& SetLocation( uint32_t value )
237 VertexAttributeBufferBinding& SetOffset( uint32_t value )
242 VertexAttributeBufferBinding& SetStride( uint32_t value )
247 VertexAttributeBufferBinding& SetBinding( uint32_t value )
252 VertexAttributeBufferBinding& SetInputAttributeRate( InputAttributeRate value)
260 * Structure describes uniform buffer binding
262 struct UniformBufferBinding
264 UniformBufferBinding() :
265 buffer( nullptr ), offset( 0u ), dataSize( 0u ), binding( 0u ) {}
266 Accessor<Buffer> buffer;
270 void* pNext{ nullptr };
272 UniformBufferBinding& SetBuffer( Accessor<Buffer> value )
277 UniformBufferBinding& SetOffset( uint32_t value )
282 UniformBufferBinding& SetDataSize( uint32_t value )
287 UniformBufferBinding& SetBinding( uint32_t value )
297 struct TextureBinding
299 Accessor<Texture> texture;
300 Accessor<Sampler> sampler;
302 void* pNext{ nullptr };
303 TextureBinding() : texture(nullptr), sampler( nullptr ), binding( 0u ) {}
305 TextureBinding& SetTexture( Accessor<Texture> value )
310 TextureBinding& SetSampler( Accessor<Sampler> value )
315 TextureBinding& SetBinding( uint32_t value )
325 struct SamplerBinding
327 Accessor<Sampler> sampler;
329 void* pNext{ nullptr };
330 SamplerBinding& SetSampler( Accessor<Sampler> value )
335 SamplerBinding& SetBinding( uint32_t value )
345 struct IndexBufferBinding
347 Accessor<Buffer> buffer { nullptr };
348 uint32_t offset { 0u };
349 IndexType type { IndexType::INDEX_TYPE_UINT16 };
350 void* pNext{ nullptr };
351 IndexBufferBinding() = default;
353 IndexBufferBinding& SetBuffer( Accessor<Buffer> value )
359 IndexBufferBinding& SetOffset( uint32_t value )
365 IndexBufferBinding& SetType( IndexType value )
372 struct RenderTargetBinding
374 Accessor<Framebuffer> framebuffer { nullptr };
375 std::vector<Framebuffer::ClearColor> clearColors {};
376 Framebuffer::DepthStencilClearColor dsClearColor {};
377 void* pNext{ nullptr };
378 RenderTargetBinding() = default;
380 RenderTargetBinding& SetFramebuffer( Accessor<Framebuffer> value )
386 RenderTargetBinding& SetClearColors( std::vector<Framebuffer::ClearColor>&& value )
392 RenderTargetBinding& SetFramebuffer( Framebuffer::DepthStencilClearColor value )
394 dsClearColor = value;
402 drawType( DrawType::UNDEFINED_DRAW ){}
406 uint32_t firstVertex;
411 uint32_t vertexCount;
412 uint32_t indicesCount;
414 uint32_t firstInstance;
415 uint32_t instanceCount;
416 void* pNext{ nullptr };
417 DrawCommand& SetDrawType( DrawType value )
422 DrawCommand& SetFirstVertex( uint32_t value )
427 DrawCommand& SetFirstIndex( uint32_t value )
432 DrawCommand& SetVertexCount( uint32_t value )
437 DrawCommand& SetIndicesCount( uint32_t value )
439 indicesCount = value;
442 DrawCommand& SetFirstInstance( uint32_t value )
444 firstInstance = value;
447 DrawCommand& SetInstanceCount( uint32_t value )
449 instanceCount = value;
457 struct PushConstantsBinding
462 void* pNext{ nullptr };
463 PushConstantsBinding() = default;
465 PushConstantsBinding& SetData( void* value )
470 PushConstantsBinding& SetSize( uint32_t value )
475 PushConstantsBinding& SetBinding( uint32_t value )
489 bool blendingEnabled { false };
492 RenderState() = default;
494 Accessor<Shader> shader { nullptr };
495 BlendState blendState {};
497 RenderState& SetShader( Accessor<Shader> value )
503 RenderState& SetBlendState( BlendState value )
509 void* pNext{ nullptr };
513 : mVertexBufferBindings(),
514 mUniformBufferBindings(),
516 mIndexBufferBinding(),
517 mRenderTargetBinding(),
519 mPushConstantsBindings(),
525 // derived types should not be moved direcly to prevent slicing
526 RenderCommand( RenderCommand&& ) = default;
527 RenderCommand& operator=( RenderCommand&& ) = default;
530 RenderCommand( const RenderCommand& ) = delete;
531 RenderCommand& operator=( const RenderCommand& ) = delete;
533 virtual ~RenderCommand() = default;
536 * Resource binding API
538 RenderCommand& BindVertexBuffers( std::vector<VertexAttributeBufferBinding>&& bindings )
540 mVertexBufferBindings = std::move( bindings );
544 RenderCommand& BindUniformBuffers( std::vector<UniformBufferBinding>&& bindings )
546 mUniformBufferBindings = std::move( bindings );
550 RenderCommand& BindTextures( std::vector<TextureBinding>&& bindings )
552 mTextureBindings = std::move( bindings );
556 RenderCommand& BindSamplers( std::vector<SamplerBinding>&& bindings )
558 mSamplerBindings = std::move( bindings );
562 RenderCommand& PushConstants( std::vector<PushConstantsBinding>&& bindings )
564 mPushConstantsBindings = bindings;
568 RenderCommand& BindRenderState( RenderState& renderState )
570 mRenderState = renderState;
574 RenderCommand& BindRenderTarget( const RenderTargetBinding& binding )
576 mRenderTargetBinding = binding;
580 RenderCommand& BindRenderTarget( RenderTargetBinding&& binding )
582 mRenderTargetBinding = std::move(binding);
586 RenderCommand& Draw( DrawCommand&& drawCommand )
588 mDrawCommand = drawCommand;
592 RenderCommand& BindPipeline( const Accessor<Pipeline>& pipeline )
594 mPipeline = pipeline;
598 static std::vector<VertexAttributeBufferBinding> NewVertexAttributeBufferBindings()
600 return std::vector<VertexAttributeBufferBinding>{};
604 * Makes a copy ( or moves ) all bindings from the source array
608 static std::vector<VertexAttributeBufferBinding> NewVertexAttributeBufferBindings( std::vector<VertexAttributeBufferBinding>&& bindings )
610 return std::vector<VertexAttributeBufferBinding>{ std::move(bindings) };
613 static std::vector<VertexAttributeBufferBinding> NewVertexAttributeBufferBindings( const std::vector<VertexAttributeBufferBinding>& bindings )
615 return std::vector<VertexAttributeBufferBinding>{ bindings };
618 static std::vector<TextureBinding> NewTextureBindings()
620 return std::vector<TextureBinding>{};
623 static std::vector<PushConstantsBinding> NewPushConstantsBindings( uint32_t count )
625 auto retval = std::vector<PushConstantsBinding>{};
626 retval.resize( count );
631 const std::vector<VertexAttributeBufferBinding>& GetVertexBufferBindings() const
633 return mVertexBufferBindings;
636 const auto& GetUniformBufferBindings() const
638 return mUniformBufferBindings;
641 const std::vector<TextureBinding>& GetTextureBindings() const
643 return mTextureBindings;
646 const auto& GetIndexBufferBinding() const
648 return mIndexBufferBinding;
651 const auto& GetRenderTargetBinding() const
653 return mRenderTargetBinding;
656 const DrawCommand& GetDrawCommand() const
661 const std::vector<PushConstantsBinding>& GetPushConstantsBindings() const
663 return mPushConstantsBindings;
666 const RenderState& GetRenderState() const
671 Accessor<Pipeline> GetPipeline() const
678 std::vector<VertexAttributeBufferBinding> mVertexBufferBindings;
679 std::vector<UniformBufferBinding> mUniformBufferBindings;
680 std::vector<TextureBinding> mTextureBindings;
681 std::vector<SamplerBinding> mSamplerBindings;
682 IndexBufferBinding mIndexBufferBinding;
683 RenderTargetBinding mRenderTargetBinding;
684 DrawCommand mDrawCommand;
685 std::vector<PushConstantsBinding> mPushConstantsBindings;
686 RenderState mRenderState;
687 Accessor<Pipeline> mPipeline;
692 } // namespace Graphics
696 #endif // DALI_GRAPHICS_API_RENDER_COMMAND_H
700 * @brief Interface class for RenderCommand types in the graphics API.
704 * skinparam defaultFontName Ubuntu Mono
705 * class RenderCommand {
707 * #VertexAttributeBufferBinding[] mVertexBufferBindings
708 * #UniformBufferBinding[] mUniformBufferBindings
709 * #TextureBinding[] mTextureBindings
710 * #SamplerBinding[] mSamplerBindings
711 * #IndexBufferBinding mIndexBufferBinding
712 * #RenderTargetBinding mRenderTargetBinding
713 * #DrawCommand mDrawCommand
714 * #PushConstantsBinding[] mPushConstantsBindings
715 * #RenderState mRenderState
718 * +RenderCommand& BindVertextBuffers()
719 * +RenderCommand& BindUniformBuffers()
720 * +RenderCommand& BindTextures()
721 * +RenderCommand& BindSamplers()
722 * +RenderCommand& PushConstants()
723 * +RenderCommand& BindRenderState()
724 * +RenderCommand& Draw()
725 * -- static API ( helper functions )--
726 * {static} NewVertexAttributeBufferBindings()
727 * {static} NewVertexAttributeBufferBindings()
728 * {static} NewVertexAttributeBufferBindings()
729 * {static} NewTextureBindings()
730 * {static} NewPushConstantsBindings()
733 * class VertexAttributeBufferBinding {
734 * Accessor<Buffer> buffer
738 * InputAttributeRate rate
742 * class UniformBufferBinding {
743 * #Accessor<Buffer> buffer
750 class IndexBufferBinding {
751 #Accessor<Buffer> buffer
757 class RenderTargetBinding {
758 #Accessor<Framebuffer> framebuffer
759 #std::vector<Framebuffer::ClearColor> clearColors
760 #Framebuffer::DepthStencilClearColor dsClearColor
766 #uint32_t firstVertex
768 #uint32_t vertexCount
769 #uint32_t indicesCount
770 #uint32_t firstInstance
771 #uint32_t instanceCount
775 class PushConstantsBinding {
783 #Accessor<Shader> shader
787 class TextureBinding {
788 #Accessor<Texture> texture
789 #Accessor<Sampler> sampler
794 class SamplerBinding {
795 #Accessor<Sampler> sampler
800 note as RenderStateWIP
801 Other render states like
802 blending etc. should be added
803 as public fields of this structure.
806 RenderStateWIP .. RenderState
809 * Each state is described as POD
810 * structure which is a Vulkan
815 * Field pNext may be used by the
816 * implementation to pass additional
820 * N2 .. VertexAttributeBufferBinding::pNext
821 * N1 .. VertexAttributeBufferBinding
822 * N1 .. UniformBufferBinding
823 * N1 .. IndexBufferBinding
824 * N1 .. RenderTargetBinding
828 * RenderCommand *-right- VertexAttributeBufferBinding
829 * RenderCommand *-right- UniformBufferBinding
830 * RenderCommand *-left- IndexBufferBinding
831 * RenderCommand *-left- RenderTargetBinding
832 * RenderCommand *-up- RenderState
833 * RenderCommand *-up- DrawCommand
834 * RenderCommand *-down- PushConstantsBinding
835 * RenderCommand *-down- SamplerBinding
836 * RenderCommand *-down- TextureBinding