2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "gles-texture-dependency-checker.h"
21 #include <dali/internal/graphics/gles-impl/egl-graphics-controller.h>
23 namespace Dali::Graphics::GLES
25 void TextureDependencyChecker::Reset()
27 for(auto& textureDependency : mTextureDependencies)
29 for(auto texture : textureDependency.textures)
31 texture->SetDependencyIndex(0xffffffff);
33 if(!textureDependency.syncing)
35 mController.GetSyncPool().FreeSyncObject(textureDependency.agingSyncObject);
38 mTextureDependencies.clear();
41 void TextureDependencyChecker::AddTextures(const GLES::Context* writeContext, const GLES::Framebuffer* framebuffer)
43 uint32_t index = mTextureDependencies.size();
44 mTextureDependencies.emplace_back();
45 TextureDependency& textureDependency = mTextureDependencies.back();
47 for(int i = 0; i < 3; ++i)
49 GLES::Texture* texture{nullptr};
53 texture = static_cast<GLES::Texture*>(framebuffer->GetCreateInfo().colorAttachments[0].texture);
56 texture = static_cast<GLES::Texture*>(framebuffer->GetCreateInfo().depthStencilAttachment.depthTexture);
59 texture = static_cast<GLES::Texture*>(framebuffer->GetCreateInfo().depthStencilAttachment.stencilTexture);
62 if(texture != nullptr)
64 textureDependency.textures.push_back(texture);
65 texture->SetDependencyIndex(index);
68 textureDependency.writeContext = const_cast<GLES::Context*>(writeContext);
69 textureDependency.framebuffer = const_cast<GLES::Framebuffer*>(framebuffer);
70 textureDependency.agingSyncObject = mController.GetSyncPool().AllocateSyncObject(writeContext);
73 void TextureDependencyChecker::CheckNeedsSync(const GLES::Context* readContext, const GLES::Texture* texture)
75 uint32_t dependencyIndex = texture->GetDependencyIndex();
76 if(dependencyIndex < mTextureDependencies.size())
78 auto& textureDependency = mTextureDependencies[dependencyIndex];
79 if(!textureDependency.syncing && textureDependency.writeContext != readContext)
82 textureDependency.syncing = true;
84 // Wait on the sync object in GPU. This will ensure that the writeContext completes its tasks prior
86 mController.GetSyncPool().Wait(textureDependency.agingSyncObject);
91 } // namespace Dali::Graphics::GLES