From: David Steele Date: Mon, 15 Mar 2021 17:51:44 +0000 (+0000) Subject: Added Scissor/Viewport handling to CommandBuffer X-Git-Tag: graphics-backend-release-1^2~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F11%2F255311%2F1;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git Added Scissor/Viewport handling to CommandBuffer Change-Id: I48e03b90422902982e62cee3b06768368e606306 --- diff --git a/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-buffer.cpp b/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-buffer.cpp index 2a75a2d..d8a1b1a 100644 --- a/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-buffer.cpp +++ b/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-buffer.cpp @@ -27,7 +27,7 @@ TestGraphicsBuffer::TestGraphicsBuffer(TraceCallStack& callStack, TestGlAbstract mGl(glAbstraction), mUsage(usage) { - memory.reserve(size); + memory.resize(size); mGl.GetBufferTrace().EnableLogging(true); } @@ -139,6 +139,7 @@ void TestGraphicsBuffer::BindAsUniformBuffer(const TestGraphicsProgram* program) } default: { + fprintf(stderr, "\n%s type not found\n", member.name.c_str()); } } } diff --git a/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-command-buffer.h b/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-command-buffer.h index 2ab178a..b07166c 100644 --- a/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-command-buffer.h +++ b/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-command-buffer.h @@ -46,7 +46,11 @@ enum class CommandType BIND_PIPELINE = 1 << 6, DRAW = 1 << 7, DRAW_INDEXED = 1 << 8, - DRAW_INDEXED_INDIRECT = 1 << 9 + DRAW_INDEXED_INDIRECT = 1 << 9, + SET_SCISSOR = 1 << 10, + SET_SCISSOR_TEST = 1 << 11, + SET_VIEWPORT = 1 << 12, + SET_VIEWPORT_TEST = 1 << 13 }; using CommandTypeMask = uint32_t; @@ -221,12 +225,32 @@ struct Command // Nothing to do break; } + case CommandType::SET_SCISSOR: + { + scissor.region = rhs.scissor.region; + break; + } + case CommandType::SET_SCISSOR_TEST: + { + scissorTest.enable = rhs.scissorTest.enable; + break; + } + case CommandType::SET_VIEWPORT: + { + viewport.region = rhs.viewport.region; + break; + } + case CommandType::SET_VIEWPORT_TEST: + { + viewportTest.enable = rhs.viewportTest.enable; + break; + } } type = rhs.type; } /** - * @brief Copy constructor + * @brief move constructor * @param[in] rhs Command */ Command(Command&& rhs) noexcept @@ -286,6 +310,26 @@ struct Command // Nothing to do break; } + case CommandType::SET_SCISSOR: + { + scissor.region = rhs.scissor.region; + break; + } + case CommandType::SET_SCISSOR_TEST: + { + scissorTest.enable = rhs.scissorTest.enable; + break; + } + case CommandType::SET_VIEWPORT: + { + viewport.region = rhs.viewport.region; + break; + } + case CommandType::SET_VIEWPORT_TEST: + { + viewportTest.enable = rhs.viewportTest.enable; + break; + } } type = rhs.type; } @@ -329,6 +373,23 @@ struct Command struct : public DrawCallDescriptor { } draw; + + struct + { + Graphics::Rect2D region; + } scissor; + struct + { + bool enable; + } scissorTest; + struct + { + Graphics::Viewport region; + } viewport; + struct + { + bool enable; + } viewportTest; }; }; @@ -521,24 +582,56 @@ public: mCallStack.PushCall("Reset", ""); } - void SetScissor(Graphics::Extent2D value) override + void SetScissor(Graphics::Rect2D value) override { - mCallStack.PushCall("SetScissor", ""); + TraceCallStack::NamedParams params; + params["x"] << value.x; + params["y"] << value.y; + params["width"] << value.width; + params["height"] << value.height; + mCallStack.PushCall("SetScissor", params.str(), params); + + mCommands.emplace_back(); + mCommands.back().type = CommandType::SET_SCISSOR; + mCommands.back().scissor.region = value; } void SetScissorTestEnable(bool value) override { - mCallStack.PushCall("SetScissorTestEnable", ""); + TraceCallStack::NamedParams params; + params["value"] << (value ? "T" : "F"); + mCallStack.PushCall("SetScissorTestEnable", params.str(), params); + + mCommands.emplace_back(); + mCommands.back().type = CommandType::SET_SCISSOR_TEST; + mCommands.back().scissorTest.enable = value; } void SetViewport(Graphics::Viewport value) override { - mCallStack.PushCall("SetViewport", ""); + TraceCallStack::NamedParams params; + params["x"] << value.x; + params["y"] << value.y; + params["width"] << value.width; + params["height"] << value.height; + params["minDepth"] << value.minDepth; + params["maxDepth"] << value.maxDepth; + mCallStack.PushCall("SetViewport", params.str(), params); + + mCommands.emplace_back(); + mCommands.back().type = CommandType::SET_VIEWPORT; + mCommands.back().viewport.region = value; } void SetViewportEnable(bool value) override { - mCallStack.PushCall("SetViewportEnable", ""); + TraceCallStack::NamedParams params; + params["value"] << (value ? "T" : "F"); + mCallStack.PushCall("SetViewportEnable", params.str(), params); + + mCommands.emplace_back(); + mCommands.back().type = CommandType::SET_VIEWPORT_TEST; + mCommands.back().viewportTest.enable = value; } [[nodiscard]] const std::vector& GetCommands() const @@ -564,8 +657,9 @@ public: std::vector GetCommandsByType(CommandTypeMask mask); private: - TraceCallStack& mCallStack; - TestGlAbstraction& mGlAbstraction; + TraceCallStack& mCallStack; + TestGlAbstraction& mGlAbstraction; + std::vector mCommands; }; diff --git a/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-controller.cpp b/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-controller.cpp index ac7d33a..f5f065e 100644 --- a/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-controller.cpp +++ b/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-controller.cpp @@ -508,6 +508,38 @@ void TestGraphicsController::SubmitCommandBuffers(const Graphics::SubmitInfo& su vertexBuffer->Bind(); } } + + bool scissorEnabled = false; + + auto scissorTestList = commandBuffer->GetCommandsByType(0 | CommandType::SET_SCISSOR_TEST); + if(!scissorTestList.empty()) + { + if(scissorTestList[0]->scissorTest.enable) + { + mGl.Enable(GL_SCISSOR_TEST); + scissorEnabled = true; + } + else + { + mGl.Disable(GL_SCISSOR_TEST); + } + } + + auto scissorList = commandBuffer->GetCommandsByType(0 | CommandType::SET_SCISSOR); + if(!scissorList.empty() && scissorEnabled) + { + auto& rect = scissorList[0]->scissor.region; + mGl.Scissor(rect.x, rect.y, rect.width, rect.height); + } + + auto viewportList = commandBuffer->GetCommandsByType(0 | CommandType::SET_VIEWPORT); + if(!viewportList.empty()) + { + mGl.Viewport(viewportList[0]->viewport.region.x, viewportList[0]->viewport.region.y, viewportList[0]->viewport.region.width, viewportList[0]->viewport.region.height); + } + + // ignore viewport enable + // Pipeline attribute setup auto bindPipelineCmds = commandBuffer->GetCommandsByType(0 | CommandType::BIND_PIPELINE); if(!bindPipelineCmds.empty()) @@ -527,6 +559,7 @@ void TestGraphicsController::SubmitCommandBuffers(const Graphics::SubmitInfo& su stride, reinterpret_cast(attributeOffset)); } + // Cull face setup auto& rasterizationState = pipeline->rasterizationState; if(rasterizationState.cullMode == Graphics::CullMode::NONE) @@ -758,8 +791,12 @@ Graphics::UniquePtr TestGraphicsController::CreateProgram(con bool found = true; for(auto& shader : *(programCreateInfo.shaderState)) { - auto graphicsShader = Uncast(shader.shader); - if(memcmp(cacheEntry.shaders[shader.pipelineStage], graphicsShader->mCreateInfo.sourceData, graphicsShader->mCreateInfo.sourceSize)) + auto graphicsShader = Uncast(shader.shader); + std::vector source; + 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())) { found = false; break; @@ -775,8 +812,9 @@ Graphics::UniquePtr TestGraphicsController::CreateProgram(con mProgramCache.back().programImpl = new TestGraphicsProgramImpl(mGl, programCreateInfo, mVertexFormats, mCustomUniforms); for(auto& shader : *(programCreateInfo.shaderState)) { - auto graphicsShader = Uncast(shader.shader); - mProgramCache.back().shaders[shader.pipelineStage] = graphicsShader->mCreateInfo.sourceData; + auto graphicsShader = Uncast(shader.shader); + mProgramCache.back().shaders[shader.pipelineStage].resize(graphicsShader->mCreateInfo.sourceSize); + memcpy(&mProgramCache.back().shaders[shader.pipelineStage][0], graphicsShader->mCreateInfo.sourceData, graphicsShader->mCreateInfo.sourceSize); } return Graphics::MakeUnique(mProgramCache.back().programImpl); } diff --git a/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-controller.h b/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-controller.h index cbe78ec..d70ed3b 100644 --- a/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-controller.h +++ b/automated-tests/src/dali-adaptor/dali-test-suite-utils/test-graphics-controller.h @@ -337,8 +337,8 @@ public: struct ProgramCache { - std::map shaders; - TestGraphicsProgramImpl* programImpl; + std::map> shaders; + TestGraphicsProgramImpl* programImpl; }; std::vector mProgramCache; diff --git a/dali/internal/graphics/gles-impl/egl-graphics-controller.cpp b/dali/internal/graphics/gles-impl/egl-graphics-controller.cpp index d17fd38..dc1e280 100644 --- a/dali/internal/graphics/gles-impl/egl-graphics-controller.cpp +++ b/dali/internal/graphics/gles-impl/egl-graphics-controller.cpp @@ -295,6 +295,28 @@ void EglGraphicsController::ProcessCommandQueues() mContext->Flush(false, cmd.draw); break; } + case GLES::CommandType::SET_SCISSOR: // @todo Consider correcting for orientation here? + { + mGlAbstraction->Scissor(cmd.scissor.region.x, cmd.scissor.region.y, cmd.scissor.region.width, cmd.scissor.region.height); + break; + } + case GLES::CommandType::SET_SCISSOR_TEST: + { + if(cmd.scissorTest.enable) + { + mGlAbstraction->Enable(GL_SCISSOR_TEST); + } + else + { + mGlAbstraction->Disable(GL_SCISSOR_TEST); + } + break; + } + case GLES::CommandType::SET_VIEWPORT: // @todo Consider correcting for orientation here? + { + mGlAbstraction->Viewport(cmd.viewport.region.x, cmd.viewport.region.y, cmd.viewport.region.width, cmd.viewport.region.height); + break; + } } } } diff --git a/dali/internal/graphics/gles-impl/egl-graphics-controller.h b/dali/internal/graphics/gles-impl/egl-graphics-controller.h index 6e90c03..2ae3296 100644 --- a/dali/internal/graphics/gles-impl/egl-graphics-controller.h +++ b/dali/internal/graphics/gles-impl/egl-graphics-controller.h @@ -361,7 +361,10 @@ public: ProcessDiscardQueues(); // Flush pipeline cache to remove unused pipelines - GetPipelineCache().FlushCache(); + if(mPipelineCache) + { + mPipelineCache->FlushCache(); + } } // Test update to tick controller, usually it will run own thread diff --git a/dali/internal/graphics/gles-impl/gles-graphics-command-buffer.h b/dali/internal/graphics/gles-impl/gles-graphics-command-buffer.h index e9ec39f..e976883 100644 --- a/dali/internal/graphics/gles-impl/gles-graphics-command-buffer.h +++ b/dali/internal/graphics/gles-impl/gles-graphics-command-buffer.h @@ -43,7 +43,10 @@ enum class CommandType BIND_PIPELINE, DRAW, DRAW_INDEXED, - DRAW_INDEXED_INDIRECT + DRAW_INDEXED_INDIRECT, + SET_SCISSOR, + SET_SCISSOR_TEST, + SET_VIEWPORT }; /** @@ -120,6 +123,21 @@ struct Command // Nothing to do break; } + case CommandType::SET_SCISSOR: + { + scissor.region = rhs.scissor.region; + break; + } + case CommandType::SET_SCISSOR_TEST: + { + scissorTest.enable = rhs.scissorTest.enable; + break; + } + case CommandType::SET_VIEWPORT: + { + viewport.region = rhs.viewport.region; + break; + } } type = rhs.type; } @@ -185,6 +203,21 @@ struct Command // Nothing to do break; } + case CommandType::SET_SCISSOR: + { + scissor.region = rhs.scissor.region; + break; + } + case CommandType::SET_SCISSOR_TEST: + { + scissorTest.enable = rhs.scissorTest.enable; + break; + } + case CommandType::SET_VIEWPORT: + { + viewport.region = rhs.viewport.region; + break; + } } type = rhs.type; } @@ -228,6 +261,21 @@ struct Command struct : public DrawCallDescriptor { } draw; + + struct + { + Graphics::Rect2D region; + } scissor; + + struct + { + bool enable; + } scissorTest; + + struct + { + Graphics::Viewport region; + } viewport; }; }; @@ -411,20 +459,30 @@ public: mCommands.clear(); } - void SetScissor(Extent2D value) override + void SetScissor(Graphics::Rect2D value) override { + mCommands.emplace_back(); + mCommands.back().type = CommandType::SET_SCISSOR; + mCommands.back().scissor.region = value; } void SetScissorTestEnable(bool value) override { + mCommands.emplace_back(); + mCommands.back().type = CommandType::SET_SCISSOR_TEST; + mCommands.back().scissorTest.enable = value; } void SetViewport(Viewport value) override { + mCommands.emplace_back(); + mCommands.back().type = CommandType::SET_VIEWPORT; + mCommands.back().viewport.region = value; } void SetViewportEnable(bool value) override { + // There is no GL equivalent } [[nodiscard]] const std::vector& GetCommands() const