X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit%2Fdali-toolkit-test-utils%2Ftest-graphics-controller.cpp;h=578285bd701315a71830e0a3ff5068d532d1e4e4;hb=refs%2Ftags%2Fgraphics-backend-pre-release-1;hp=4732a9adbf33463c8b8bee441282b161a21c9c17;hpb=cef353d5b0add148dd99197bf25fb47a9c23d4d9;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-graphics-controller.cpp b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-graphics-controller.cpp index 4732a9a..578285b 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-graphics-controller.cpp +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-graphics-controller.cpp @@ -22,11 +22,36 @@ #include "test-graphics-texture.h" #include +#include #include #include namespace Dali { +template +T* Uncast(const Graphics::CommandBuffer* object) +{ + return const_cast(static_cast(object)); +} + +template +T* Uncast(const Graphics::Texture* object) +{ + return const_cast(static_cast(object)); +} + +template +T* Uncast(const Graphics::Sampler* object) +{ + return const_cast(static_cast(object)); +} + +template +T* Uncast(const Graphics::Buffer* object) +{ + return const_cast(static_cast(object)); +} + std::ostream& operator<<(std::ostream& o, const Graphics::BufferCreateInfo& bufferCreateInfo) { return o << "usage:" << std::hex << bufferCreateInfo.usage << ", size:" << std::dec << bufferCreateInfo.size; @@ -140,39 +165,181 @@ std::ostream& operator<<(std::ostream& o, const Graphics::SamplerCreateInfo& cre return o; } +class TestGraphicsMemory : public Graphics::Memory +{ +public: + TestGraphicsMemory(TraceCallStack& callStack, TestGraphicsBuffer& buffer, uint32_t mappedOffset, uint32_t mappedSize) + : mCallStack(callStack), + mBuffer(buffer), + mMappedOffset(mappedOffset), + mMappedSize(mappedSize) + { + } + + void* LockRegion(uint32_t offset, uint32_t size) override + { + std::ostringstream o; + o << offset << ", " << size; + mCallStack.PushCall("Memory::LockRegion", o.str()); + + if(offset > mMappedOffset + mMappedSize || + size + offset > mMappedOffset + mMappedSize) + { + fprintf(stderr, "TestGraphics.Memory::LockRegion() Out of bounds"); + mBuffer.memory.resize(mMappedOffset + offset + size); // Grow to prevent memcpy from crashing + } + mLockedOffset = offset; + mLockedSize = size; + return &mBuffer.memory[mMappedOffset + offset]; + } + + void Unlock(bool flush) override + { + mCallStack.PushCall("Memory::Unlock", (flush ? "Flush" : "NoFlush")); + if(flush) + { + Flush(); + } + } + + void Flush() override + { + mCallStack.PushCall("Memory::Flush", ""); + mBuffer.Bind(); + mBuffer.Upload(mMappedOffset + mLockedOffset, mLockedSize); + mBuffer.Unbind(); + } + + TraceCallStack& mCallStack; + TestGraphicsBuffer& mBuffer; + uint32_t mMappedOffset; + uint32_t mMappedSize; + uint32_t mLockedOffset; + uint32_t mLockedSize; +}; + TestGraphicsController::TestGraphicsController() +: mCallStack(true, "TestGraphicsController."), + mCommandBufferCallStack(true, "TestCommandBuffer.") { mCallStack.Enable(true); - mCallStack.EnableLogging(true); mCommandBufferCallStack.Enable(true); - mCommandBufferCallStack.EnableLogging(true); - auto& trace = mGlAbstraction.GetTextureTrace(); + auto& trace = mGl.GetTextureTrace(); trace.Enable(true); trace.EnableLogging(true); } +int GetNumComponents(Graphics::VertexInputFormat vertexFormat) +{ + switch(vertexFormat) + { + case Graphics::VertexInputFormat::UNDEFINED: + case Graphics::VertexInputFormat::FLOAT: + case Graphics::VertexInputFormat::INTEGER: + return 1; + case Graphics::VertexInputFormat::IVECTOR2: + case Graphics::VertexInputFormat::FVECTOR2: + return 2; + case Graphics::VertexInputFormat::IVECTOR3: + case Graphics::VertexInputFormat::FVECTOR3: + return 3; + case Graphics::VertexInputFormat::FVECTOR4: + case Graphics::VertexInputFormat::IVECTOR4: + return 4; + } + return 1; +} + +GLint GetSize(Graphics::VertexInputFormat vertexFormat) +{ + switch(vertexFormat) + { + case Graphics::VertexInputFormat::UNDEFINED: + return 1u; + case Graphics::VertexInputFormat::INTEGER: + case Graphics::VertexInputFormat::IVECTOR2: + case Graphics::VertexInputFormat::IVECTOR3: + case Graphics::VertexInputFormat::IVECTOR4: + return 2u; + case Graphics::VertexInputFormat::FLOAT: + case Graphics::VertexInputFormat::FVECTOR2: + case Graphics::VertexInputFormat::FVECTOR3: + case Graphics::VertexInputFormat::FVECTOR4: + return 4u; + } + return 1u; +} + +GLint GetGlType(Graphics::VertexInputFormat vertexFormat) +{ + switch(vertexFormat) + { + case Graphics::VertexInputFormat::UNDEFINED: + return GL_BYTE; + case Graphics::VertexInputFormat::INTEGER: + case Graphics::VertexInputFormat::IVECTOR2: + case Graphics::VertexInputFormat::IVECTOR3: + case Graphics::VertexInputFormat::IVECTOR4: + return GL_SHORT; + case Graphics::VertexInputFormat::FLOAT: + case Graphics::VertexInputFormat::FVECTOR2: + case Graphics::VertexInputFormat::FVECTOR3: + case Graphics::VertexInputFormat::FVECTOR4: + return GL_FLOAT; + } + return GL_BYTE; +} + +GLenum GetTopology(Graphics::PrimitiveTopology topology) +{ + switch(topology) + { + case Graphics::PrimitiveTopology::POINT_LIST: + return GL_POINTS; + + case Graphics::PrimitiveTopology::LINE_LIST: + return GL_LINES; + + case Graphics::PrimitiveTopology::LINE_LOOP: + return GL_LINE_LOOP; + + case Graphics::PrimitiveTopology::LINE_STRIP: + return GL_LINE_STRIP; + + case Graphics::PrimitiveTopology::TRIANGLE_LIST: + return GL_TRIANGLES; + + case Graphics::PrimitiveTopology::TRIANGLE_STRIP: + return GL_TRIANGLE_STRIP; + + case Graphics::PrimitiveTopology::TRIANGLE_FAN: + return GL_TRIANGLE_FAN; + } + return GL_TRIANGLES; +} + void TestGraphicsController::SubmitCommandBuffers(const Graphics::SubmitInfo& submitInfo) { - std::ostringstream out; TraceCallStack::NamedParams namedParams; - out << "cmdBuffer[" << submitInfo.cmdBuffer.size() << "], flags:" << std::hex << submitInfo.flags; - namedParams["submitInfo"] = out.str(); + namedParams["submitInfo"] << "cmdBuffer[" << submitInfo.cmdBuffer.size() + << "], flags:" << std::hex << submitInfo.flags; - mCallStack.PushCall("SubmitCommandBuffers", "", namedParams); + mCallStack.PushCall("Controller::SubmitCommandBuffers", "", namedParams); - for(auto& commandBuffer : submitInfo.cmdBuffer) + for(auto& graphicsCommandBuffer : submitInfo.cmdBuffer) { - for(auto& binding : (static_cast(commandBuffer))->mTextureBindings) + auto commandBuffer = Uncast(graphicsCommandBuffer); + for(auto& binding : commandBuffer->mTextureBindings) { if(binding.texture) { - auto texture = const_cast(static_cast(binding.texture)); + auto texture = Uncast(binding.texture); texture->Bind(binding.binding); if(binding.sampler) { - auto sampler = const_cast(static_cast(binding.sampler)); + auto sampler = Uncast(binding.sampler); if(sampler) { sampler->Apply(texture->GetTarget()); @@ -182,6 +349,58 @@ void TestGraphicsController::SubmitCommandBuffers(const Graphics::SubmitInfo& su texture->Prepare(); // Ensure native texture is ready } } + + // IndexBuffer binding, + auto& indexBufferBinding = commandBuffer->mIndexBufferBinding; + if(indexBufferBinding.buffer) + { + auto buffer = Uncast(indexBufferBinding.buffer); + buffer->Bind(); + } + + // VertexBuffer binding, + for(auto graphicsBuffer : commandBuffer->mVertexBufferBindings.buffers) + { + auto vertexBuffer = Uncast(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(attributeOffset)); + } + + // draw call + auto topology = commandBuffer->mPipeline->inputAssemblyState.topology; + + if(commandBuffer->drawCommand.drawType == TestGraphicsCommandBuffer::Draw::DrawType::Indexed) + { + mGl.DrawElements(GetTopology(topology), + static_cast(commandBuffer->drawCommand.u.indexedDraw.indexCount), + GL_UNSIGNED_SHORT, + reinterpret_cast(commandBuffer->drawCommand.u.indexedDraw.firstIndex)); + } + else + { + mGl.DrawArrays(GetTopology(topology), 0, commandBuffer->drawCommand.u.unindexedDraw.vertexCount); + } + + // attribute clear + for(auto& attribute : vi.attributes) + { + mGl.DisableVertexAttribArray(attribute.location); + } } } @@ -191,11 +410,9 @@ void TestGraphicsController::SubmitCommandBuffers(const Graphics::SubmitInfo& su */ void TestGraphicsController::PresentRenderTarget(Graphics::RenderTarget* renderTarget) { - std::ostringstream out; TraceCallStack::NamedParams namedParams; - out << std::hex << renderTarget; - namedParams["renderTarget"] = out.str(); - mCallStack.PushCall("PresentRenderTarget", "", namedParams); + namedParams["renderTarget"] << std::hex << renderTarget; + mCallStack.PushCall("Controller::PresentRenderTarget", "", namedParams); } /** @@ -203,7 +420,7 @@ void TestGraphicsController::PresentRenderTarget(Graphics::RenderTarget* renderT */ void TestGraphicsController::WaitIdle() { - mCallStack.PushCall("WaitIdle", ""); + mCallStack.PushCall("Controller::WaitIdle", ""); } /** @@ -211,7 +428,7 @@ void TestGraphicsController::WaitIdle() */ void TestGraphicsController::Pause() { - mCallStack.PushCall("Pause", ""); + mCallStack.PushCall("Controller::Pause", ""); } /** @@ -219,21 +436,17 @@ void TestGraphicsController::Pause() */ void TestGraphicsController::Resume() { - mCallStack.PushCall("Resume", ""); + mCallStack.PushCall("Controller::Resume", ""); } void TestGraphicsController::UpdateTextures(const std::vector& updateInfoList, const std::vector& sourceList) { - std::ostringstream out; TraceCallStack::NamedParams namedParams; - out << "[" << updateInfoList.size() << "]:"; - namedParams["updateInfoList"] = out.str(); - out.str(""); - out << "[" << sourceList.size() << "]:"; - namedParams["sourceList"] = out.str(); + namedParams["updateInfoList"] << "[" << updateInfoList.size() << "]:"; + namedParams["sourceList"] << "[" << sourceList.size() << "]:"; - mCallStack.PushCall("UpdateTextures", "", namedParams); + mCallStack.PushCall("Controller::UpdateTextures", "", namedParams); // Call either TexImage2D or TexSubImage2D for(unsigned int i = 0; i < updateInfoList.size(); ++i) @@ -250,29 +463,27 @@ void TestGraphicsController::UpdateTextures(const std::vector TestGraphicsController::CreateBuffer(const Graphics::BufferCreateInfo& bufferCreateInfo, Graphics::UniquePtr&& oldBuffer) +Graphics::UniquePtr TestGraphicsController::CreateBuffer(const Graphics::BufferCreateInfo& createInfo, Graphics::UniquePtr&& oldBuffer) { std::ostringstream oss; - oss << "bufferCreateInfo:" << bufferCreateInfo; - mCallStack.PushCall("CreateBuffer", oss.str()); - - return Graphics::MakeUnique(); + oss << "bufferCreateInfo:" << createInfo; + mCallStack.PushCall("Controller::CreateBuffer", oss.str()); + return Graphics::MakeUnique(mCallStack, mGl, createInfo.size, createInfo.usage); } Graphics::UniquePtr TestGraphicsController::CreateCommandBuffer(const Graphics::CommandBufferCreateInfo& commandBufferCreateInfo, Graphics::UniquePtr&& oldCommandBuffer) { std::ostringstream oss; oss << "commandBufferCreateInfo:" << commandBufferCreateInfo; - mCallStack.PushCall("CreateCommandBuffer", oss.str()); - return Graphics::MakeUnique(mCommandBufferCallStack, mGlAbstraction); + mCallStack.PushCall("Controller::CreateCommandBuffer", oss.str()); + return Graphics::MakeUnique(mCommandBufferCallStack, mGl); } Graphics::UniquePtr TestGraphicsController::CreateRenderPass(const Graphics::RenderPassCreateInfo& renderPassCreateInfo, Graphics::UniquePtr&& oldRenderPass) { - mCallStack.PushCall("CreateRenderPass", ""); + mCallStack.PushCall("Controller::CreateRenderPass", ""); return nullptr; } Graphics::UniquePtr TestGraphicsController::CreateTexture(const Graphics::TextureCreateInfo& textureCreateInfo, Graphics::UniquePtr&& oldTexture) { - std::ostringstream params, oss; - params << "textureCreateInfo:" << textureCreateInfo; TraceCallStack::NamedParams namedParams; - oss << textureCreateInfo; - namedParams["textureCreateInfo"] = oss.str(); - mCallStack.PushCall("CreateTexture", params.str(), namedParams); + namedParams["textureCreateInfo"] << textureCreateInfo; + mCallStack.PushCall("Controller::CreateTexture", namedParams.str(), namedParams); - return Graphics::MakeUnique(mGlAbstraction, textureCreateInfo); + return Graphics::MakeUnique(mGl, textureCreateInfo); } Graphics::UniquePtr TestGraphicsController::CreateFramebuffer(const Graphics::FramebufferCreateInfo& framebufferCreateInfo, Graphics::UniquePtr&& oldFramebuffer) { - mCallStack.PushCall("CreateFramebuffer", ""); + mCallStack.PushCall("Controller::CreateFramebuffer", ""); return nullptr; } Graphics::UniquePtr TestGraphicsController::CreatePipeline(const Graphics::PipelineCreateInfo& pipelineCreateInfo, Graphics::UniquePtr&& oldPipeline) { - mCallStack.PushCall("CreatePipeline", ""); - return nullptr; + mCallStack.PushCall("Controller::CreatePipeline", ""); + return std::make_unique(mGl, pipelineCreateInfo); } Graphics::UniquePtr TestGraphicsController::CreateShader(const Graphics::ShaderCreateInfo& shaderCreateInfo, Graphics::UniquePtr&& oldShader) { - mCallStack.PushCall("CreateShader", ""); + mCallStack.PushCall("Controller::CreateShader", ""); return nullptr; } Graphics::UniquePtr TestGraphicsController::CreateSampler(const Graphics::SamplerCreateInfo& samplerCreateInfo, Graphics::UniquePtr&& oldSampler) { - std::ostringstream params, oss; - params << "samplerCreateInfo:" << samplerCreateInfo; TraceCallStack::NamedParams namedParams; - oss << samplerCreateInfo; - namedParams["samplerCreateInfo"] = oss.str(); - mCallStack.PushCall("CreateSampler", params.str(), namedParams); + namedParams["samplerCreateInfo"] << samplerCreateInfo; + mCallStack.PushCall("Controller::CreateSampler", namedParams.str(), namedParams); - return Graphics::MakeUnique(mGlAbstraction, samplerCreateInfo); + return Graphics::MakeUnique(mGl, samplerCreateInfo); } Graphics::UniquePtr TestGraphicsController::CreateRenderTarget(const Graphics::RenderTargetCreateInfo& renderTargetCreateInfo, Graphics::UniquePtr&& oldRenderTarget) { - mCallStack.PushCall("CreateRenderTarget", ""); + mCallStack.PushCall("Controller::CreateRenderTarget", ""); return nullptr; } Graphics::UniquePtr TestGraphicsController::MapBufferRange(const Graphics::MapBufferInfo& mapInfo) { - mCallStack.PushCall("MapBufferRange", ""); - return nullptr; + mCallStack.PushCall("Controller::MapBufferRange", ""); + + auto buffer = static_cast(mapInfo.buffer); + buffer->memory.resize(mapInfo.offset + mapInfo.size); // For initial testing, allow writes past capacity + + return std::make_unique(mCallStack, *buffer, mapInfo.offset, mapInfo.size); } Graphics::UniquePtr TestGraphicsController::MapTextureRange(const Graphics::MapTextureInfo& mapInfo) { - mCallStack.PushCall("MapTextureRange", ""); + mCallStack.PushCall("Controller::MapTextureRange", ""); return nullptr; } void TestGraphicsController::UnmapMemory(Graphics::UniquePtr memory) { - mCallStack.PushCall("UnmapMemory", ""); + mCallStack.PushCall("Controller::UnmapMemory", ""); } Graphics::MemoryRequirements TestGraphicsController::GetTextureMemoryRequirements(Graphics::Texture& texture) const { - mCallStack.PushCall("GetTextureMemoryRequirements", ""); + mCallStack.PushCall("Controller::GetTextureMemoryRequirements", ""); return Graphics::MemoryRequirements{}; } Graphics::MemoryRequirements TestGraphicsController::GetBufferMemoryRequirements(Graphics::Buffer& buffer) const { - mCallStack.PushCall("GetBufferMemoryRequirements", ""); + mCallStack.PushCall("Controller::GetBufferMemoryRequirements", ""); return Graphics::MemoryRequirements{}; } const Graphics::TextureProperties& TestGraphicsController::GetTextureProperties(const Graphics::Texture& texture) { static Graphics::TextureProperties textureProperties{}; - mCallStack.PushCall("GetTextureProperties", ""); + mCallStack.PushCall("Controller::GetTextureProperties", ""); return textureProperties; } bool TestGraphicsController::PipelineEquals(const Graphics::Pipeline& pipeline0, const Graphics::Pipeline& pipeline1) const { - mCallStack.PushCall("PipelineEquals", ""); + mCallStack.PushCall("Controller::PipelineEquals", ""); return false; }