1 #ifndef TEST_GRAPHICS_CONTROLLER_H
2 #define TEST_GRAPHICS_CONTROLLER_H
5 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 #include <dali/graphics-api/graphics-controller.h>
21 #include "test-gl-abstraction.h"
22 #include "test-gl-context-helper-abstraction.h"
23 #include "test-gl-sync-abstraction.h"
24 #include "test-graphics-command-buffer.h"
25 #include "test-graphics-program.h"
26 #include "test-graphics-reflection.h"
30 std::ostream& operator<<(std::ostream& o, const Graphics::BufferCreateInfo& bufferCreateInfo);
31 std::ostream& operator<<(std::ostream& o, const Graphics::CommandBufferCreateInfo& commandBufferCreateInfo);
32 std::ostream& operator<<(std::ostream& o, const Graphics::TextureType& textureType);
33 std::ostream& operator<<(std::ostream& o, const Graphics::Extent2D extent);
34 std::ostream& operator<<(std::ostream& o, const Graphics::TextureCreateInfo& createInfo);
35 std::ostream& operator<<(std::ostream& o, Graphics::SamplerAddressMode addressMode);
36 std::ostream& operator<<(std::ostream& o, Graphics::SamplerFilter filterMode);
37 std::ostream& operator<<(std::ostream& o, Graphics::SamplerMipmapMode mipmapMode);
38 std::ostream& operator<<(std::ostream& o, const Graphics::SamplerCreateInfo& createInfo);
41 T* Uncast(const Graphics::CommandBuffer* object)
43 return const_cast<T*>(static_cast<const T*>(object));
47 T* Uncast(const Graphics::Texture* object)
49 return const_cast<T*>(static_cast<const T*>(object));
53 T* Uncast(const Graphics::Sampler* object)
55 return const_cast<T*>(static_cast<const T*>(object));
59 T* Uncast(const Graphics::Buffer* object)
61 return const_cast<T*>(static_cast<const T*>(object));
65 T* Uncast(const Graphics::Shader* object)
67 return const_cast<T*>(static_cast<const T*>(object));
71 T* Uncast(const Graphics::Framebuffer* object)
73 return const_cast<T*>(static_cast<const T*>(object));
77 T* Uncast(const Graphics::Pipeline* object)
79 return const_cast<T*>(static_cast<const T*>(object));
83 T* Uncast(const Graphics::RenderTarget* object)
85 return const_cast<T*>(static_cast<const T*>(object));
88 class TestGraphicsController : public Dali::Graphics::Controller
91 TestGraphicsController();
93 virtual ~TestGraphicsController() = default;
100 Integration::GlAbstraction& GetGlAbstraction() override
105 Integration::GlSyncAbstraction& GetGlSyncAbstraction() override
107 return mGlSyncAbstraction;
110 Integration::GlContextHelperAbstraction& GetGlContextHelperAbstraction() override
112 return mGlContextHelperAbstraction;
115 void SubmitCommandBuffers(const Graphics::SubmitInfo& submitInfo) override;
118 * @brief Presents render target
119 * @param renderTarget render target to present
121 void PresentRenderTarget(Graphics::RenderTarget* renderTarget) override;
124 * @brief Waits until the GPU is idle
126 void WaitIdle() override;
129 * @brief Lifecycle pause event
131 void Pause() override;
134 * @brief Lifecycle resume event
136 void Resume() override;
139 * @brief Lifecycle shutdown event
141 void Shutdown() override;
144 * @brief Lifecycle destroy event
146 void Destroy() override;
149 * @brief Executes batch update of textures
151 * This function may perform full or partial update of many textures.
152 * The data source may come from:
153 * - CPU memory (client side)
154 * - GPU memory (another Texture or Buffer)
156 * UpdateTextures() is the only way to update unmappable Texture objects.
157 * It is recommended to batch updates as it may help with optimizing
158 * memory transfers based on dependencies.
161 void UpdateTextures(const std::vector<Graphics::TextureUpdateInfo>& updateInfoList,
162 const std::vector<Graphics::TextureUpdateSourceInfo>& sourceList) override;
165 * TBD: do we need those functions in the new implementation?
167 bool EnableDepthStencilBuffer(bool enableDepth, bool enableStencil) override;
169 void RunGarbageCollector(size_t numberOfDiscardedRenderers) override;
171 void DiscardUnusedResources() override;
173 bool IsDiscardQueueEmpty() override;
176 * @brief Test if the graphics subsystem has resumed & should force a draw
178 * @return true if the graphics subsystem requires a re-draw
180 bool IsDrawOnResumeRequired() override;
183 * @brief Creates new Buffer object
185 * The Buffer object is created with underlying memory. The Buffer
186 * specification is immutable. Based on the BufferCreateInfo::usage,
187 * the memory may be client-side mappable or not.
189 * The old buffer may be passed as BufferCreateInfo::oldbuffer, however,
190 * it's up to the implementation whether the object will be reused or
191 * discarded and replaced by the new one.
193 * @param[in] bufferCreateInfo The valid BufferCreateInfo structure
194 * @return pointer to the Buffer object
196 Graphics::UniquePtr<Graphics::Buffer> CreateBuffer(const Graphics::BufferCreateInfo& bufferCreateInfo, Graphics::UniquePtr<Graphics::Buffer>&& oldBuffer) override;
199 * @brief Creates new CommandBuffer object
201 * @param[in] bufferCreateInfo The valid BufferCreateInfo structure
202 * @return pointer to the CommandBuffer object
204 Graphics::UniquePtr<Graphics::CommandBuffer> CreateCommandBuffer(const Graphics::CommandBufferCreateInfo& commandBufferCreateInfo, Graphics::UniquePtr<Graphics::CommandBuffer>&& oldCommandBuffer) override;
207 * @brief Creates new RenderPass object
209 * @param[in] renderPassCreateInfo The valid RenderPassCreateInfo structure
210 * @return pointer to the RenderPass object
212 Graphics::UniquePtr<Graphics::RenderPass> CreateRenderPass(const Graphics::RenderPassCreateInfo& renderPassCreateInfo, Graphics::UniquePtr<Graphics::RenderPass>&& oldRenderPass) override;
215 * @brief Creates new Texture object
217 * @param[in] textureCreateInfo The valid TextureCreateInfo structure
218 * @return pointer to the TextureCreateInfo object
220 Graphics::UniquePtr<Graphics::Texture> CreateTexture(const Graphics::TextureCreateInfo& textureCreateInfo, Graphics::UniquePtr<Graphics::Texture>&& oldTexture) override;
223 * @brief Creates new Framebuffer object
225 * @param[in] framebufferCreateInfo The valid FramebufferCreateInfo structure
226 * @return pointer to the Framebuffer object
228 Graphics::UniquePtr<Graphics::Framebuffer> CreateFramebuffer(const Graphics::FramebufferCreateInfo& framebufferCreateInfo, Graphics::UniquePtr<Graphics::Framebuffer>&& oldFramebuffer) override;
231 * @brief Creates new Pipeline object
233 * @param[in] pipelineCreateInfo The valid PipelineCreateInfo structure
234 * @return pointer to the Pipeline object
236 Graphics::UniquePtr<Graphics::Pipeline> CreatePipeline(const Graphics::PipelineCreateInfo& pipelineCreateInfo, Graphics::UniquePtr<Graphics::Pipeline>&& oldPipeline) override;
239 * @brief Creates new Program object
241 * @param[in] programCreateInfo The valid ProgramCreateInfo structure
242 * @return pointer to the Program object
244 Graphics::UniquePtr<Graphics::Program> CreateProgram(const Graphics::ProgramCreateInfo& programCreateInfo, Graphics::UniquePtr<Graphics::Program>&& oldProgram) override;
247 * @brief Creates new Shader object
249 * @param[in] shaderCreateInfo The valid ShaderCreateInfo structure
250 * @return pointer to the Shader object
252 Graphics::UniquePtr<Graphics::Shader> CreateShader(const Graphics::ShaderCreateInfo& shaderCreateInfo, Graphics::UniquePtr<Graphics::Shader>&& oldShader) override;
255 * @brief Creates new Sampler object
257 * @param[in] samplerCreateInfo The valid SamplerCreateInfo structure
258 * @return pointer to the Sampler object
260 Graphics::UniquePtr<Graphics::Sampler> CreateSampler(const Graphics::SamplerCreateInfo& samplerCreateInfo, Graphics::UniquePtr<Graphics::Sampler>&& oldSampler) override;
263 * @brief Creates new RenderTarget object
265 * @param[in] renderTargetCreateInfo The valid RenderTargetCreateInfo structure
266 * @return pointer to the RenderTarget object
268 Graphics::UniquePtr<Graphics::RenderTarget> CreateRenderTarget(const Graphics::RenderTargetCreateInfo& renderTargetCreateInfo, Graphics::UniquePtr<Graphics::RenderTarget>&& oldRenderTarget) override;
271 * @brief Maps memory associated with Buffer object
273 * @param[in] mapInfo Filled details of mapped resource
275 * @return Returns pointer to Memory object or Graphicsnullptr on error
277 Graphics::UniquePtr<Graphics::Memory> MapBufferRange(const Graphics::MapBufferInfo& mapInfo) override;
280 * @brief Maps memory associated with the texture.
282 * Only Texture objects that are backed with linear memory (staging memory) can be mapped.
284 * 1) GLES implementation may create PBO object as staging memory and couple it
285 * with the texture. Texture can be mapped and the memory can be read/write on demand.
287 * 2) Vulkan implementation may allocate DeviceMemory and use linear layout.
289 * @param[in] mapInfo Filled details of mapped resource
291 * @return Valid Memory object or nullptr on error
293 Graphics::UniquePtr<Graphics::Memory> MapTextureRange(const Graphics::MapTextureInfo& mapInfo) override;
296 * @brief Unmaps memory and discards Memory object
298 * This function automatically removes lock if Memory has been
301 * @param[in] memory Valid and previously mapped Memory object
303 void UnmapMemory(Graphics::UniquePtr<Graphics::Memory> memory) override;
306 * @brief Returns memory requirements of the Texture object.
308 * Call this function whenever it's necessary to know how much memory
309 * is needed to store all the texture data and what memory alignment
310 * the data should follow.
312 * @return Returns memory requirements of Texture
314 Graphics::MemoryRequirements GetTextureMemoryRequirements(Graphics::Texture& texture) const override;
317 * @brief Returns memory requirements of the Buffer object.
319 * Call this function whenever it's necessary to know how much memory
320 * is needed to store all the buffer data and what memory alignment
321 * the data should follow.
323 * @return Returns memory requirements of Buffer
325 Graphics::MemoryRequirements GetBufferMemoryRequirements(Graphics::Buffer& buffer) const override;
328 * @brief Returns specification of the Texture object
330 * Function obtains specification of the Texture object. It may retrieve
331 * implementation dependent details like ie. whether the texture is
332 * emulated (for example, RGB emulated on RGBA), compressed etc.
334 * @return Returns the TextureProperties object
336 const Graphics::TextureProperties& GetTextureProperties(const Graphics::Texture& texture) override;
339 * @brief Returns the reflection of the given program
341 * @param[in] program The program
342 * @return The reflection of the program
344 const Graphics::Reflection& GetProgramReflection(const Graphics::Program& program) override;
347 * @brief Tests whether two Pipelines are the same.
349 * On the higher level, this function may help wit creating pipeline cache.
351 * @return true if pipeline objects match
353 bool PipelineEquals(const Graphics::Pipeline& pipeline0, const Graphics::Pipeline& pipeline1) const override;
355 public: // Test Functions
356 void SetVertexFormats(Property::Array& vfs)
358 mVertexFormats = vfs;
361 void AddCustomUniforms(std::vector<UniformData>& customUniforms)
363 mCustomUniforms = customUniforms;
366 void ClearSubmitStack()
368 mSubmitStack.clear();
372 * @brief Retrieves program parameters
374 * This function can be used to retrieve data from internal implementation
376 * @param[in] program Valid program object
377 * @param[in] parameterId Integer parameter id
378 * @param[out] outData Pointer to output memory
379 * @return True on success
381 bool GetProgramParameter(Graphics::Program& program, uint32_t parameterId, void* outData) override;
383 void ProcessCommandBuffer(TestGraphicsCommandBuffer& commandBuffer);
385 void BindPipeline(TestGraphicsPipeline* pipeline);
388 mutable TraceCallStack mCallStack;
389 mutable TraceCallStack mCommandBufferCallStack;
390 mutable TraceCallStack mFrameBufferCallStack;
391 mutable std::vector<Graphics::SubmitInfo> mSubmitStack;
393 TestGlAbstraction mGl;
394 TestGlSyncAbstraction mGlSyncAbstraction;
395 TestGlContextHelperAbstraction mGlContextHelperAbstraction;
397 bool isDiscardQueueEmptyResult{true};
398 bool isDrawOnResumeRequiredResult{true};
400 Property::Array mVertexFormats;
404 std::map<Graphics::PipelineStage, std::vector<uint8_t>> shaders;
405 TestGraphicsProgramImpl* programImpl;
407 std::vector<ProgramCache> mProgramCache;
409 std::vector<UniformData> mCustomUniforms;
414 #endif //TEST_GRAPHICS_CONTROLLER_H