From: Eunki, Hong Date: Thu, 11 Jul 2024 02:25:21 +0000 (+0900) Subject: Add internal UTC to use ShaderFactory.SaveShader X-Git-Tag: dali_2.3.34~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fea86ba4cdc7f90a2e94b5b6a00e3002fc87c6c1;p=platform%2Fcore%2Fuifw%2Fdali-core.git Add internal UTC to use ShaderFactory.SaveShader Since there was no UTC relative with it, platform abstraction code become broken. To make code clean, let we implement something internal UTC about shader cache. Change-Id: I83f10b5a7231af9f6a68c33336c92bc1f7ea1a68 Signed-off-by: Eunki, Hong --- diff --git a/automated-tests/src/dali-internal/utc-Dali-Internal-Shader.cpp b/automated-tests/src/dali-internal/utc-Dali-Internal-Shader.cpp index ec9cfa9..e89c289 100644 --- a/automated-tests/src/dali-internal/utc-Dali-Internal-Shader.cpp +++ b/automated-tests/src/dali-internal/utc-Dali-Internal-Shader.cpp @@ -95,4 +95,110 @@ int UtcDaliShaderWithPrefixTestVersion(void) DALI_TEST_EQUALS(shaderData->GetFragmentShaderVersion(), 101, TEST_LOCATION); END_TEST; -} \ No newline at end of file +} + +int UtcDaliInternalShaderSaveAndLoad(void) +{ + TestApplication application; + + std::string vertexShader1 = "some vertex code\n"; + std::string fragmentShader1 = "some fragment code\n"; + + std::string vertexShader2 = "some another vertex code\n"; + std::string fragmentShader2 = "some another fragment code\n"; + + Dali::Vector dummyBuffer(5); + for(size_t i = 0; i < 5; ++i) + { + dummyBuffer[i] = static_cast(i + 21); + } + + // Make save and load failed successful + auto& platformAbstraction = application.GetPlatform(); + platformAbstraction.SetLoadFileResult(false, dummyBuffer); + + // Test version number in the shader data + Dali::Internal::ThreadLocalStorage& tls = Dali::Internal::ThreadLocalStorage::Get(); + Dali::Internal::ShaderFactory& shaderFactory = tls.GetShaderFactory(); + + tet_printf("Load shader1. It should be fail to load from platform abstraction\n"); + size_t shaderHash1 = 0u; + Internal::ShaderDataPtr shaderData1 = shaderFactory.Load(vertexShader1, fragmentShader1, Shader::Hint::NONE, 0u, "", shaderHash1); + DALI_TEST_CHECK(shaderHash1 != 0u); + DALI_TEST_EQUALS(shaderData1.Get()->HasBinary(), false, TEST_LOCATION); + + DALI_TEST_EQUALS(platformAbstraction.WasCalled(TestPlatformAbstraction::SaveShaderBinaryFileFunc), false, TEST_LOCATION); + DALI_TEST_EQUALS(platformAbstraction.WasCalled(TestPlatformAbstraction::LoadShaderBinaryFileFunc), true, TEST_LOCATION); + + // Reset trace callstack + platformAbstraction.GetTrace().Reset(); + + // Copy the memory of dummy + shaderData1.Get()->AllocateBuffer(7); + for(size_t i = 0; i < 7; ++i) + { + shaderData1.Get()->GetBuffer()[i] = static_cast(i + 1); + } + + DALI_TEST_EQUALS(shaderData1.Get()->HasBinary(), true, TEST_LOCATION); + + tet_printf("Save shaderData1 as binary, but failed.\n"); + shaderFactory.SaveBinary(shaderData1); + + tet_printf("Check shader saved\n"); + DALI_TEST_EQUALS(platformAbstraction.WasCalled(TestPlatformAbstraction::SaveShaderBinaryFileFunc), true, TEST_LOCATION); + DALI_TEST_EQUALS(platformAbstraction.WasCalled(TestPlatformAbstraction::LoadShaderBinaryFileFunc), false, TEST_LOCATION); + + // Reset trace callstack + platformAbstraction.GetTrace().Reset(); + + tet_printf("Save shaderData1 as binary, and success now.\n"); + platformAbstraction.SetSaveFileResult(true); + shaderFactory.SaveBinary(shaderData1); + + tet_printf("Check shader saved\n"); + DALI_TEST_EQUALS(platformAbstraction.WasCalled(TestPlatformAbstraction::SaveShaderBinaryFileFunc), true, TEST_LOCATION); + DALI_TEST_EQUALS(platformAbstraction.WasCalled(TestPlatformAbstraction::LoadShaderBinaryFileFunc), false, TEST_LOCATION); + + // Reset trace callstack + platformAbstraction.GetTrace().Reset(); + + tet_printf("Load shaderData2 with same code as shaderData1\n"); + size_t shaderHash2 = 0u; + Internal::ShaderDataPtr shaderData2 = shaderFactory.Load(vertexShader1, fragmentShader1, Shader::Hint::NONE, 0u, "", shaderHash2); + + tet_printf("Check shaderData2 cached\n"); + DALI_TEST_EQUALS(shaderHash2, shaderHash1, TEST_LOCATION); + DALI_TEST_EQUALS(shaderData2.Get()->HasBinary(), true, TEST_LOCATION); + + DALI_TEST_EQUALS(shaderData2->GetBufferSize(), shaderData1->GetBufferSize(), TEST_LOCATION); + for(size_t i = 0; i < shaderData1->GetBufferSize(); ++i) + { + DALI_TEST_EQUALS(shaderData2->GetBuffer()[i], shaderData1->GetBuffer()[i], TEST_LOCATION); + } + + DALI_TEST_EQUALS(platformAbstraction.WasCalled(TestPlatformAbstraction::SaveShaderBinaryFileFunc), false, TEST_LOCATION); + DALI_TEST_EQUALS(platformAbstraction.WasCalled(TestPlatformAbstraction::LoadShaderBinaryFileFunc), false, TEST_LOCATION); + + // Reset trace callstack + platformAbstraction.GetTrace().Reset(); + + tet_printf("Make shaderData3 load dummyBuffer from filesystem\n"); + platformAbstraction.SetLoadFileResult(true, dummyBuffer); + + tet_printf("Load shader3. It will get binary same as dummyBuffer\n"); + size_t shaderHash3 = 0u; + Internal::ShaderDataPtr shaderData3 = shaderFactory.Load(vertexShader2, fragmentShader2, Shader::Hint::NONE, 0u, "", shaderHash3); + DALI_TEST_CHECK(shaderHash3 != 0u); + DALI_TEST_EQUALS(shaderData3.Get()->HasBinary(), true, TEST_LOCATION); + DALI_TEST_EQUALS(shaderData3->GetBufferSize(), dummyBuffer.Count(), TEST_LOCATION); + for(size_t i = 0; i < dummyBuffer.Count(); ++i) + { + DALI_TEST_EQUALS(shaderData3->GetBuffer()[i], dummyBuffer[i], TEST_LOCATION); + } + + DALI_TEST_EQUALS(platformAbstraction.WasCalled(TestPlatformAbstraction::SaveShaderBinaryFileFunc), false, TEST_LOCATION); + DALI_TEST_EQUALS(platformAbstraction.WasCalled(TestPlatformAbstraction::LoadShaderBinaryFileFunc), true, TEST_LOCATION); + + END_TEST; +} diff --git a/automated-tests/src/dali/dali-test-suite-utils/test-platform-abstraction.cpp b/automated-tests/src/dali/dali-test-suite-utils/test-platform-abstraction.cpp index 290f663..fa5ac89 100644 --- a/automated-tests/src/dali/dali-test-suite-utils/test-platform-abstraction.cpp +++ b/automated-tests/src/dali/dali-test-suite-utils/test-platform-abstraction.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2024 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. @@ -84,6 +84,13 @@ bool TestPlatformAbstraction::LoadShaderBinaryFile(const std::string& filename, return mLoadFileResult.loadResult; } +bool TestPlatformAbstraction::SaveShaderBinaryFile(const std::string& filename, const unsigned char* buffer, unsigned int numBytes) const +{ + mTrace.PushCall("SaveShaderBinaryFile", ""); + + return mSaveFileResult; +} + /** Call this every test */ void TestPlatformAbstraction::Initialize() { diff --git a/automated-tests/src/dali/dali-test-suite-utils/test-platform-abstraction.h b/automated-tests/src/dali/dali-test-suite-utils/test-platform-abstraction.h index 3146e2d..707e2fe 100644 --- a/automated-tests/src/dali/dali-test-suite-utils/test-platform-abstraction.h +++ b/automated-tests/src/dali/dali-test-suite-utils/test-platform-abstraction.h @@ -2,7 +2,7 @@ #define DALI_TEST_PLATFORM_ABSTRACTION_H /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2024 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. @@ -85,10 +85,7 @@ public: /** * @copydoc PlatformAbstraction::SaveShaderBinaryFile() */ - virtual bool SaveShaderBinaryFile(const std::string& filename, const unsigned char* buffer, unsigned int numBytes) const override - { - return true; - } + bool SaveShaderBinaryFile(const std::string& filename, const unsigned char* buffer, unsigned int numBytes) const override; /** * @copydoc PlatformAbstraction::StartTimer()