2 * Copyright (c) 2021 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.
17 #include "test-graphics-controller.h"
19 #include "test-graphics-buffer.h"
20 #include "test-graphics-command-buffer.h"
21 #include "test-graphics-sampler.h"
22 #include "test-graphics-texture.h"
24 #include <dali/integration-api/gl-defines.h>
30 std::ostream& operator<<(std::ostream& o, const Graphics::BufferCreateInfo& bufferCreateInfo)
32 return o << "usage:" << std::hex << bufferCreateInfo.usage << ", size:" << std::dec << bufferCreateInfo.size;
35 std::ostream& operator<<(std::ostream& o, const Graphics::CommandBufferCreateInfo& commandBufferCreateInfo)
37 return o << "level:" << (commandBufferCreateInfo.level == Graphics::CommandBufferLevel::PRIMARY ? "PRIMARY" : "SECONDARY")
38 << ", fixedCapacity:" << std::dec << commandBufferCreateInfo.fixedCapacity;
41 std::ostream& operator<<(std::ostream& o, const Graphics::TextureType& textureType)
45 case Graphics::TextureType::TEXTURE_2D:
48 case Graphics::TextureType::TEXTURE_3D:
51 case Graphics::TextureType::TEXTURE_CUBEMAP:
52 o << "TEXTURE_CUBEMAP";
58 std::ostream& operator<<(std::ostream& o, const Graphics::Extent2D extent)
60 o << "width:" << extent.width << ", height:" << extent.height;
64 std::ostream& operator<<(std::ostream& o, const Graphics::TextureCreateInfo& createInfo)
66 o << "textureType:" << createInfo.textureType
67 << " size:" << createInfo.size
68 << " format:" << static_cast<uint32_t>(createInfo.format)
69 << " mipMapFlag:" << createInfo.mipMapFlag
70 << " layout:" << (createInfo.layout == Graphics::TextureLayout::LINEAR ? "LINEAR" : "OPTIMAL")
71 << " usageFlags:" << std::hex << createInfo.usageFlags
72 << " data:" << std::hex << createInfo.data
73 << " dataSize:" << std::dec << createInfo.dataSize
74 << " nativeImagePtr:" << std::hex << createInfo.nativeImagePtr;
78 std::ostream& operator<<(std::ostream& o, Graphics::SamplerAddressMode addressMode)
82 case Graphics::SamplerAddressMode::REPEAT:
85 case Graphics::SamplerAddressMode::MIRRORED_REPEAT:
86 o << "MIRRORED_REPEAT";
88 case Graphics::SamplerAddressMode::CLAMP_TO_EDGE:
91 case Graphics::SamplerAddressMode::CLAMP_TO_BORDER:
92 o << "CLAMP_TO_BORDER";
94 case Graphics::SamplerAddressMode::MIRROR_CLAMP_TO_EDGE:
95 o << "MIRROR_CLAMP_TO_EDGE";
101 std::ostream& operator<<(std::ostream& o, Graphics::SamplerFilter filterMode)
105 case Graphics::SamplerFilter::LINEAR:
108 case Graphics::SamplerFilter::NEAREST:
115 std::ostream& operator<<(std::ostream& o, Graphics::SamplerMipmapMode mipmapMode)
119 case Graphics::SamplerMipmapMode::NONE:
122 case Graphics::SamplerMipmapMode::LINEAR:
125 case Graphics::SamplerMipmapMode::NEAREST:
132 std::ostream& operator<<(std::ostream& o, const Graphics::SamplerCreateInfo& createInfo)
134 o << "minFilter:" << createInfo.minFilter
135 << " magFilter:" << createInfo.magFilter
136 << " wrapModeU:" << createInfo.addressModeU
137 << " wrapModeV:" << createInfo.addressModeV
138 << " wrapModeW:" << createInfo.addressModeW
139 << " mipMapMode:" << createInfo.mipMapMode;
143 TestGraphicsController::TestGraphicsController()
145 mCallStack.Enable(true);
146 mCallStack.EnableLogging(true);
147 mCommandBufferCallStack.Enable(true);
148 mCommandBufferCallStack.EnableLogging(true);
149 auto& trace = mGlAbstraction.GetTextureTrace();
151 trace.EnableLogging(true);
154 void TestGraphicsController::SubmitCommandBuffers(const Graphics::SubmitInfo& submitInfo)
156 std::ostringstream out;
157 TraceCallStack::NamedParams namedParams;
158 out << "cmdBuffer[" << submitInfo.cmdBuffer.size() << "], flags:" << std::hex << submitInfo.flags;
159 namedParams["submitInfo"] = out.str();
161 mCallStack.PushCall("SubmitCommandBuffers", "", namedParams);
163 for(auto& commandBuffer : submitInfo.cmdBuffer)
165 for(auto& binding : (static_cast<TestGraphicsCommandBuffer*>(commandBuffer))->mTextureBindings)
169 auto texture = const_cast<TestGraphicsTexture*>(static_cast<const TestGraphicsTexture*>(binding.texture));
171 texture->Bind(binding.binding);
175 auto sampler = const_cast<TestGraphicsSampler*>(static_cast<const TestGraphicsSampler*>(binding.sampler));
178 sampler->Apply(texture->GetTarget());
182 texture->Prepare(); // Ensure native texture is ready
189 * @brief Presents render target
190 * @param renderTarget render target to present
192 void TestGraphicsController::PresentRenderTarget(Graphics::RenderTarget* renderTarget)
194 std::ostringstream out;
195 TraceCallStack::NamedParams namedParams;
196 out << std::hex << renderTarget;
197 namedParams["renderTarget"] = out.str();
198 mCallStack.PushCall("PresentRenderTarget", "", namedParams);
202 * @brief Waits until the GPU is idle
204 void TestGraphicsController::WaitIdle()
206 mCallStack.PushCall("WaitIdle", "");
210 * @brief Lifecycle pause event
212 void TestGraphicsController::Pause()
214 mCallStack.PushCall("Pause", "");
218 * @brief Lifecycle resume event
220 void TestGraphicsController::Resume()
222 mCallStack.PushCall("Resume", "");
225 void TestGraphicsController::UpdateTextures(const std::vector<Graphics::TextureUpdateInfo>& updateInfoList,
226 const std::vector<Graphics::TextureUpdateSourceInfo>& sourceList)
228 std::ostringstream out;
229 TraceCallStack::NamedParams namedParams;
230 out << "[" << updateInfoList.size() << "]:";
231 namedParams["updateInfoList"] = out.str();
233 out << "[" << sourceList.size() << "]:";
234 namedParams["sourceList"] = out.str();
236 mCallStack.PushCall("UpdateTextures", "", namedParams);
238 // Call either TexImage2D or TexSubImage2D
239 for(unsigned int i = 0; i < updateInfoList.size(); ++i)
241 auto& updateInfo = updateInfoList[i];
242 auto& source = sourceList[i];
244 auto texture = static_cast<TestGraphicsTexture*>(updateInfo.dstTexture);
245 texture->Bind(0); // Use first texture unit during resource update
246 texture->Update(updateInfo, source);
250 bool TestGraphicsController::EnableDepthStencilBuffer(bool enableDepth, bool enableStencil)
252 TraceCallStack::NamedParams namedParams;
253 namedParams["enableDepth"] = enableDepth ? "T" : "F";
254 namedParams["enableStencil"] = enableStencil ? "T" : "F";
255 mCallStack.PushCall("EnableDepthStencilBuffer", "", namedParams);
259 void TestGraphicsController::RunGarbageCollector(size_t numberOfDiscardedRenderers)
261 std::ostringstream out;
262 out << numberOfDiscardedRenderers;
263 TraceCallStack::NamedParams namedParams;
264 namedParams["numberOfDiscardedrenderers"] = out.str();
265 mCallStack.PushCall("RunGarbageCollector", "", namedParams);
268 void TestGraphicsController::DiscardUnusedResources()
270 mCallStack.PushCall("DiscardUnusedResources", "");
273 bool TestGraphicsController::IsDiscardQueueEmpty()
275 mCallStack.PushCall("IsDiscardQueueEmpty", "");
276 return isDiscardQueueEmptyResult;
280 * @brief Test if the graphics subsystem has resumed & should force a draw
282 * @return true if the graphics subsystem requires a re-draw
284 bool TestGraphicsController::IsDrawOnResumeRequired()
286 mCallStack.PushCall("IsDrawOnResumeRequired", "");
287 return isDrawOnResumeRequiredResult;
290 Graphics::UniquePtr<Graphics::Buffer> TestGraphicsController::CreateBuffer(const Graphics::BufferCreateInfo& bufferCreateInfo, Graphics::UniquePtr<Graphics::Buffer>&& oldBuffer)
292 std::ostringstream oss;
293 oss << "bufferCreateInfo:" << bufferCreateInfo;
294 mCallStack.PushCall("CreateBuffer", oss.str());
296 return Graphics::MakeUnique<TestGraphicsBuffer>();
299 Graphics::UniquePtr<Graphics::CommandBuffer> TestGraphicsController::CreateCommandBuffer(const Graphics::CommandBufferCreateInfo& commandBufferCreateInfo, Graphics::UniquePtr<Graphics::CommandBuffer>&& oldCommandBuffer)
301 std::ostringstream oss;
302 oss << "commandBufferCreateInfo:" << commandBufferCreateInfo;
303 mCallStack.PushCall("CreateCommandBuffer", oss.str());
304 return Graphics::MakeUnique<TestGraphicsCommandBuffer>(mCommandBufferCallStack, mGlAbstraction);
307 Graphics::UniquePtr<Graphics::RenderPass> TestGraphicsController::CreateRenderPass(const Graphics::RenderPassCreateInfo& renderPassCreateInfo, Graphics::UniquePtr<Graphics::RenderPass>&& oldRenderPass)
309 mCallStack.PushCall("CreateRenderPass", "");
313 Graphics::UniquePtr<Graphics::Texture> TestGraphicsController::CreateTexture(const Graphics::TextureCreateInfo& textureCreateInfo, Graphics::UniquePtr<Graphics::Texture>&& oldTexture)
315 std::ostringstream params, oss;
316 params << "textureCreateInfo:" << textureCreateInfo;
317 TraceCallStack::NamedParams namedParams;
318 oss << textureCreateInfo;
319 namedParams["textureCreateInfo"] = oss.str();
320 mCallStack.PushCall("CreateTexture", params.str(), namedParams);
322 return Graphics::MakeUnique<TestGraphicsTexture>(mGlAbstraction, textureCreateInfo);
325 Graphics::UniquePtr<Graphics::Framebuffer> TestGraphicsController::CreateFramebuffer(const Graphics::FramebufferCreateInfo& framebufferCreateInfo, Graphics::UniquePtr<Graphics::Framebuffer>&& oldFramebuffer)
327 mCallStack.PushCall("CreateFramebuffer", "");
331 Graphics::UniquePtr<Graphics::Pipeline> TestGraphicsController::CreatePipeline(const Graphics::PipelineCreateInfo& pipelineCreateInfo, Graphics::UniquePtr<Graphics::Pipeline>&& oldPipeline)
333 mCallStack.PushCall("CreatePipeline", "");
337 Graphics::UniquePtr<Graphics::Shader> TestGraphicsController::CreateShader(const Graphics::ShaderCreateInfo& shaderCreateInfo, Graphics::UniquePtr<Graphics::Shader>&& oldShader)
339 mCallStack.PushCall("CreateShader", "");
343 Graphics::UniquePtr<Graphics::Sampler> TestGraphicsController::CreateSampler(const Graphics::SamplerCreateInfo& samplerCreateInfo, Graphics::UniquePtr<Graphics::Sampler>&& oldSampler)
345 std::ostringstream params, oss;
346 params << "samplerCreateInfo:" << samplerCreateInfo;
347 TraceCallStack::NamedParams namedParams;
348 oss << samplerCreateInfo;
349 namedParams["samplerCreateInfo"] = oss.str();
350 mCallStack.PushCall("CreateSampler", params.str(), namedParams);
352 return Graphics::MakeUnique<TestGraphicsSampler>(mGlAbstraction, samplerCreateInfo);
355 Graphics::UniquePtr<Graphics::RenderTarget> TestGraphicsController::CreateRenderTarget(const Graphics::RenderTargetCreateInfo& renderTargetCreateInfo, Graphics::UniquePtr<Graphics::RenderTarget>&& oldRenderTarget)
357 mCallStack.PushCall("CreateRenderTarget", "");
361 Graphics::UniquePtr<Graphics::Memory> TestGraphicsController::MapBufferRange(const Graphics::MapBufferInfo& mapInfo)
363 mCallStack.PushCall("MapBufferRange", "");
367 Graphics::UniquePtr<Graphics::Memory> TestGraphicsController::MapTextureRange(const Graphics::MapTextureInfo& mapInfo)
369 mCallStack.PushCall("MapTextureRange", "");
373 void TestGraphicsController::UnmapMemory(Graphics::UniquePtr<Graphics::Memory> memory)
375 mCallStack.PushCall("UnmapMemory", "");
378 Graphics::MemoryRequirements TestGraphicsController::GetTextureMemoryRequirements(Graphics::Texture& texture) const
380 mCallStack.PushCall("GetTextureMemoryRequirements", "");
381 return Graphics::MemoryRequirements{};
384 Graphics::MemoryRequirements TestGraphicsController::GetBufferMemoryRequirements(Graphics::Buffer& buffer) const
386 mCallStack.PushCall("GetBufferMemoryRequirements", "");
387 return Graphics::MemoryRequirements{};
390 const Graphics::TextureProperties& TestGraphicsController::GetTextureProperties(const Graphics::Texture& texture)
392 static Graphics::TextureProperties textureProperties{};
393 mCallStack.PushCall("GetTextureProperties", "");
395 return textureProperties;
398 bool TestGraphicsController::PipelineEquals(const Graphics::Pipeline& pipeline0, const Graphics::Pipeline& pipeline1) const
400 mCallStack.PushCall("PipelineEquals", "");