if(it2 == uniformIDs.end())
{
// Uniform not found, so add it...
- uniformIDs[name] = ++mLastUniformIdUsed;
+ uniformIDs[name] = mLastUniformIdUsed++;
return mLastUniformIdUsed;
}
mShaderTrace.PushCall("LinkProgram", out.str(), namedParams);
mNumberOfActiveUniforms = 3;
- GetUniformLocation(program, "sTexture");
+
+ GetUniformLocation(program, "uRendererColor");
+ GetUniformLocation(program, "uCustom");
+ GetUniformLocation(program, "uCustom3");
+ GetUniformLocation(program, "uFadeColor");
+ GetUniformLocation(program, "uUniform1");
+ GetUniformLocation(program, "uUniform2");
+ GetUniformLocation(program, "uUniform3");
+ GetUniformLocation(program, "uFadeProgress");
+ GetUniformLocation(program, "uANormalMatrix");
GetUniformLocation(program, "sEffect");
+ GetUniformLocation(program, "sTexture");
+ GetUniformLocation(program, "sTextureRect");
GetUniformLocation(program, "sGloss");
+ GetUniformLocation(program, "uColor");
+ GetUniformLocation(program, "uModelMatrix");
+ GetUniformLocation(program, "uModelView");
+ GetUniformLocation(program, "uMvpMatrix");
+ GetUniformLocation(program, "uNormalMatrix");
+ GetUniformLocation(program, "uProjection");
+ GetUniformLocation(program, "uSize");
+ GetUniformLocation(program, "uViewMatrix");
+ GetUniformLocation(program, "uLightCameraProjectionMatrix");
+ GetUniformLocation(program, "uLightCameraViewMatrix");
}
inline void PixelStorei(GLenum pname, GLint param) override
*/
#include "test-graphics-buffer.h"
+#include "test-graphics-program.h"
+#include "test-graphics-reflection.h"
#include <sstream>
#include "dali-test-suite-utils.h"
return target;
}
+void TestGraphicsBuffer::BindAsUniformBuffer( const TestGraphicsProgram* program ) const
+{
+ auto* reflection = static_cast<const TestGraphicsReflection*>(&program->GetReflection());
+
+ Graphics::UniformBlockInfo uboInfo{};
+ reflection->GetUniformBlock(0, uboInfo);
+
+ auto* data = memory.data();
+
+ for( const auto& member : uboInfo.members )
+ {
+ auto type = reflection->GetMemberType( 0, member.location );
+ switch(type)
+ {
+ case Property::VECTOR4:
+ {
+ auto value = *reinterpret_cast<const Dali::Vector4*>(data+member.offset);
+ mGl.Uniform4f( member.location, value.x, value.y, value.z, value.w );
+ break;
+ }
+ case Property::VECTOR3:
+ {
+ auto value = *reinterpret_cast<const Dali::Vector3*>(data+member.offset);
+ mGl.Uniform3f( member.location, value.x, value.y, value.z );
+ break;
+ }
+ case Property::VECTOR2:
+ {
+ auto value = *reinterpret_cast<const Dali::Vector2*>(data+member.offset);
+ mGl.Uniform2f( member.location, value.x, value.y );
+ break;
+ }
+ case Property::FLOAT:
+ {
+ auto value = *reinterpret_cast<const float*>(data+member.offset);
+ mGl.Uniform1f( member.location, value );
+ break;
+ }
+ case Property::INTEGER:
+ {
+ auto ptr = reinterpret_cast<const GLint*>(data+member.offset);
+ auto value = *ptr;
+ mGl.Uniform1i( member.location, value );
+ break;
+ }
+ case Property::MATRIX:
+ {
+ auto value = reinterpret_cast<const float*>(data+member.offset);
+ mGl.UniformMatrix4fv( member.location, 1, GL_FALSE, value );
+ break;
+ }
+ case Property::MATRIX3:
+ {
+ auto value = reinterpret_cast<const float*>(data+member.offset);
+ mGl.UniformMatrix3fv( member.location, 1, GL_FALSE, value );
+ break;
+ }
+ default:
+ {
+
+ }
+ }
+ }
+
+
+}
+
} // namespace Dali
namespace Dali
{
+class TestGraphicsProgram;
class TestGraphicsBuffer : public Graphics::Buffer
{
public:
void Upload(uint32_t offset, uint32_t size);
GLenum GetTarget();
+ bool IsCPUAllocated() const
+ {
+ return true;
+ }
+
+ void BindAsUniformBuffer( const TestGraphicsProgram* program ) const;
+
TraceCallStack& mCallStack;
TestGlAbstraction& mGl;
std::vector<uint8_t> memory;
{
}
-void TestGraphicsCommandBuffer::BindVertexBuffers(uint32_t firstBinding,
- std::vector<const Graphics::Buffer*> buffers,
- std::vector<uint32_t> offsets)
+int TestGraphicsCommandBuffer::GetDrawCallsCount()
{
- mVertexBufferBindings.firstBinding = firstBinding;
- mVertexBufferBindings.buffers = buffers; // Copy
- mVertexBufferBindings.offsets = offsets; // Copy
- mCallStack.PushCall("BindVertexBuffers", "");
-}
-
-void TestGraphicsCommandBuffer::BindUniformBuffers(const std::vector<Graphics::UniformBufferBinding>& bindings)
-{
- mCallStack.PushCall("BindUniformBuffers", "");
-}
-
-void TestGraphicsCommandBuffer::BindPipeline(const Graphics::Pipeline& pipeline)
-{
- mPipeline = static_cast<TestGraphicsPipeline*>(const_cast<Graphics::Pipeline*>(&pipeline));
- mCallStack.PushCall("BindPipeline", "");
-}
-
-void TestGraphicsCommandBuffer::BindTextures(std::vector<Graphics::TextureBinding>& textureBindings)
-{
- mCallStack.PushCall("BindTextures", "");
- for(auto& binding : textureBindings)
+ int count = 0;
+ for( auto& cmd : mCommands )
{
- mTextureBindings.push_back(binding);
+ if( cmd.type == CommandType::DRAW ||
+ cmd.type == CommandType::DRAW_INDEXED ||
+ cmd.type == CommandType::DRAW_INDEXED_INDIRECT )
+ {
+ ++count;
+ }
}
+ return count;
}
-void TestGraphicsCommandBuffer::BindSamplers(std::vector<Graphics::SamplerBinding>& samplerBindings)
-{
- mCallStack.PushCall("BindSamplers", "");
-}
-
-void TestGraphicsCommandBuffer::BindPushConstants(void* data,
- uint32_t size,
- uint32_t binding)
+void TestGraphicsCommandBuffer::GetStateForDrawCall( int drawCallIndex )
{
- mCallStack.PushCall("BindPushConstants", "");
-}
-
-void TestGraphicsCommandBuffer::BindIndexBuffer(const Graphics::Buffer& buffer,
- uint32_t offset,
- Graphics::Format format)
-{
- mIndexBufferBinding.buffer = &buffer;
- mIndexBufferBinding.offset = offset;
- mIndexBufferBinding.format = format;
- mCallStack.PushCall("BindIndexBuffer", "");
-}
-
-void TestGraphicsCommandBuffer::BeginRenderPass(
- Graphics::RenderPass& renderPass,
- Graphics::RenderTarget& renderTarget,
- Graphics::Extent2D renderArea,
- std::vector<Graphics::ClearValue> clearValues)
-{
- mCallStack.PushCall("BeginRenderPass", "");
-}
-
-void TestGraphicsCommandBuffer::EndRenderPass()
-{
- mCallStack.PushCall("EndRenderPass", "");
-}
-
-void TestGraphicsCommandBuffer::Draw(
- uint32_t vertexCount,
- uint32_t instanceCount,
- uint32_t firstVertex,
- uint32_t firstInstance)
-{
- drawCommand.drawType = Draw::DrawType::Unindexed;
- drawCommand.u.unindexedDraw.vertexCount = vertexCount;
- drawCommand.u.unindexedDraw.instanceCount = instanceCount;
- drawCommand.u.unindexedDraw.firstVertex = firstVertex;
- drawCommand.u.unindexedDraw.firstInstance = firstInstance;
- mCallStack.PushCall("Draw", "");
-}
-
-void TestGraphicsCommandBuffer::DrawIndexed(
- uint32_t indexCount,
- uint32_t instanceCount,
- uint32_t firstIndex,
- int32_t vertexOffset,
- uint32_t firstInstance)
-{
- drawCommand.drawType = TestGraphicsCommandBuffer::Draw::DrawType::Indexed;
- drawCommand.u.indexedDraw.indexCount = indexCount;
- drawCommand.u.indexedDraw.instanceCount = instanceCount;
- drawCommand.u.indexedDraw.firstIndex = firstIndex;
- drawCommand.u.indexedDraw.vertexOffset = vertexOffset;
- drawCommand.u.indexedDraw.firstInstance = firstInstance;
- mCallStack.PushCall("DrawIndexed", "");
-}
-
-void TestGraphicsCommandBuffer::DrawIndexedIndirect(
- Graphics::Buffer& buffer,
- uint32_t offset,
- uint32_t drawCount,
- uint32_t stride)
-{
- mCallStack.PushCall("DrawIndexedIndirect", "");
-}
-
-void TestGraphicsCommandBuffer::Reset(Graphics::CommandBuffer& commandBuffer)
-{
- mCallStack.PushCall("Reset", "");
-}
-
-void TestGraphicsCommandBuffer::SetScissor(Graphics::Extent2D value)
-{
- mCallStack.PushCall("SetScissor", "");
-}
-
-void TestGraphicsCommandBuffer::SetScissorTestEnable(bool value)
-{
- mCallStack.PushCall("SetScissorTestEnable", "");
-}
+ int index = 0;
+ std::vector<Command> mCommandStack{};
+ for( auto& cmd : mCommands )
+ {
+ mCommandStack.push_back(cmd);
+ if( cmd.type == CommandType::DRAW ||
+ cmd.type == CommandType::DRAW_INDEXED ||
+ cmd.type == CommandType::DRAW_INDEXED_INDIRECT )
+ {
+ if( index == drawCallIndex )
+ {
+ break;
+ }
+ mCommandStack.clear();
+ ++index;
+ }
+ }
-void TestGraphicsCommandBuffer::SetViewport(Graphics::Viewport value)
-{
- mCallStack.PushCall("SetViewport", "");
+ //
}
-void TestGraphicsCommandBuffer::SetViewportEnable(bool value)
+std::vector<Command*> TestGraphicsCommandBuffer::GetCommandsByType( CommandTypeMask mask )
{
- mCallStack.PushCall("SetViewportEnable", "");
+ std::vector<Command*> mCommandStack{};
+ for( auto& cmd : mCommands )
+ {
+ if(uint32_t(cmd.type) == (mask & uint32_t(cmd.type)) )
+ {
+ mCommandStack.emplace_back( &cmd );
+ }
+ }
+ return mCommandStack;
}
} // namespace Dali
#include <vector>
#include "test-gl-abstraction.h"
#include "test-graphics-pipeline.h"
+#include "test-graphics-buffer.h"
#include "test-trace-call-stack.h"
namespace Dali
{
+class TestGraphicsTexture;
+class TestGraphicsBuffer;
+class TestGraphicsSampler;
+class TestGraphicsPipeline;
+
+enum class CommandType
+{
+ FLUSH = 1 << 0,
+ BIND_TEXTURES = 1 << 1,
+ BIND_SAMPLERS = 1 << 2,
+ BIND_VERTEX_BUFFERS = 1 << 3,
+ BIND_INDEX_BUFFER = 1 << 4,
+ BIND_UNIFORM_BUFFER = 1 << 5,
+ BIND_PIPELINE = 1 << 6,
+ DRAW = 1 << 7,
+ DRAW_INDEXED = 1 << 8,
+ DRAW_INDEXED_INDIRECT = 1 << 9
+};
+
+using CommandTypeMask = uint32_t;
+template<typename T>
+inline CommandTypeMask operator|(T flags, CommandType bit)
+{
+ return static_cast<CommandTypeMask>(flags) | static_cast<CommandTypeMask>(bit);
+}
+
+/**
+ * @brief Descriptor of single buffer binding within
+ * command buffer.
+ */
+struct VertexBufferBindingDescriptor
+{
+ const TestGraphicsBuffer* buffer{nullptr};
+ uint32_t offset{0u};
+};
+
+/**
+ * @brief Descriptor of ix buffer binding within
+ * command buffer.
+ */
+struct IndexBufferBindingDescriptor
+{
+ const TestGraphicsBuffer* buffer{nullptr};
+ uint32_t offset{};
+ Graphics::Format format{};
+};
+
+/**
+ * @brief Descriptor of uniform buffer binding within
+ * command buffer.
+ */
+struct UniformBufferBindingDescriptor
+{
+ const TestGraphicsBuffer* buffer{nullptr};
+ uint32_t binding{0u};
+ uint32_t offset{0u};
+ bool emulated; ///<true if UBO is emulated for old gfx API
+};
+
+/**
+ * @brief The descriptor of draw call
+ */
+struct DrawCallDescriptor
+{
+ /**
+ * @brief Enum specifying type of the draw call
+ */
+ enum class Type
+ {
+ DRAW,
+ DRAW_INDEXED,
+ DRAW_INDEXED_INDIRECT
+ };
+
+ Type type{}; ///< Type of the draw call
+
+ /**
+ * Union contains data for all types of draw calls.
+ */
+ union
+ {
+ /**
+ * @brief Vertex array draw
+ */
+ struct
+ {
+ uint32_t vertexCount;
+ uint32_t instanceCount;
+ uint32_t firstVertex;
+ uint32_t firstInstance;
+ } draw;
+
+ /**
+ * @brief Indexed draw
+ */
+ struct
+ {
+ uint32_t indexCount;
+ uint32_t instanceCount;
+ uint32_t firstIndex;
+ int32_t vertexOffset;
+ uint32_t firstInstance;
+ } drawIndexed;
+
+ /**
+ * @brief Indexed draw indirect
+ */
+ struct
+ {
+ const TestGraphicsBuffer* buffer;
+ uint32_t offset;
+ uint32_t drawCount;
+ uint32_t stride;
+ } drawIndexedIndirect;
+ };
+};
+
+/**
+ * Command structure allocates memory to store a single command
+ */
+struct Command
+{
+ Command()
+ {
+ }
+
+ ~Command()
+ {
+ }
+
+ /**
+ * @brief Copy constructor
+ * @param[in] rhs Command
+ */
+ Command(const Command& rhs)
+ {
+ switch(rhs.type)
+ {
+ case CommandType::BIND_VERTEX_BUFFERS:
+ {
+ bindVertexBuffers = rhs.bindVertexBuffers;
+ break;
+ }
+ case CommandType::BIND_INDEX_BUFFER:
+ {
+ bindIndexBuffer = rhs.bindIndexBuffer;
+ break;
+ }
+ case CommandType::BIND_SAMPLERS:
+ {
+ bindSamplers = rhs.bindSamplers;
+ break;
+ }
+ case CommandType::BIND_TEXTURES:
+ {
+ bindTextures = rhs.bindTextures;
+ break;
+ }
+ case CommandType::BIND_PIPELINE:
+ {
+ bindPipeline = rhs.bindPipeline;
+ break;
+ }
+ case CommandType::BIND_UNIFORM_BUFFER:
+ {
+ bindUniformBuffers = rhs.bindUniformBuffers;
+ break;
+ }
+ case CommandType::DRAW:
+ {
+ draw.type = rhs.draw.type;
+ draw.draw = rhs.draw.draw;
+ break;
+ }
+ case CommandType::DRAW_INDEXED:
+ {
+ draw.type = rhs.draw.type;
+ draw.drawIndexed = rhs.draw.drawIndexed;
+ break;
+ }
+ case CommandType::DRAW_INDEXED_INDIRECT:
+ {
+ draw.type = rhs.draw.type;
+ draw.drawIndexedIndirect = rhs.draw.drawIndexedIndirect;
+ break;
+ }
+ case CommandType::FLUSH:
+ {
+ // Nothing to do
+ break;
+ }
+ }
+ type = rhs.type;
+ }
+
+ /**
+ * @brief Copy constructor
+ * @param[in] rhs Command
+ */
+ Command(Command&& rhs) noexcept
+ {
+ switch(rhs.type)
+ {
+ case CommandType::BIND_VERTEX_BUFFERS:
+ {
+ bindVertexBuffers = std::move(rhs.bindVertexBuffers);
+ break;
+ }
+ case CommandType::BIND_INDEX_BUFFER:
+ {
+ bindIndexBuffer = rhs.bindIndexBuffer;
+ break;
+ }
+ case CommandType::BIND_UNIFORM_BUFFER:
+ {
+ bindUniformBuffers = std::move(rhs.bindUniformBuffers);
+ break;
+ }
+ case CommandType::BIND_SAMPLERS:
+ {
+ bindSamplers = std::move(rhs.bindSamplers);
+ break;
+ }
+ case CommandType::BIND_TEXTURES:
+ {
+ bindTextures = std::move(rhs.bindTextures);
+ break;
+ }
+ case CommandType::BIND_PIPELINE:
+ {
+ bindPipeline = rhs.bindPipeline;
+ break;
+ }
+ case CommandType::DRAW:
+ {
+ draw.type = rhs.draw.type;
+ draw.draw = rhs.draw.draw;
+ break;
+ }
+ case CommandType::DRAW_INDEXED:
+ {
+ draw.type = rhs.draw.type;
+ draw.drawIndexed = rhs.draw.drawIndexed;
+ break;
+ }
+ case CommandType::DRAW_INDEXED_INDIRECT:
+ {
+ draw.type = rhs.draw.type;
+ draw.drawIndexedIndirect = rhs.draw.drawIndexedIndirect;
+ break;
+ }
+ case CommandType::FLUSH:
+ {
+ // Nothing to do
+ break;
+ }
+ }
+ type = rhs.type;
+ }
+
+ CommandType type{CommandType::FLUSH}; ///< Type of command
+
+ union
+ {
+ struct
+ {
+ std::vector<Graphics::TextureBinding> textureBindings;
+ } bindTextures{};
+
+ // BindSampler command
+ struct
+ {
+ std::vector<Graphics::SamplerBinding> samplerBindings;
+ } bindSamplers;
+
+ struct
+ {
+ using Binding = VertexBufferBindingDescriptor;
+ std::vector<Binding> vertexBufferBindings;
+ } bindVertexBuffers;
+
+ struct : public IndexBufferBindingDescriptor
+ {
+ } bindIndexBuffer;
+
+ struct
+ {
+ std::vector<UniformBufferBindingDescriptor> uniformBufferBindings{};
+ UniformBufferBindingDescriptor standaloneUniformsBufferBinding{};
+ } bindUniformBuffers;
+
+ struct
+ {
+ const TestGraphicsPipeline* pipeline{nullptr};
+ } bindPipeline;
+
+ struct : public DrawCallDescriptor
+ {
+ } draw;
+ };
+};
+
+
class TestGraphicsCommandBuffer : public Graphics::CommandBuffer
{
public:
TestGraphicsCommandBuffer(TraceCallStack& callstack, TestGlAbstraction& glAbstraction);
+ ~TestGraphicsCommandBuffer()
+ {
+
+ }
void BindVertexBuffers(uint32_t firstBinding,
std::vector<const Graphics::Buffer*> buffers,
- std::vector<uint32_t> offsets);
+ std::vector<uint32_t> offsets) override
+ {
+ mCommands.emplace_back();
+ mCommands.back().type = CommandType::BIND_VERTEX_BUFFERS;
+ auto& bindings = mCommands.back().bindVertexBuffers.vertexBufferBindings;
+ if(bindings.size() < firstBinding + buffers.size())
+ {
+ bindings.resize(firstBinding + buffers.size());
+ auto index = firstBinding;
+ for(auto& buf : buffers)
+ {
+ bindings[index].buffer = static_cast<const TestGraphicsBuffer*>(buf);
+ bindings[index].offset = offsets[index - firstBinding];
+ index++;
+ }
+ }
+ mCallStack.PushCall("BindVertexBuffers", "");
+ }
- void BindUniformBuffers(const std::vector<Graphics::UniformBufferBinding>& bindings);
+ void BindUniformBuffers(const std::vector<Graphics::UniformBufferBinding>& bindings) override
+ {
+ mCommands.emplace_back();
+ auto& cmd = mCommands.back();
+ cmd.type = CommandType::BIND_UNIFORM_BUFFER;
+ auto& bindCmd = cmd.bindUniformBuffers;
+ for(const auto& binding : bindings)
+ {
+ if(binding.buffer)
+ {
+ auto testBuffer = static_cast<const TestGraphicsBuffer*>(binding.buffer);
+ if(testBuffer->IsCPUAllocated()) // standalone uniforms
+ {
+ bindCmd.standaloneUniformsBufferBinding.buffer = testBuffer;
+ bindCmd.standaloneUniformsBufferBinding.offset = binding.offset;
+ bindCmd.standaloneUniformsBufferBinding.binding = binding.binding;
+ bindCmd.standaloneUniformsBufferBinding.emulated = true;
+ }
+ else // Bind regular UBO
+ {
+ // resize binding slots
+ if(binding.binding >= bindCmd.uniformBufferBindings.size())
+ {
+ bindCmd.uniformBufferBindings.resize(binding.binding + 1);
+ }
+ auto& slot = bindCmd.uniformBufferBindings[binding.binding];
+ slot.buffer = testBuffer;
+ slot.offset = binding.offset;
+ slot.binding = binding.binding;
+ slot.emulated = false;
+ }
+ }
+ }
+ mCallStack.PushCall("BindUniformBuffers", "");
+ }
- void BindPipeline(const Graphics::Pipeline& pipeline);
+ void BindPipeline(const Graphics::Pipeline& pipeline) override
+ {
+ mCommands.emplace_back();
+ mCommands.back().type = CommandType::BIND_PIPELINE;
+ mCommands.back().bindPipeline.pipeline = static_cast<const TestGraphicsPipeline*>(&pipeline);
+ mCallStack.PushCall("BindPipeline", "");
+ }
- void BindTextures(std::vector<Graphics::TextureBinding>& textureBindings);
+ void BindTextures(std::vector<Graphics::TextureBinding>& textureBindings) override
+ {
+ mCommands.emplace_back();
+ mCommands.back().type = CommandType::BIND_TEXTURES;
+ mCommands.back().bindTextures.textureBindings = std::move(textureBindings);
+ mCallStack.PushCall("BindTextures", "");
+ }
- void BindSamplers(std::vector<Graphics::SamplerBinding>& samplerBindings);
+ void BindSamplers(std::vector<Graphics::SamplerBinding>& samplerBindings) override
+ {
+ mCommands.emplace_back();
+ mCommands.back().bindSamplers.samplerBindings = std::move(samplerBindings);
+ mCallStack.PushCall("BindSamplers", "");
+ }
void BindPushConstants(void* data,
uint32_t size,
- uint32_t binding);
+ uint32_t binding) override
+ {
+ mCallStack.PushCall("BindPushConstants", "");
+ }
void BindIndexBuffer(const Graphics::Buffer& buffer,
uint32_t offset,
- Graphics::Format format);
+ Graphics::Format format) override
+ {
+ mCommands.emplace_back();
+ mCommands.back().type = CommandType::BIND_INDEX_BUFFER;
+ mCommands.back().bindIndexBuffer.buffer = static_cast<const TestGraphicsBuffer*>(&buffer);
+ mCommands.back().bindIndexBuffer.offset = offset;
+ mCommands.back().bindIndexBuffer.format = format;
+ mCallStack.PushCall("BindIndexBuffer", "");
+ }
- void BeginRenderPass(Graphics::RenderPass& renderPass,
- Graphics::RenderTarget& renderTarget,
- Graphics::Extent2D renderArea,
- std::vector<Graphics::ClearValue> clearValues);
+ void BeginRenderPass(
+ Graphics::RenderPass& renderPass,
+ Graphics::RenderTarget& renderTarget,
+ Graphics::Extent2D renderArea,
+ std::vector<Graphics::ClearValue> clearValues) override
+ {
+ mCallStack.PushCall("BeginRenderPass", "");
+ }
- void EndRenderPass();
+ /**
+ * @brief Ends current render pass
+ *
+ * This command must be issued in order to finalize the render pass.
+ * It's up to the implementation whether anything has to be done but
+ * the Controller may use end RP marker in order to resolve resource
+ * dependencies (for example, to know when target texture is ready
+ * before passing it to another render pass).
+ */
+ void EndRenderPass() override
+ {
+ mCallStack.PushCall("EndRenderPass", "");
+ }
void Draw(
uint32_t vertexCount,
uint32_t instanceCount,
uint32_t firstVertex,
- uint32_t firstInstance);
+ uint32_t firstInstance) override
+ {
+ mCommands.emplace_back();
+ mCommands.back().type = CommandType::DRAW;
+ auto& cmd = mCommands.back().draw;
+ cmd.type = DrawCallDescriptor::Type::DRAW;
+ cmd.draw.vertexCount = vertexCount;
+ cmd.draw.instanceCount = instanceCount;
+ cmd.draw.firstInstance = firstInstance;
+ cmd.draw.firstVertex = firstVertex;
+ mCallStack.PushCall("Draw", "");
+ }
void DrawIndexed(
uint32_t indexCount,
uint32_t instanceCount,
uint32_t firstIndex,
int32_t vertexOffset,
- uint32_t firstInstance);
+ uint32_t firstInstance) override
+ {
+ mCommands.emplace_back();
+ mCommands.back().type = CommandType::DRAW_INDEXED;
+ auto& cmd = mCommands.back().draw;
+ cmd.type = DrawCallDescriptor::Type::DRAW_INDEXED;
+ cmd.drawIndexed.firstIndex = firstIndex;
+ cmd.drawIndexed.firstInstance = firstInstance;
+ cmd.drawIndexed.indexCount = indexCount;
+ cmd.drawIndexed.vertexOffset = vertexOffset;
+ cmd.drawIndexed.instanceCount = instanceCount;
+ mCallStack.PushCall("DrawIndexed", "");
+ }
void DrawIndexedIndirect(
Graphics::Buffer& buffer,
uint32_t offset,
uint32_t drawCount,
- uint32_t stride);
-
- void Reset(Graphics::CommandBuffer& commandBuffer);
-
- void SetScissor(Graphics::Extent2D value);
-
- void SetScissorTestEnable(bool value);
+ uint32_t stride) override
+ {
+ mCommands.emplace_back();
+ mCommands.back().type = CommandType::DRAW_INDEXED_INDIRECT;
+ auto& cmd = mCommands.back().draw;
+ cmd.type = DrawCallDescriptor::Type::DRAW_INDEXED_INDIRECT;
+ cmd.drawIndexedIndirect.buffer = static_cast<const TestGraphicsBuffer*>(&buffer);
+ cmd.drawIndexedIndirect.offset = offset;
+ cmd.drawIndexedIndirect.drawCount = drawCount;
+ cmd.drawIndexedIndirect.stride = stride;
+ mCallStack.PushCall("DrawIndexedIndirect", "");
+ }
- void SetViewport(Graphics::Viewport value);
+ void Reset() override
+ {
+ mCommands.clear();
+ mCallStack.PushCall("Reset", "");
+ }
- void SetViewportEnable(bool value);
+ void SetScissor(Graphics::Extent2D value) override
+ {
+ mCallStack.PushCall("SetScissor", "");
+ }
-public:
- TraceCallStack& mCallStack;
- TestGlAbstraction& mGlAbstraction;
- TestGraphicsPipeline* mPipeline{nullptr};
- std::vector<Graphics::TextureBinding> mTextureBindings{};
+ void SetScissorTestEnable(bool value) override
+ {
+ mCallStack.PushCall("SetScissorTestEnable", "");
+ }
- struct VertexBuffersBinding
+ void SetViewport(Graphics::Viewport value) override
{
- uint32_t firstBinding;
- std::vector<const Graphics::Buffer*> buffers;
- std::vector<uint32_t> offsets;
- };
- VertexBuffersBinding mVertexBufferBindings{};
+ mCallStack.PushCall("SetViewport", "");
+ }
- struct IndexBufferBinding
+ void SetViewportEnable(bool value) override
{
- const Graphics::Buffer* buffer;
- uint32_t offset;
- Graphics::Format format;
- };
- IndexBufferBinding mIndexBufferBinding{};
+ mCallStack.PushCall("SetViewportEnable", "");
+ }
- struct Draw
+ [[nodiscard]] const std::vector<Command>& GetCommands() const
{
- enum class DrawType
- {
- Indexed,
- Unindexed
- } drawType;
- union
- {
- struct IndexedDraw
- {
- uint32_t indexCount;
- uint32_t instanceCount;
- uint32_t firstIndex;
- int32_t vertexOffset;
- uint32_t firstInstance;
- } indexedDraw;
- struct UnindexedDraw
- {
- uint32_t vertexCount;
- uint32_t instanceCount;
- uint32_t firstVertex;
- uint32_t firstInstance;
- } unindexedDraw;
- } u;
- } drawCommand;
+ return mCommands;
+ }
+
+ /**
+ * Returns number of draw commands
+ * @return
+ */
+ int GetDrawCallsCount();
+
+ /**
+ * Retrieves state resolve for selected draw call
+ * @param drawCommandIndex
+ */
+ void GetStateForDrawCall( int drawCallIndex );
+
+ /**
+ * Retrieves commands of specified type
+ */
+ std::vector<Command*> GetCommandsByType( CommandTypeMask mask );
+
+
+private:
+ TraceCallStack& mCallStack;
+ TestGlAbstraction& mGlAbstraction;
+ std::vector<Command> mCommands;
};
} // namespace Dali
for(auto& graphicsCommandBuffer : submitInfo.cmdBuffer)
{
auto commandBuffer = Uncast<TestGraphicsCommandBuffer>(graphicsCommandBuffer);
- for(auto& binding : commandBuffer->mTextureBindings)
+
+ auto value = commandBuffer->GetCommandsByType(0 | CommandType::BIND_TEXTURES);
+ if(!value.empty())
{
- if(binding.texture)
+ // must be fixed
+ for (auto &binding : value[0]->bindTextures.textureBindings)
{
- auto texture = Uncast<TestGraphicsTexture>(binding.texture);
+ if (binding.texture)
+ {
+ auto texture = Uncast<TestGraphicsTexture>(binding.texture);
- texture->Bind(binding.binding);
+ texture->Bind(binding.binding);
- if(binding.sampler)
- {
- auto sampler = Uncast<TestGraphicsSampler>(binding.sampler);
- if(sampler)
+ if (binding.sampler)
{
- sampler->Apply(texture->GetTarget());
+ auto sampler = Uncast<TestGraphicsSampler>(binding.sampler);
+ if (sampler)
+ {
+ sampler->Apply(texture->GetTarget());
+ }
}
- }
- texture->Prepare(); // Ensure native texture is ready
+ texture->Prepare(); // Ensure native texture is ready
+ }
}
}
// IndexBuffer binding,
- auto& indexBufferBinding = commandBuffer->mIndexBufferBinding;
- if(indexBufferBinding.buffer)
+ auto bindIndexBufferCmds = commandBuffer->GetCommandsByType(0 | CommandType::BIND_INDEX_BUFFER);
+ if (!bindIndexBufferCmds.empty())
{
- auto buffer = Uncast<TestGraphicsBuffer>(indexBufferBinding.buffer);
- buffer->Bind();
+ auto &indexBufferBinding = bindIndexBufferCmds[0]->bindIndexBuffer;
+ if (indexBufferBinding.buffer)
+ {
+ auto buffer = Uncast<TestGraphicsBuffer>(indexBufferBinding.buffer);
+ buffer->Bind();
+ }
}
// VertexBuffer binding,
- for(auto graphicsBuffer : commandBuffer->mVertexBufferBindings.buffers)
+ auto bindVertexBufferCmds = commandBuffer->GetCommandsByType(0 | CommandType::BIND_VERTEX_BUFFERS);
+ if (!bindVertexBufferCmds.empty())
{
- auto vertexBuffer = Uncast<TestGraphicsBuffer>(graphicsBuffer);
- vertexBuffer->Bind();
+ for (auto &binding : bindVertexBufferCmds[0]->bindVertexBuffers.vertexBufferBindings)
+ {
+ auto graphicsBuffer = binding.buffer;
+ auto vertexBuffer = Uncast<TestGraphicsBuffer>(graphicsBuffer);
+ vertexBuffer->Bind();
+ }
}
-
// Pipeline attribute setup
- auto& vi = commandBuffer->mPipeline->vertexInputState;
- for(auto& attribute : vi.attributes)
- {
- mGl.EnableVertexAttribArray(attribute.location);
- uint32_t attributeOffset = attribute.offset;
- GLsizei stride = vi.bufferBindings[attribute.binding].stride;
-
- mGl.VertexAttribPointer(attribute.location,
- GetNumComponents(attribute.format),
- GetGlType(attribute.format),
- GL_FALSE, // Not normalized
- stride,
- reinterpret_cast<void*>(attributeOffset));
- }
-
- // Cull face setup
- auto& rasterizationState = commandBuffer->mPipeline->rasterizationState;
- if(rasterizationState.cullMode == Graphics::CullMode::NONE)
+ auto bindPipelineCmds = commandBuffer->GetCommandsByType(0 | CommandType::BIND_PIPELINE);
+ if (!bindPipelineCmds.empty())
{
- mGl.Disable(GL_CULL_FACE);
- }
- else
- {
- mGl.Enable(GL_CULL_FACE);
- mGl.CullFace(GetCullFace(rasterizationState.cullMode));
- }
-
- mGl.FrontFace(GetFrontFace(rasterizationState.frontFace));
- // We don't modify glPolygonMode in our context/abstraction from GL_FILL (the GL default),
- // so it isn't present in the API (and won't have any tests!)
+ auto pipeline = bindPipelineCmds[0]->bindPipeline.pipeline;
+ auto &vi = pipeline->vertexInputState;
+ for (auto &attribute : vi.attributes)
+ {
+ mGl.EnableVertexAttribArray(attribute.location);
+ uint32_t attributeOffset = attribute.offset;
+ GLsizei stride = vi.bufferBindings[attribute.binding].stride;
+
+ mGl.VertexAttribPointer(attribute.location,
+ GetNumComponents(attribute.format),
+ GetGlType(attribute.format),
+ GL_FALSE, // Not normalized
+ stride,
+ reinterpret_cast<void *>(attributeOffset));
+ }
+ // Cull face setup
+ auto &rasterizationState = pipeline->rasterizationState;
+ if (rasterizationState.cullMode == Graphics::CullMode::NONE)
+ {
+ mGl.Disable(GL_CULL_FACE);
+ }
+ else
+ {
+ mGl.Enable(GL_CULL_FACE);
+ mGl.CullFace(GetCullFace(rasterizationState.cullMode));
+ }
- // Blending setup
- auto& colorBlendState = commandBuffer->mPipeline->colorBlendState;
- if(colorBlendState.blendEnable)
- {
- mGl.Enable(GL_BLEND);
+ mGl.FrontFace(GetFrontFace(rasterizationState.frontFace));
+ // We don't modify glPolygonMode in our context/abstraction from GL_FILL (the GL default),
+ // so it isn't present in the API (and won't have any tests!)
- mGl.BlendFuncSeparate(GetBlendFactor(colorBlendState.srcColorBlendFactor),
- GetBlendFactor(colorBlendState.dstColorBlendFactor),
- GetBlendFactor(colorBlendState.srcAlphaBlendFactor),
- GetBlendFactor(colorBlendState.dstAlphaBlendFactor));
- if(colorBlendState.colorBlendOp != colorBlendState.alphaBlendOp)
+ // Blending setup
+ auto &colorBlendState = pipeline->colorBlendState;
+ if (colorBlendState.blendEnable)
{
- mGl.BlendEquationSeparate(GetBlendOp(colorBlendState.colorBlendOp), GetBlendOp(colorBlendState.alphaBlendOp));
+ mGl.Enable(GL_BLEND);
+
+ mGl.BlendFuncSeparate(GetBlendFactor(colorBlendState.srcColorBlendFactor),
+ GetBlendFactor(colorBlendState.dstColorBlendFactor),
+ GetBlendFactor(colorBlendState.srcAlphaBlendFactor),
+ GetBlendFactor(colorBlendState.dstAlphaBlendFactor));
+ if (colorBlendState.colorBlendOp != colorBlendState.alphaBlendOp)
+ {
+ mGl.BlendEquationSeparate(GetBlendOp(colorBlendState.colorBlendOp), GetBlendOp(colorBlendState.alphaBlendOp));
+ }
+ else
+ {
+ mGl.BlendEquation(GetBlendOp(colorBlendState.colorBlendOp));
+ }
+ mGl.BlendColor(colorBlendState.blendConstants[0],
+ colorBlendState.blendConstants[1],
+ colorBlendState.blendConstants[2],
+ colorBlendState.blendConstants[3]);
}
else
{
- mGl.BlendEquation(GetBlendOp(colorBlendState.colorBlendOp));
+ mGl.Disable(GL_BLEND);
}
- mGl.BlendColor(colorBlendState.blendConstants[0],
- colorBlendState.blendConstants[1],
- colorBlendState.blendConstants[2],
- colorBlendState.blendConstants[3]);
- }
- else
- {
- mGl.Disable(GL_BLEND);
- }
- // draw call
- auto topology = commandBuffer->mPipeline->inputAssemblyState.topology;
+ // draw call
+ auto topology = pipeline->inputAssemblyState.topology;
- if(commandBuffer->drawCommand.drawType == TestGraphicsCommandBuffer::Draw::DrawType::Indexed)
- {
- mGl.DrawElements(GetTopology(topology),
- static_cast<GLsizei>(commandBuffer->drawCommand.u.indexedDraw.indexCount),
- GL_UNSIGNED_SHORT,
- reinterpret_cast<void*>(commandBuffer->drawCommand.u.indexedDraw.firstIndex));
- }
- else
- {
- mGl.DrawArrays(GetTopology(topology), 0, commandBuffer->drawCommand.u.unindexedDraw.vertexCount);
- }
+ // UniformBuffer binding (once we know pipeline)
+ auto bindUniformBuffersCmds = commandBuffer->GetCommandsByType(0 | CommandType::BIND_UNIFORM_BUFFER);
+ if (!bindUniformBuffersCmds.empty())
+ {
+ auto buffer = bindUniformBuffersCmds[0]->bindUniformBuffers.standaloneUniformsBufferBinding;
+ printf("%p\n", buffer.buffer);
- // attribute clear
- for(auto& attribute : vi.attributes)
- {
- mGl.DisableVertexAttribArray(attribute.location);
+ // based on reflection, issue gl calls
+ buffer.buffer->BindAsUniformBuffer( static_cast<const TestGraphicsProgram*>(pipeline->programState.program) );
+ }
+
+ auto drawCmds = commandBuffer->GetCommandsByType( 0 |
+ CommandType::DRAW |
+ CommandType::DRAW_INDEXED_INDIRECT |
+ CommandType::DRAW_INDEXED );
+
+ if(!drawCmds.empty())
+ {
+ if (drawCmds[0]->draw.type == DrawCallDescriptor::Type::DRAW_INDEXED )
+ {
+ mGl.DrawElements(GetTopology(topology),
+ static_cast<GLsizei>(drawCmds[0]->draw.drawIndexed.indexCount),
+ GL_UNSIGNED_SHORT,
+ reinterpret_cast<void *>(drawCmds[0]->draw.drawIndexed.firstIndex));
+ }
+ else
+ {
+ mGl.DrawArrays(GetTopology(topology), 0, drawCmds[0]->draw.draw.vertexCount);
+ }
+ }
+ // attribute clear
+ for (auto &attribute : vi.attributes)
+ {
+ mGl.DisableVertexAttribArray(attribute.location);
+ }
}
}
}
#include "test-graphics-reflection.h"
#include <dali/public-api/object/property-map.h>
-
+#include <vector>
+#include <string>
namespace Dali
{
+namespace
+{
+// Add members
+struct UniformData
+{
+ std::string name;
+ Property::Type type;
+ UniformData( const std::string& name, Property::Type type = Property::Type::NONE)
+ : name(name), type(type)
+ {}
+};
+static const std::vector<UniformData> UNIFORMS =
+ {
+ UniformData("uRendererColor",Property::Type::FLOAT),
+ UniformData("uCustom", Property::Type::INTEGER),
+ UniformData("uCustom3", Property::Type::VECTOR3),
+ UniformData("uFadeColor", Property::Type::VECTOR4),
+ UniformData("uUniform1", Property::Type::VECTOR4),
+ UniformData("uUniform2", Property::Type::VECTOR4),
+ UniformData("uUniform3", Property::Type::VECTOR4),
+ UniformData("uFadeProgress", Property::Type::FLOAT),
+ UniformData("uANormalMatrix", Property::Type::MATRIX3),
+ UniformData("sEffect", Property::Type::FLOAT),
+ UniformData("sTexture", Property::Type::FLOAT),
+ UniformData("sTextureRect", Property::Type::FLOAT),
+ UniformData("sGloss", Property::Type::FLOAT),
+ UniformData("uColor", Property::Type::VECTOR4),
+ UniformData("uModelMatrix", Property::Type::MATRIX),
+ UniformData("uModelView", Property::Type::MATRIX),
+ UniformData("uMvpMatrix", Property::Type::MATRIX),
+ UniformData("uNormalMatrix", Property::Type::MATRIX3),
+ UniformData("uProjection", Property::Type::MATRIX),
+ UniformData("uSize", Property::Type::VECTOR3),
+ UniformData("uViewMatrix", Property::Type::MATRIX),
+ UniformData("uLightCameraProjectionMatrix", Property::Type::MATRIX),
+ UniformData("uLightCameraViewMatrix", Property::Type::MATRIX),
+
+ };
+}
+
TestGraphicsReflection::TestGraphicsReflection(TestGlAbstraction& gl, Property::Array& vfs)
-: mGl(gl)
+ : mGl(gl)
{
for(Property::Array::SizeType i = 0; i < vfs.Count(); ++i)
{
uint32_t TestGraphicsReflection::GetUniformBlockCount() const
{
- return 0u;
+ return 1u;
}
uint32_t TestGraphicsReflection::GetUniformBlockBinding(uint32_t index) const
uint32_t TestGraphicsReflection::GetUniformBlockSize(uint32_t index) const
{
- return 0u;
+ // 64 bytes per uniform (64 = 4x4 matrix)
+ // TODO: fix if array will be used
+ return 64 * UNIFORMS.size();
}
bool TestGraphicsReflection::GetUniformBlock(uint32_t index, Dali::Graphics::UniformBlockInfo& out) const
{
+ auto& info = out;
+ info.name = "";
+ info.members = {};
+ info.binding = 0;
+ info.size = 64 * UNIFORMS.size();
+ info.descriptorSet = 0;
+ info.members.clear();
+ int loc = 0;
+ for( const auto& data : UNIFORMS )
+ {
+ info.members.emplace_back();
+ auto& item = info.members.back();
+ item.name = data.name;
+ item.binding = 0;
+ item.offset = loc*64;
+ item.location = loc++;
+ item.bufferIndex = 0;
+ item.uniformClass = Graphics::UniformClass::UNIFORM;
+ }
return true;
}
uint32_t TestGraphicsReflection::GetUniformBlockMemberCount(uint32_t blockIndex) const
{
- return 0u;
+ return UNIFORMS.size();
}
std::string TestGraphicsReflection::GetUniformBlockMemberName(uint32_t blockIndex, uint32_t memberLocation) const
{
- return std::string{};
+ return UNIFORMS[memberLocation].name;
}
uint32_t TestGraphicsReflection::GetUniformBlockMemberOffset(uint32_t blockIndex, uint32_t memberLocation) const
return Graphics::ShaderLanguage::GLSL_3_1;
}
+Dali::Property::Type TestGraphicsReflection::GetMemberType( int blockIndex, int location) const
+{
+ return UNIFORMS[location].type;
+}
+
} // namespace Dali
}
}
+ Dali::Property::Type GetMemberType( int blockIndex, int location) const;
+
TestGlAbstraction& mGl;
mutable std::vector<std::string> mAttributes;
};
const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
application.GetGlAbstraction().GetBufferDataCalls();
- DALI_TEST_EQUALS(bufferDataCalls.size(), 1u, TEST_LOCATION);
+ DALI_TEST_EQUALS(bufferDataCalls.size(), 3u, TEST_LOCATION);
DALI_TEST_EQUALS(bufferDataCalls[0], 4 * sizeof(TexturedQuadVertex), TEST_LOCATION);
}
const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
application.GetGlAbstraction().GetBufferDataCalls();
- DALI_TEST_EQUALS(bufferDataCalls.size(), 1u, TEST_LOCATION);
+ DALI_TEST_EQUALS(bufferDataCalls.size(), 3u, TEST_LOCATION);
DALI_TEST_EQUALS(bufferDataCalls[0], 4 * sizeof(TexturedQuadVertex), TEST_LOCATION);
}
std::vector<Graphics::SubmitInfo>& submissions = graphics.mSubmitStack;
DALI_TEST_EQUALS(submissions.size(), 1, TEST_LOCATION);
DALI_TEST_EQUALS(submissions[0].cmdBuffer.size(), 1, TEST_LOCATION);
- const TestGraphicsCommandBuffer* cmdBuf = static_cast<TestGraphicsCommandBuffer*>((submissions[0].cmdBuffer[0]));
- auto pipeline = cmdBuf->mPipeline;
+ TestGraphicsCommandBuffer* cmdBuf = static_cast<TestGraphicsCommandBuffer*>((submissions[0].cmdBuffer[0]));
+ //auto pipeline = cmdBuf->mPipeline;
+ auto result = cmdBuf->GetCommandsByType( 0 | CommandType::BIND_PIPELINE );
+ auto pipeline = result[0]->bindPipeline.pipeline;
+
if(pipeline)
{
DALI_TEST_EQUALS(pipeline->vertexInputState.attributes.size(), 12, TEST_LOCATION);
application.Render(100);
// register another custom property as well
- Property::Index customIndex = shader.RegisterProperty("uCustom", Vector3(1, 2, 3));
+ Property::Index customIndex = shader.RegisterProperty("uCustom3", Vector3(1, 2, 3));
DALI_TEST_EQUALS(shader.GetProperty<Vector3>(customIndex), Vector3(1, 2, 3), TEST_LOCATION);
application.SendNotification();
DALI_TEST_EQUALS(actualValue, Color::TRANSPARENT, TEST_LOCATION);
Vector3 customValue;
- DALI_TEST_CHECK(gl.GetUniformValue<Vector3>("uCustom", customValue));
+ DALI_TEST_CHECK(gl.GetUniformValue<Vector3>("uCustom3", customValue));
DALI_TEST_EQUALS(customValue, Vector3(1, 2, 3), TEST_LOCATION);
END_TEST;
}
const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
application.GetGlAbstraction().GetBufferDataCalls();
- DALI_TEST_EQUALS(bufferDataCalls.size(), 1u, TEST_LOCATION);
+ DALI_TEST_EQUALS(bufferDataCalls.size(), 3u, TEST_LOCATION);
DALI_TEST_EQUALS(bufferDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION);
}
const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
application.GetGlAbstraction().GetBufferDataCalls();
- DALI_TEST_EQUALS(bufferDataCalls.size(), 1u, TEST_LOCATION);
+ DALI_TEST_EQUALS(bufferDataCalls.size(), 2u, TEST_LOCATION);
DALI_TEST_EQUALS(bufferDataCalls[0], sizeof(texturedQuadVertexData), TEST_LOCATION);
}
const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
application.GetGlAbstraction().GetBufferDataCalls();
- DALI_TEST_EQUALS(bufferSubDataCalls.size(), 1u, TEST_LOCATION);
- DALI_TEST_EQUALS(bufferDataCalls.size(), 1u, TEST_LOCATION);
+ // test below includes updates of uniform buffers
+ DALI_TEST_EQUALS(bufferSubDataCalls.size(), 17u, TEST_LOCATION);
+ DALI_TEST_EQUALS(bufferDataCalls.size(), 3u, TEST_LOCATION);
if(bufferSubDataCalls.size())
{