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-graphics-command-buffer.h"
24 #include "test-graphics-program.h"
25 #include "test-graphics-reflection.h"
26 #include "test-graphics-sync-impl.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));
89 T* Uncast(const Graphics::SyncObject* object)
91 return const_cast<T*>(static_cast<const T*>(object));
94 class TestGraphicsController : public Dali::Graphics::Controller
97 TestGraphicsController();
99 virtual ~TestGraphicsController() = default;
106 Integration::GlAbstraction& GetGlAbstraction() override
111 Integration::GlContextHelperAbstraction& GetGlContextHelperAbstraction() override
113 return mGlContextHelperAbstraction;
116 TestGraphicsSyncImplementation& GetGraphicsSyncImpl()
118 return mGraphicsSyncImpl;
121 void SubmitCommandBuffers(const Graphics::SubmitInfo& submitInfo) override;
124 * @brief Presents render target
125 * @param renderTarget render target to present
127 void PresentRenderTarget(Graphics::RenderTarget* renderTarget) override;
130 * @brief Waits until the GPU is idle
132 void WaitIdle() override;
135 * @brief Lifecycle pause event
137 void Pause() override;
140 * @brief Lifecycle resume event
142 void Resume() override;
145 * @brief Lifecycle shutdown event
147 void Shutdown() override;
150 * @brief Lifecycle destroy event
152 void Destroy() override;
155 * @brief Executes batch update of textures
157 * This function may perform full or partial update of many textures.
158 * The data source may come from:
159 * - CPU memory (client side)
160 * - GPU memory (another Texture or Buffer)
162 * UpdateTextures() is the only way to update unmappable Texture objects.
163 * It is recommended to batch updates as it may help with optimizing
164 * memory transfers based on dependencies.
167 void UpdateTextures(const std::vector<Graphics::TextureUpdateInfo>& updateInfoList,
168 const std::vector<Graphics::TextureUpdateSourceInfo>& sourceList) override;
171 * Auto generates mipmaps for the texture
172 * @param[in] texture The texture
174 void GenerateTextureMipmaps(const Graphics::Texture& texture) override;
177 * TBD: do we need those functions in the new implementation?
179 bool EnableDepthStencilBuffer(bool enableDepth, bool enableStencil) override;
181 void RunGarbageCollector(size_t numberOfDiscardedRenderers) override;
183 void DiscardUnusedResources() override;
185 bool IsDiscardQueueEmpty() override;
188 * @brief Test if the graphics subsystem has resumed & should force a draw
190 * @return true if the graphics subsystem requires a re-draw
192 bool IsDrawOnResumeRequired() override;
195 * @brief Creates new Buffer object
197 * The Buffer object is created with underlying memory. The Buffer
198 * specification is immutable. Based on the BufferCreateInfo::usage,
199 * the memory may be client-side mappable or not.
201 * The old buffer may be passed as BufferCreateInfo::oldbuffer, however,
202 * it's up to the implementation whether the object will be reused or
203 * discarded and replaced by the new one.
205 * @param[in] bufferCreateInfo The valid BufferCreateInfo structure
206 * @return pointer to the Buffer object
208 Graphics::UniquePtr<Graphics::Buffer> CreateBuffer(const Graphics::BufferCreateInfo& bufferCreateInfo, Graphics::UniquePtr<Graphics::Buffer>&& oldBuffer) override;
211 * @brief Creates new CommandBuffer object
213 * @param[in] bufferCreateInfo The valid BufferCreateInfo structure
214 * @return pointer to the CommandBuffer object
216 Graphics::UniquePtr<Graphics::CommandBuffer> CreateCommandBuffer(const Graphics::CommandBufferCreateInfo& commandBufferCreateInfo, Graphics::UniquePtr<Graphics::CommandBuffer>&& oldCommandBuffer) override;
219 * @brief Creates new RenderPass object
221 * @param[in] renderPassCreateInfo The valid RenderPassCreateInfo structure
222 * @return pointer to the RenderPass object
224 Graphics::UniquePtr<Graphics::RenderPass> CreateRenderPass(const Graphics::RenderPassCreateInfo& renderPassCreateInfo, Graphics::UniquePtr<Graphics::RenderPass>&& oldRenderPass) override;
227 * @brief Creates new Texture object
229 * @param[in] textureCreateInfo The valid TextureCreateInfo structure
230 * @return pointer to the TextureCreateInfo object
232 Graphics::UniquePtr<Graphics::Texture> CreateTexture(const Graphics::TextureCreateInfo& textureCreateInfo, Graphics::UniquePtr<Graphics::Texture>&& oldTexture) override;
235 * @brief Creates new Framebuffer object
237 * @param[in] framebufferCreateInfo The valid FramebufferCreateInfo structure
238 * @return pointer to the Framebuffer object
240 Graphics::UniquePtr<Graphics::Framebuffer> CreateFramebuffer(const Graphics::FramebufferCreateInfo& framebufferCreateInfo, Graphics::UniquePtr<Graphics::Framebuffer>&& oldFramebuffer) override;
243 * @brief Creates new Pipeline object
245 * @param[in] pipelineCreateInfo The valid PipelineCreateInfo structure
246 * @return pointer to the Pipeline object
248 Graphics::UniquePtr<Graphics::Pipeline> CreatePipeline(const Graphics::PipelineCreateInfo& pipelineCreateInfo, Graphics::UniquePtr<Graphics::Pipeline>&& oldPipeline) override;
251 * @brief Creates new Program object
253 * @param[in] programCreateInfo The valid ProgramCreateInfo structure
254 * @return pointer to the Program object
256 Graphics::UniquePtr<Graphics::Program> CreateProgram(const Graphics::ProgramCreateInfo& programCreateInfo, Graphics::UniquePtr<Graphics::Program>&& oldProgram) override;
259 * @brief Creates new Shader object
261 * @param[in] shaderCreateInfo The valid ShaderCreateInfo structure
262 * @return pointer to the Shader object
264 Graphics::UniquePtr<Graphics::Shader> CreateShader(const Graphics::ShaderCreateInfo& shaderCreateInfo, Graphics::UniquePtr<Graphics::Shader>&& oldShader) override;
267 * @brief Creates new Sampler object
269 * @param[in] samplerCreateInfo The valid SamplerCreateInfo structure
270 * @return pointer to the Sampler object
272 Graphics::UniquePtr<Graphics::Sampler> CreateSampler(const Graphics::SamplerCreateInfo& samplerCreateInfo, Graphics::UniquePtr<Graphics::Sampler>&& oldSampler) override;
275 * @brief Creates new RenderTarget object
277 * @param[in] renderTargetCreateInfo The valid RenderTargetCreateInfo structure
278 * @return pointer to the RenderTarget object
280 Graphics::UniquePtr<Graphics::RenderTarget> CreateRenderTarget(const Graphics::RenderTargetCreateInfo& renderTargetCreateInfo, Graphics::UniquePtr<Graphics::RenderTarget>&& oldRenderTarget) override;
283 * @brief Creates new sync object
284 * Could add timeout etc to createinfo... but nah.
286 * @return pointer to the SyncObject
288 Graphics::UniquePtr<Graphics::SyncObject> CreateSyncObject(const Graphics::SyncObjectCreateInfo& syncObjectCreateInfo,
289 Graphics::UniquePtr<Graphics::SyncObject>&& oldSyncObject) override;
292 * @brief Maps memory associated with Buffer object
294 * @param[in] mapInfo Filled details of mapped resource
296 * @return Returns pointer to Memory object or nullptr on error
298 Graphics::UniquePtr<Graphics::Memory> MapBufferRange(const Graphics::MapBufferInfo& mapInfo) override;
301 * @brief Maps memory associated with the texture.
303 * Only Texture objects that are backed with linear memory (staging memory) can be mapped.
305 * 1) GLES implementation may create PBO object as staging memory and couple it
306 * with the texture. Texture can be mapped and the memory can be read/write on demand.
308 * 2) Vulkan implementation may allocate DeviceMemory and use linear layout.
310 * @param[in] mapInfo Filled details of mapped resource
312 * @return Valid Memory object or nullptr on error
314 Graphics::UniquePtr<Graphics::Memory> MapTextureRange(const Graphics::MapTextureInfo& mapInfo) override;
317 * @brief Unmaps memory and discards Memory object
319 * This function automatically removes lock if Memory has been
322 * @param[in] memory Valid and previously mapped Memory object
324 void UnmapMemory(Graphics::UniquePtr<Graphics::Memory> memory) override;
327 * @brief Returns memory requirements of the Texture object.
329 * Call this function whenever it's necessary to know how much memory
330 * is needed to store all the texture data and what memory alignment
331 * the data should follow.
333 * @return Returns memory requirements of Texture
335 Graphics::MemoryRequirements GetTextureMemoryRequirements(Graphics::Texture& texture) const override;
338 * @brief Returns memory requirements of the Buffer object.
340 * Call this function whenever it's necessary to know how much memory
341 * is needed to store all the buffer data and what memory alignment
342 * the data should follow.
344 * @return Returns memory requirements of Buffer
346 Graphics::MemoryRequirements GetBufferMemoryRequirements(Graphics::Buffer& buffer) const override;
349 * @brief Returns specification of the Texture object
351 * Function obtains specification of the Texture object. It may retrieve
352 * implementation dependent details like ie. whether the texture is
353 * emulated (for example, RGB emulated on RGBA), compressed etc.
355 * @return Returns the TextureProperties object
357 const Graphics::TextureProperties& GetTextureProperties(const Graphics::Texture& texture) override;
360 * @brief Returns the reflection of the given program
362 * @param[in] program The program
363 * @return The reflection of the program
365 const Graphics::Reflection& GetProgramReflection(const Graphics::Program& program) override;
368 * @brief Tests whether two Pipelines are the same.
370 * On the higher level, this function may help wit creating pipeline cache.
372 * @return true if pipeline objects match
374 bool PipelineEquals(const Graphics::Pipeline& pipeline0, const Graphics::Pipeline& pipeline1) const override;
376 public: // Test Functions
377 void SetVertexFormats(Property::Array& vfs)
379 mVertexFormats = vfs;
382 void AddCustomUniforms(std::vector<UniformData>& customUniforms)
384 mCustomUniforms = customUniforms;
387 void ClearSubmitStack()
389 mSubmitStack.clear();
393 * @brief Retrieves program parameters
395 * This function can be used to retrieve data from internal implementation
397 * @param[in] program Valid program object
398 * @param[in] parameterId Integer parameter id
399 * @param[out] outData Pointer to output memory
400 * @return True on success
402 bool GetProgramParameter(Graphics::Program& program, uint32_t parameterId, void* outData) override;
404 void ProcessCommandBuffer(TestGraphicsCommandBuffer& commandBuffer);
406 void BindPipeline(TestGraphicsPipeline* pipeline);
409 mutable TraceCallStack mCallStack;
410 mutable TraceCallStack mCommandBufferCallStack;
411 mutable TraceCallStack mFrameBufferCallStack;
412 mutable std::vector<Graphics::SubmitInfo> mSubmitStack;
414 TestGlAbstraction mGl;
415 TestGraphicsSyncImplementation mGraphicsSyncImpl;
416 TestGlContextHelperAbstraction mGlContextHelperAbstraction;
418 bool isDiscardQueueEmptyResult{true};
419 bool isDrawOnResumeRequiredResult{true};
421 Property::Array mVertexFormats;
425 std::map<Graphics::PipelineStage, std::vector<uint8_t>> shaders;
426 TestGraphicsProgramImpl* programImpl;
428 std::vector<ProgramCache> mProgramCache;
434 std::vector<UniformData> mCustomUniforms;
439 #endif //TEST_GRAPHICS_CONTROLLER_H