From: Adam Bialogonski Date: Mon, 20 May 2024 09:51:44 +0000 (+0100) Subject: Shader processing fix X-Git-Tag: dali_2.3.25~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F94%2F311394%2F5;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git Shader processing fix Making sure that #version is a very first statement in GLSL shader Change-Id: I74992af10166127a285e0d2a0cc3e7ec41854237 --- diff --git a/automated-tests/src/dali-graphics/utc-Dali-GraphicsShader.cpp b/automated-tests/src/dali-graphics/utc-Dali-GraphicsShader.cpp index e2ec99e..6b9bad3 100644 --- a/automated-tests/src/dali-graphics/utc-Dali-GraphicsShader.cpp +++ b/automated-tests/src/dali-graphics/utc-Dali-GraphicsShader.cpp @@ -118,4 +118,42 @@ int UtcDaliGlesStripLegacyCodeIfNeededTest2(void) } END_TEST; +} + +int UtcDaliGlesLegacyCodeTest(void) +{ + TestGraphicsApplication application; + + std::string vertexShader = + "#version 320 es\n" + "some code\n"; + + std::string somePrefix = + "This is some prefix\n"; + + auto newVertexPrefix = Dali::Integration::Test::GenerateTaggedShaderPrefix(somePrefix); + { + Dali::Graphics::ShaderCreateInfo info; + info.SetPipelineStage(Dali::Graphics::PipelineStage::VERTEX_SHADER); + + std::string prefixedVertexShader = newVertexPrefix + vertexShader; + + info.SetShaderVersion(0); + info.SetSourceData(prefixedVertexShader.data()); + info.SetSourceSize(prefixedVertexShader.size()); + info.SetSourceMode(Dali::Graphics::ShaderSourceMode::TEXT); + + size_t dataSize = 0; + size_t dataIndex = 0; + Graphics::GLES::ShaderImpl::StripLegacyCodeIfNeeded(info, dataIndex, dataSize); + + auto index = prefixedVertexShader.find("#version"); + + DALI_TEST_EQUALS(dataIndex, index, TEST_LOCATION); + + // should match original shader size + DALI_TEST_EQUALS(dataSize, vertexShader.size(), TEST_LOCATION); + } + + END_TEST; } \ No newline at end of file diff --git a/dali/internal/graphics/gles-impl/gles-graphics-shader.cpp b/dali/internal/graphics/gles-impl/gles-graphics-shader.cpp index 897a50d..36ffd27 100644 --- a/dali/internal/graphics/gles-impl/gles-graphics-shader.cpp +++ b/dali/internal/graphics/gles-impl/gles-graphics-shader.cpp @@ -43,7 +43,7 @@ struct ShaderImpl::Impl source.resize(dataSize); std::copy(reinterpret_cast(_createInfo.sourceData) + dataStartIndex, - reinterpret_cast(_createInfo.sourceData) + dataSize, + reinterpret_cast(_createInfo.sourceData) + dataStartIndex + dataSize, source.data()); // Substitute pointer @@ -220,10 +220,10 @@ void ShaderImpl::StripLegacyCodeIfNeeded(const ShaderCreateInfo& info, size_t& s { // Make a copy of source code. if code is meant to be used // by modern parser, skip the prefix part + auto text = reinterpret_cast(info.sourceData); + auto result = std::string_view(text).find("//@legacy-prefix-end"); if(info.shaderVersion != 0) { - auto text = reinterpret_cast(info.sourceData); - auto result = std::string_view(text).find("//@legacy-prefix-end"); if(result != 0 && result != std::string::npos) { DALI_LOG_ERROR("Shader processing: @legacy-prefix-end must be a very first statement!\n"); @@ -234,7 +234,24 @@ void ShaderImpl::StripLegacyCodeIfNeeded(const ShaderCreateInfo& info, size_t& s startIndex = std::strtoul(reinterpret_cast(info.sourceData) + 21, &end, 10); } } - + else + { + // For legacy shaders we need to make sure that the #version is a very first line + // so need to strip //@legacy-prefix-end tag + if(result != std::string::npos) + { + auto versionPos = std::string_view(text).find("#version", result); + if(versionPos == std::string::npos) + { + DALI_LOG_ERROR("Shader processing: new-line missing after @legacy-prefix-end!\n"); + startIndex = 0; // not trimming anything + } + else + { + startIndex = versionPos; + } + } + } finalDataSize = info.sourceSize - startIndex; }