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.
52 static constexpr uint32_t BINDING_INDEX_DONT_CARE { 0xffffffff };
54 enum class InputAttributeRate
74 * Describes buffer attribute binding
76 struct VertexAttributeBufferBinding
78 VertexAttributeBufferBinding() = default;
80 Accessor<Buffer> buffer{ nullptr };
81 uint32_t location { 0u };
82 uint32_t offset { 0u };
83 uint32_t stride { 0u };
84 InputAttributeRate rate { InputAttributeRate::PER_VERTEX };
86 uint32_t binding { 0u };
87 void* pNext{ nullptr };
89 VertexAttributeBufferBinding& SetBuffer( Accessor<Buffer> value )
94 VertexAttributeBufferBinding& SetLocation( uint32_t value )
99 VertexAttributeBufferBinding& SetOffset( uint32_t value )
104 VertexAttributeBufferBinding& SetStride( uint32_t value )
109 VertexAttributeBufferBinding& SetBinding( uint32_t value )
114 VertexAttributeBufferBinding& SetInputAttributeRate( InputAttributeRate value)
122 * Structure describes uniform buffer binding
124 struct UniformBufferBinding
126 UniformBufferBinding() :
127 buffer( nullptr ), offset( 0u ), dataSize( 0u ), binding( 0u ) {}
128 Accessor<Buffer> buffer;
132 void* pNext{ nullptr };
134 UniformBufferBinding& SetBuffer( Accessor<Buffer> value )
139 UniformBufferBinding& SetOffset( uint32_t value )
144 UniformBufferBinding& SetDataSize( uint32_t value )
149 UniformBufferBinding& SetBinding( uint32_t value )
159 struct TextureBinding
161 Accessor<Texture> texture;
162 Accessor<Sampler> sampler;
164 void* pNext{ nullptr };
165 TextureBinding() : texture(nullptr), sampler( nullptr ), binding( 0u ) {}
167 TextureBinding& SetTexture( Accessor<Texture> value )
172 TextureBinding& SetSampler( Accessor<Sampler> value )
177 TextureBinding& SetBinding( uint32_t value )
187 struct SamplerBinding
189 Accessor<Sampler> sampler;
191 void* pNext{ nullptr };
192 SamplerBinding& SetSampler( Accessor<Sampler> value )
197 SamplerBinding& SetBinding( uint32_t value )
207 struct IndexBufferBinding
209 Accessor<Buffer> buffer { nullptr };
210 uint32_t offset { 0u };
211 IndexType type { IndexType::INDEX_TYPE_UINT16 };
212 void* pNext{ nullptr };
213 IndexBufferBinding() = default;
215 IndexBufferBinding& SetBuffer( Accessor<Buffer> value )
221 IndexBufferBinding& SetOffset( uint32_t value )
227 IndexBufferBinding& SetType( IndexType value )
234 struct RenderTargetBinding
236 Accessor<Framebuffer> framebuffer { nullptr };
237 std::vector<Framebuffer::ClearColor> clearColors {};
238 Framebuffer::DepthStencilClearColor dsClearColor {};
239 void* pNext{ nullptr };
240 RenderTargetBinding() = default;
242 RenderTargetBinding& SetFramebuffer( Accessor<Framebuffer> value )
248 RenderTargetBinding& SetClearColors( std::vector<Framebuffer::ClearColor>&& value )
254 RenderTargetBinding& SetFramebuffer( Framebuffer::DepthStencilClearColor value )
256 dsClearColor = value;
264 drawType( DrawType::UNDEFINED_DRAW ){}
268 uint32_t firstVertex;
273 uint32_t vertexCount;
274 uint32_t indicesCount;
276 uint32_t firstInstance;
277 uint32_t instanceCount;
278 void* pNext{ nullptr };
279 DrawCommand& SetDrawType( DrawType value )
284 DrawCommand& SetFirstVertex( uint32_t value )
289 DrawCommand& SetFirstIndex( uint32_t value )
294 DrawCommand& SetVertexCount( uint32_t value )
299 DrawCommand& SetIndicesCount( uint32_t value )
301 indicesCount = value;
304 DrawCommand& SetFirstInstance( uint32_t value )
306 firstInstance = value;
309 DrawCommand& SetInstanceCount( uint32_t value )
311 instanceCount = value;
319 struct PushConstantsBinding
324 void* pNext{ nullptr };
325 PushConstantsBinding() = default;
327 PushConstantsBinding& SetData( void* value )
332 PushConstantsBinding& SetSize( uint32_t value )
337 PushConstantsBinding& SetBinding( uint32_t value )
351 bool blendingEnabled { false };
354 RenderState() = default;
356 Accessor<Shader> shader { nullptr };
357 BlendState blendState {};
359 RenderState& SetShader( Accessor<Shader> value )
365 RenderState& SetBlendState( BlendState value )
371 void* pNext{ nullptr };
375 : mVertexBufferBindings(),
376 mUniformBufferBindings(),
378 mIndexBufferBinding(),
379 mRenderTargetBinding(),
381 mPushConstantsBindings(),
387 // derived types should not be moved direcly to prevent slicing
388 RenderCommand( RenderCommand&& ) = default;
389 RenderCommand& operator=( RenderCommand&& ) = default;
392 RenderCommand( const RenderCommand& ) = delete;
393 RenderCommand& operator=( const RenderCommand& ) = delete;
395 virtual ~RenderCommand() = default;
398 * Resource binding API
400 RenderCommand& BindVertexBuffers( std::vector<VertexAttributeBufferBinding>&& bindings )
402 mVertexBufferBindings = std::move( bindings );
406 RenderCommand& BindUniformBuffers( std::vector<UniformBufferBinding>&& bindings )
408 mUniformBufferBindings = std::move( bindings );
412 RenderCommand& BindTextures( std::vector<TextureBinding>&& bindings )
414 mTextureBindings = std::move( bindings );
418 RenderCommand& BindSamplers( std::vector<SamplerBinding>&& bindings )
420 mSamplerBindings = std::move( bindings );
424 RenderCommand& PushConstants( std::vector<PushConstantsBinding>&& bindings )
426 mPushConstantsBindings = bindings;
430 RenderCommand& BindRenderState( RenderState& renderState )
432 mRenderState = renderState;
436 RenderCommand& BindRenderTarget( const RenderTargetBinding& binding )
438 mRenderTargetBinding = binding;
442 RenderCommand& BindRenderTarget( RenderTargetBinding&& binding )
444 mRenderTargetBinding = std::move(binding);
448 RenderCommand& Draw( DrawCommand&& drawCommand )
450 mDrawCommand = drawCommand;
454 RenderCommand& BindPipeline( const Accessor<Pipeline>& pipeline )
456 mPipeline = pipeline;
460 static std::vector<VertexAttributeBufferBinding> NewVertexAttributeBufferBindings()
462 return std::vector<VertexAttributeBufferBinding>{};
466 * Makes a copy ( or moves ) all bindings from the source array
470 static std::vector<VertexAttributeBufferBinding> NewVertexAttributeBufferBindings( std::vector<VertexAttributeBufferBinding>&& bindings )
472 return std::vector<VertexAttributeBufferBinding>{ std::move(bindings) };
475 static std::vector<VertexAttributeBufferBinding> NewVertexAttributeBufferBindings( const std::vector<VertexAttributeBufferBinding>& bindings )
477 return std::vector<VertexAttributeBufferBinding>{ bindings };
480 static std::vector<TextureBinding> NewTextureBindings()
482 return std::vector<TextureBinding>{};
485 static std::vector<PushConstantsBinding> NewPushConstantsBindings( uint32_t count )
487 auto retval = std::vector<PushConstantsBinding>{};
488 retval.resize( count );
493 const std::vector<VertexAttributeBufferBinding>& GetVertexBufferBindings() const
495 return mVertexBufferBindings;
498 const auto& GetUniformBufferBindings() const
500 return mUniformBufferBindings;
503 const std::vector<TextureBinding>& GetTextureBindings() const
505 return mTextureBindings;
508 const auto& GetIndexBufferBinding() const
510 return mIndexBufferBinding;
513 const auto& GetRenderTargetBinding() const
515 return mRenderTargetBinding;
518 const DrawCommand& GetDrawCommand() const
523 const std::vector<PushConstantsBinding>& GetPushConstantsBindings() const
525 return mPushConstantsBindings;
528 const RenderState& GetRenderState() const
533 Accessor<Pipeline> GetPipeline() const
540 std::vector<VertexAttributeBufferBinding> mVertexBufferBindings;
541 std::vector<UniformBufferBinding> mUniformBufferBindings;
542 std::vector<TextureBinding> mTextureBindings;
543 std::vector<SamplerBinding> mSamplerBindings;
544 IndexBufferBinding mIndexBufferBinding;
545 RenderTargetBinding mRenderTargetBinding;
546 DrawCommand mDrawCommand;
547 std::vector<PushConstantsBinding> mPushConstantsBindings;
548 RenderState mRenderState;
549 Accessor<Pipeline> mPipeline;
554 } // namespace Graphics
557 #endif // DALI_GRAPHICS_API_RENDER_COMMAND_H
561 * @brief Interface class for RenderCommand types in the graphics API.
565 * skinparam defaultFontName Ubuntu Mono
566 * class RenderCommand {
568 * #VertexAttributeBufferBinding[] mVertexBufferBindings
569 * #UniformBufferBinding[] mUniformBufferBindings
570 * #TextureBinding[] mTextureBindings
571 * #SamplerBinding[] mSamplerBindings
572 * #IndexBufferBinding mIndexBufferBinding
573 * #RenderTargetBinding mRenderTargetBinding
574 * #DrawCommand mDrawCommand
575 * #PushConstantsBinding[] mPushConstantsBindings
576 * #RenderState mRenderState
579 * +RenderCommand& BindVertextBuffers()
580 * +RenderCommand& BindUniformBuffers()
581 * +RenderCommand& BindTextures()
582 * +RenderCommand& BindSamplers()
583 * +RenderCommand& PushConstants()
584 * +RenderCommand& BindRenderState()
585 * +RenderCommand& Draw()
586 * -- static API ( helper functions )--
587 * {static} NewVertexAttributeBufferBindings()
588 * {static} NewVertexAttributeBufferBindings()
589 * {static} NewVertexAttributeBufferBindings()
590 * {static} NewTextureBindings()
591 * {static} NewPushConstantsBindings()
594 * class VertexAttributeBufferBinding {
595 * Accessor<Buffer> buffer
599 * InputAttributeRate rate
603 * class UniformBufferBinding {
604 * #Accessor<Buffer> buffer
611 class IndexBufferBinding {
612 #Accessor<Buffer> buffer
618 class RenderTargetBinding {
619 #Accessor<Framebuffer> framebuffer
620 #std::vector<Framebuffer::ClearColor> clearColors
621 #Framebuffer::DepthStencilClearColor dsClearColor
627 #uint32_t firstVertex
629 #uint32_t vertexCount
630 #uint32_t indicesCount
631 #uint32_t firstInstance
632 #uint32_t instanceCount
636 class PushConstantsBinding {
644 #Accessor<Shader> shader
648 class TextureBinding {
649 #Accessor<Texture> texture
650 #Accessor<Sampler> sampler
655 class SamplerBinding {
656 #Accessor<Sampler> sampler
661 note as RenderStateWIP
662 Other render states like
663 blending etc. should be added
664 as public fields of this structure.
667 RenderStateWIP .. RenderState
670 * Each state is described as POD
671 * structure which is a Vulkan
676 * Field pNext may be used by the
677 * implementation to pass additional
681 * N2 .. VertexAttributeBufferBinding::pNext
682 * N1 .. VertexAttributeBufferBinding
683 * N1 .. UniformBufferBinding
684 * N1 .. IndexBufferBinding
685 * N1 .. RenderTargetBinding
689 * RenderCommand *-right- VertexAttributeBufferBinding
690 * RenderCommand *-right- UniformBufferBinding
691 * RenderCommand *-left- IndexBufferBinding
692 * RenderCommand *-left- RenderTargetBinding
693 * RenderCommand *-up- RenderState
694 * RenderCommand *-up- DrawCommand
695 * RenderCommand *-down- PushConstantsBinding
696 * RenderCommand *-down- SamplerBinding
697 * RenderCommand *-down- TextureBinding