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=08867195432360e2a431ff8c9e8ef6e26dcf6296;hb=HEAD;hp=a3a0feef74fb43501547271093e959e9495eacb4;hpb=2022199840909d30df3f6a2935bcfcf9da4c597f;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 a3a0fee..24bb51e 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 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2023 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. @@ -16,6 +16,7 @@ #include "test-graphics-controller.h" +#include #include "test-graphics-buffer.h" #include "test-graphics-command-buffer.h" #include "test-graphics-framebuffer.h" @@ -24,15 +25,33 @@ #include "test-graphics-render-target.h" #include "test-graphics-sampler.h" #include "test-graphics-shader.h" +#include "test-graphics-sync-object.h" #include "test-graphics-texture.h" #include +#include #include #include +#include #include namespace Dali { +namespace +{ +template +struct TestGraphicsDeleter +{ + TestGraphicsDeleter() = default; + void operator()(T* object) + { + // Discard resource + object->DiscardResource(); + } +}; + +} //namespace + std::ostream& operator<<(std::ostream& o, const Graphics::BufferCreateInfo& bufferCreateInfo) { return o << "usage:" << std::hex << bufferCreateInfo.usage << ", size:" << std::dec << bufferCreateInfo.size; @@ -77,7 +96,7 @@ std::ostream& operator<<(std::ostream& o, const Graphics::TextureCreateInfo& cre << " usageFlags:" << std::hex << createInfo.usageFlags << " data:" << std::hex << createInfo.data << " dataSize:" << std::dec << createInfo.dataSize - << " nativeImagePtr:" << std::hex << createInfo.nativeImagePtr; + << " nativeImagePtr:" << std::hex << createInfo.nativeImagePtr.Get(); return o; } @@ -378,8 +397,81 @@ GLenum GetBlendOp(Graphics::BlendOp blendOp) case Graphics::BlendOp::MAX: op = GL_MAX; break; - - // @todo Add advanced blend equations + case Graphics::BlendOp::MULTIPLY: + { + op = GL_MULTIPLY; + break; + } + case Graphics::BlendOp::SCREEN: + { + op = GL_SCREEN; + break; + } + case Graphics::BlendOp::OVERLAY: + { + op = GL_OVERLAY; + break; + } + case Graphics::BlendOp::DARKEN: + { + op = GL_DARKEN; + break; + } + case Graphics::BlendOp::LIGHTEN: + { + op = GL_LIGHTEN; + break; + } + case Graphics::BlendOp::COLOR_DODGE: + { + op = GL_COLORDODGE; + break; + } + case Graphics::BlendOp::COLOR_BURN: + { + op = GL_COLORBURN; + break; + } + case Graphics::BlendOp::HARD_LIGHT: + { + op = GL_HARDLIGHT; + break; + } + case Graphics::BlendOp::SOFT_LIGHT: + { + op = GL_SOFTLIGHT; + break; + } + case Graphics::BlendOp::DIFFERENCE: + { + op = GL_DIFFERENCE; + break; + } + case Graphics::BlendOp::EXCLUSION: + { + op = GL_EXCLUSION; + break; + } + case Graphics::BlendOp::HUE: + { + op = GL_HSL_HUE; + break; + } + case Graphics::BlendOp::SATURATION: + { + op = GL_HSL_SATURATION; + break; + } + case Graphics::BlendOp::COLOR: + { + op = GL_HSL_COLOR; + break; + } + case Graphics::BlendOp::LUMINOSITY: + { + op = GL_HSL_LUMINOSITY; + break; + } } return op; } @@ -510,15 +602,15 @@ public: }; TestGraphicsController::TestGraphicsController() -: mCallStack(true, "TestGraphicsController."), - mCommandBufferCallStack(true, "TestCommandBuffer."), - mFrameBufferCallStack(true, "TestFrameBuffer.") +: mCallStack(false, "TestGraphicsController."), + mCommandBufferCallStack(false, "TestCommandBuffer."), + mFrameBufferCallStack(false, "TestFrameBuffer.") { mCallStack.Enable(true); mCommandBufferCallStack.Enable(true); auto& trace = mGl.GetTextureTrace(); trace.Enable(true); - trace.EnableLogging(true); + trace.EnableLogging(false); } void TestGraphicsController::SubmitCommandBuffers(const Graphics::SubmitInfo& submitInfo) @@ -599,11 +691,14 @@ void TestGraphicsController::ProcessCommandBuffer(TestGraphicsCommandBuffer& com } case CommandType::BIND_UNIFORM_BUFFER: { - auto& bindings = cmd.data.bindUniformBuffers; - auto buffer = bindings.standaloneUniformsBufferBinding; + if(currentPipeline) + { + auto& bindings = cmd.data.bindUniformBuffers; + auto buffer = bindings.standaloneUniformsBufferBinding; - // based on reflection, issue gl calls - buffer.buffer->BindAsUniformBuffer(static_cast(currentPipeline->programState.program)); + // based on reflection, issue gl calls + buffer.buffer->BindAsUniformBuffer(static_cast(currentPipeline->programState.program), bindings.standaloneUniformsBufferBinding); + } break; } case CommandType::BIND_SAMPLERS: @@ -616,27 +711,70 @@ void TestGraphicsController::ProcessCommandBuffer(TestGraphicsCommandBuffer& com BindPipeline(currentPipeline); break; } + case CommandType::DRAW_NATIVE: + { + auto info = &cmd.data.draw.drawNative.drawNativeInfo; + + if(info->glesNativeInfo.eglSharedContextStoragePointer) + { + auto* anyContext = reinterpret_cast(info->glesNativeInfo.eglSharedContextStoragePointer); + *anyContext = reinterpret_cast(0x12345678u); + } + + CallbackBase::ExecuteReturn(*info->callback, info->userData); + break; + } case CommandType::DRAW: { - mGl.DrawArrays(GetTopology(currentPipeline->inputAssemblyState.topology), - 0, - cmd.data.draw.draw.vertexCount); + if(currentPipeline) + { + if(cmd.data.draw.draw.instanceCount == 0) + { + mGl.DrawArrays(GetTopology(currentPipeline->inputAssemblyState.topology), + cmd.data.draw.draw.firstVertex, + cmd.data.draw.draw.vertexCount); + } + else + { + mGl.DrawArraysInstanced(GetTopology(currentPipeline->inputAssemblyState.topology), + cmd.data.draw.draw.firstVertex, + cmd.data.draw.draw.vertexCount, + cmd.data.draw.draw.instanceCount); + } + } break; } case CommandType::DRAW_INDEXED: { - mGl.DrawElements(GetTopology(currentPipeline->inputAssemblyState.topology), - static_cast(cmd.data.draw.drawIndexed.indexCount), - GL_UNSIGNED_SHORT, - reinterpret_cast(cmd.data.draw.drawIndexed.firstIndex)); + if(currentPipeline) + { + if(cmd.data.draw.draw.instanceCount == 0) + { + mGl.DrawElements(GetTopology(currentPipeline->inputAssemblyState.topology), + static_cast(cmd.data.draw.drawIndexed.indexCount), + GL_UNSIGNED_SHORT, + reinterpret_cast(cmd.data.draw.drawIndexed.firstIndex)); + } + else + { + mGl.DrawElementsInstanced(GetTopology(currentPipeline->inputAssemblyState.topology), + static_cast(cmd.data.draw.drawIndexed.indexCount), + GL_UNSIGNED_SHORT, + reinterpret_cast(cmd.data.draw.drawIndexed.firstIndex), + cmd.data.draw.drawIndexed.instanceCount); + } + } break; } case CommandType::DRAW_INDEXED_INDIRECT: { - mGl.DrawElements(GetTopology(currentPipeline->inputAssemblyState.topology), - static_cast(cmd.data.draw.drawIndexed.indexCount), - GL_UNSIGNED_SHORT, - reinterpret_cast(cmd.data.draw.drawIndexed.firstIndex)); + if(currentPipeline) + { + mGl.DrawElements(GetTopology(currentPipeline->inputAssemblyState.topology), + static_cast(cmd.data.draw.drawIndexed.indexCount), + GL_UNSIGNED_SHORT, + reinterpret_cast(cmd.data.draw.drawIndexed.firstIndex)); + } break; } case CommandType::SET_SCISSOR: @@ -837,6 +975,7 @@ void TestGraphicsController::ProcessCommandBuffer(TestGraphicsCommandBuffer& com const auto& area = cmd.data.beginRenderPass.renderArea; if(area.x == 0 && area.y == 0 && + renderTarget && area.width == renderTarget->mCreateInfo.extent.width && area.height == renderTarget->mCreateInfo.extent.height) { @@ -861,6 +1000,11 @@ void TestGraphicsController::ProcessCommandBuffer(TestGraphicsCommandBuffer& com } case CommandType::END_RENDER_PASS: { + if(cmd.data.endRenderPass.syncObject != nullptr) + { + auto syncObject = Uncast(cmd.data.endRenderPass.syncObject); + syncObject->InitializeResource(); // create the sync object. + } break; } } @@ -876,12 +1020,22 @@ void TestGraphicsController::BindPipeline(TestGraphicsPipeline* pipeline) uint32_t attributeOffset = attribute.offset; GLsizei stride = vi.bufferBindings[attribute.binding].stride; + auto rate = vi.bufferBindings[attribute.binding].inputRate; + mGl.VertexAttribPointer(attribute.location, GetNumComponents(attribute.format), GetGlType(attribute.format), GL_FALSE, // Not normalized stride, reinterpret_cast(attributeOffset)); + if(rate == Graphics::VertexInputRate::PER_VERTEX) + { + mGl.VertexAttribDivisor(attribute.location, 0); + } + else if(rate == Graphics::VertexInputRate::PER_INSTANCE) + { + mGl.VertexAttribDivisor(attribute.location, 1); + } } // Cull face setup @@ -936,9 +1090,11 @@ void TestGraphicsController::BindPipeline(TestGraphicsPipeline* pipeline) */ void TestGraphicsController::PresentRenderTarget(Graphics::RenderTarget* renderTarget) { + auto* rt = static_cast(renderTarget); TraceCallStack::NamedParams namedParams; namedParams["renderTarget"] << std::hex << renderTarget; - mCallStack.PushCall("PresentRenderTarget", "", namedParams); + namedParams["surface"] << std::hex << rt->mCreateInfo.surface; + mCallStack.PushCall("PresentRenderTarget", namedParams.str(), namedParams); } /** @@ -996,6 +1152,15 @@ void TestGraphicsController::UpdateTextures(const std::vector(&texture); + mGl.BindTexture(gfxTexture->GetTarget(), 0); + mGl.GenerateMipmap(gfxTexture->GetTarget()); +} + bool TestGraphicsController::EnableDepthStencilBuffer(bool enableDepth, bool enableStencil) { TraceCallStack::NamedParams namedParams; @@ -1036,10 +1201,25 @@ bool TestGraphicsController::IsDrawOnResumeRequired() Graphics::UniquePtr TestGraphicsController::CreateBuffer(const Graphics::BufferCreateInfo& createInfo, Graphics::UniquePtr&& oldBuffer) { - std::ostringstream oss; - oss << "bufferCreateInfo:" << createInfo; - mCallStack.PushCall("CreateBuffer", oss.str()); - return Graphics::MakeUnique(mCallStack, mGl, createInfo.size, createInfo.usage); + TraceCallStack::NamedParams namedParams; + namedParams["usage"] << "0x" << std::hex << createInfo.usage; + namedParams["propertiesFlags"] << createInfo.propertiesFlags; + namedParams["size"] << createInfo.size; + mCallStack.PushCall("CreateBuffer", namedParams.str(), namedParams); + + auto ptr = Graphics::MakeUnique>(createInfo, *this, mGl, mCallStack); + mAllocatedBuffers.push_back(ptr.get()); + return ptr; +} + +void TestGraphicsController::DiscardBuffer(TestGraphicsBuffer* buffer) +{ + auto iter = std::find(mAllocatedBuffers.begin(), mAllocatedBuffers.end(), buffer); + if(iter != mAllocatedBuffers.end()) + { + mAllocatedBuffers.erase(iter); + } + delete buffer; } Graphics::UniquePtr TestGraphicsController::CreateCommandBuffer(const Graphics::CommandBufferCreateInfo& commandBufferCreateInfo, Graphics::UniquePtr&& oldCommandBuffer) @@ -1096,7 +1276,7 @@ Graphics::UniquePtr TestGraphicsController::CreateProgram(con source.resize(graphicsShader->mCreateInfo.sourceSize); memcpy(&source[0], graphicsShader->mCreateInfo.sourceData, graphicsShader->mCreateInfo.sourceSize); - if(!std::equal(source.begin(), source.end(), cacheEntry.shaders[shader.pipelineStage].begin())) + if(!std::equal(source.begin(), source.end(), cacheEntry.shaders[shader.pipelineStage].begin(), cacheEntry.shaders[shader.pipelineStage].end())) { found = false; break; @@ -1109,7 +1289,8 @@ Graphics::UniquePtr TestGraphicsController::CreateProgram(con } mProgramCache.emplace_back(); - mProgramCache.back().programImpl = new TestGraphicsProgramImpl(mGl, programCreateInfo, mVertexFormats, mCustomUniforms); + mProgramCache.back().programImpl = new TestGraphicsProgramImpl(*this, mGl, programCreateInfo, mVertexFormats, mCustomUniforms, mCustomUniformBlocks); + for(auto& shader : *(programCreateInfo.shaderState)) { auto graphicsShader = Uncast(shader.shader); @@ -1136,10 +1317,21 @@ Graphics::UniquePtr TestGraphicsController::CreateSampler(con Graphics::UniquePtr TestGraphicsController::CreateRenderTarget(const Graphics::RenderTargetCreateInfo& renderTargetCreateInfo, Graphics::UniquePtr&& oldRenderTarget) { - mCallStack.PushCall("CreateRenderTarget", ""); + TraceCallStack::NamedParams namedParams; + namedParams["surface"] << std::hex << renderTargetCreateInfo.surface; + mCallStack.PushCall("CreateRenderTarget", namedParams.str(), namedParams); + return Graphics::MakeUnique(mGl, renderTargetCreateInfo); } +Graphics::UniquePtr TestGraphicsController::CreateSyncObject( + const Graphics::SyncObjectCreateInfo& syncObjectCreateInfo, + Graphics::UniquePtr&& oldSyncObject) +{ + mCallStack.PushCall("CreateSyncObject", ""); + return Graphics::MakeUnique(mGraphicsSyncImpl, syncObjectCreateInfo); +} + Graphics::UniquePtr TestGraphicsController::MapBufferRange(const Graphics::MapBufferInfo& mapInfo) { mCallStack.PushCall("MapBufferRange", ""); @@ -1169,11 +1361,27 @@ Graphics::MemoryRequirements TestGraphicsController::GetTextureMemoryRequirement Graphics::MemoryRequirements TestGraphicsController::GetBufferMemoryRequirements(Graphics::Buffer& buffer) const { + static GLint uniformAlign{0}; + + Graphics::MemoryRequirements reqs{}; mCallStack.PushCall("GetBufferMemoryRequirements", ""); - return Graphics::MemoryRequirements{}; + + auto gfxBuffer = Uncast(&buffer); + if(gfxBuffer->mCreateInfo.usage & (0 | Graphics::BufferUsage::UNIFORM_BUFFER)) + { + if(!uniformAlign) + { + // Throw off the shackles of constness + auto& gl = *const_cast(&mGl); + gl.GetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &uniformAlign); + } + reqs.size = gfxBuffer->mCreateInfo.size; + reqs.alignment = uint32_t(uniformAlign); + } + return reqs; } -const Graphics::TextureProperties& TestGraphicsController::GetTextureProperties(const Graphics::Texture& texture) +Graphics::TextureProperties TestGraphicsController::GetTextureProperties(const Graphics::Texture& texture) { static Graphics::TextureProperties textureProperties{}; mCallStack.PushCall("GetTextureProperties", ""); @@ -1201,4 +1409,71 @@ bool TestGraphicsController::GetProgramParameter(Graphics::Program& program, uin return graphicsProgram->GetParameter(parameterId, outData); } +Graphics::Texture* TestGraphicsController::CreateTextureByResourceId(uint32_t resourceId, const Graphics::TextureCreateInfo& createInfo) +{ + Graphics::Texture* ret = nullptr; + Graphics::UniquePtr texture; + TraceCallStack::NamedParams namedParams; + namedParams["resourceId"] << resourceId; + + auto iter = mTextureUploadBindMapper.find(resourceId); + DALI_ASSERT_ALWAYS(iter == mTextureUploadBindMapper.end()); + + // Create new graphics texture. + texture = CreateTexture(createInfo, std::move(texture)); + ret = texture.get(); + + mTextureUploadBindMapper.insert(std::make_pair(resourceId, std::move(texture))); + + mCallStack.PushCall("CreateTextureByResourceId", "", namedParams); + return ret; +} + +void TestGraphicsController::DiscardTextureFromResourceId(uint32_t resourceId) +{ + TraceCallStack::NamedParams namedParams; + namedParams["resourceId"] << resourceId; + + mTextureUploadBindMapper.erase(resourceId); + + mCallStack.PushCall("DiscardTextureFromResourceId", "", namedParams); +} + +Graphics::Texture* TestGraphicsController::GetTextureFromResourceId(uint32_t resourceId) +{ + TraceCallStack::NamedParams namedParams; + namedParams["resourceId"] << resourceId; + + Graphics::Texture* ret = nullptr; + + auto iter = mTextureUploadBindMapper.find(resourceId); + if(iter != mTextureUploadBindMapper.end()) + { + ret = iter->second.get(); + } + + mCallStack.PushCall("GetTextureFromResourceId", "", namedParams); + + return ret; +} + +Graphics::UniquePtr TestGraphicsController::ReleaseTextureFromResourceId(uint32_t resourceId) +{ + TraceCallStack::NamedParams namedParams; + namedParams["resourceId"] << resourceId; + + Graphics::UniquePtr texture; + + auto iter = mTextureUploadBindMapper.find(resourceId); + if(iter != mTextureUploadBindMapper.end()) + { + texture = std::move(iter->second); + mTextureUploadBindMapper.erase(iter); + } + + mCallStack.PushCall("ReleaseTextureFromResourceId", "", namedParams); + + return texture; +} + } // namespace Dali