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.
17 #include "test-graphics-controller.h"
19 #include "test-graphics-buffer.h"
20 #include "test-graphics-command-buffer.h"
21 #include "test-graphics-framebuffer.h"
22 #include "test-graphics-reflection.h"
23 #include "test-graphics-render-pass.h"
24 #include "test-graphics-render-target.h"
25 #include "test-graphics-sampler.h"
26 #include "test-graphics-shader.h"
27 #include "test-graphics-sync-object.h"
28 #include "test-graphics-texture.h"
30 #include <dali/integration-api/gl-defines.h>
37 std::ostream& operator<<(std::ostream& o, const Graphics::BufferCreateInfo& bufferCreateInfo)
39 return o << "usage:" << std::hex << bufferCreateInfo.usage << ", size:" << std::dec << bufferCreateInfo.size;
42 std::ostream& operator<<(std::ostream& o, const Graphics::CommandBufferCreateInfo& commandBufferCreateInfo)
44 return o << "level:" << (commandBufferCreateInfo.level == Graphics::CommandBufferLevel::PRIMARY ? "PRIMARY" : "SECONDARY")
45 << ", fixedCapacity:" << std::dec << commandBufferCreateInfo.fixedCapacity;
48 std::ostream& operator<<(std::ostream& o, const Graphics::TextureType& textureType)
52 case Graphics::TextureType::TEXTURE_2D:
55 case Graphics::TextureType::TEXTURE_3D:
58 case Graphics::TextureType::TEXTURE_CUBEMAP:
59 o << "TEXTURE_CUBEMAP";
65 std::ostream& operator<<(std::ostream& o, const Graphics::Extent2D extent)
67 o << "width:" << extent.width << ", height:" << extent.height;
71 std::ostream& operator<<(std::ostream& o, const Graphics::TextureCreateInfo& createInfo)
73 o << "textureType:" << createInfo.textureType
74 << " size:" << createInfo.size
75 << " format:" << static_cast<uint32_t>(createInfo.format)
76 << " mipMapFlag:" << createInfo.mipMapFlag
77 << " layout:" << (createInfo.layout == Graphics::TextureLayout::LINEAR ? "LINEAR" : "OPTIMAL")
78 << " usageFlags:" << std::hex << createInfo.usageFlags
79 << " data:" << std::hex << createInfo.data
80 << " dataSize:" << std::dec << createInfo.dataSize
81 << " nativeImagePtr:" << std::hex << createInfo.nativeImagePtr.Get();
85 std::ostream& operator<<(std::ostream& o, Graphics::SamplerAddressMode addressMode)
89 case Graphics::SamplerAddressMode::REPEAT:
92 case Graphics::SamplerAddressMode::MIRRORED_REPEAT:
93 o << "MIRRORED_REPEAT";
95 case Graphics::SamplerAddressMode::CLAMP_TO_EDGE:
98 case Graphics::SamplerAddressMode::CLAMP_TO_BORDER:
99 o << "CLAMP_TO_BORDER";
101 case Graphics::SamplerAddressMode::MIRROR_CLAMP_TO_EDGE:
102 o << "MIRROR_CLAMP_TO_EDGE";
108 std::ostream& operator<<(std::ostream& o, Graphics::SamplerFilter filterMode)
112 case Graphics::SamplerFilter::LINEAR:
115 case Graphics::SamplerFilter::NEAREST:
122 std::ostream& operator<<(std::ostream& o, Graphics::SamplerMipmapMode mipmapMode)
126 case Graphics::SamplerMipmapMode::NONE:
129 case Graphics::SamplerMipmapMode::LINEAR:
132 case Graphics::SamplerMipmapMode::NEAREST:
139 std::ostream& operator<<(std::ostream& o, const Graphics::SamplerCreateInfo& createInfo)
141 o << "minFilter:" << createInfo.minFilter
142 << " magFilter:" << createInfo.magFilter
143 << " wrapModeU:" << createInfo.addressModeU
144 << " wrapModeV:" << createInfo.addressModeV
145 << " wrapModeW:" << createInfo.addressModeW
146 << " mipMapMode:" << createInfo.mipMapMode;
150 std::ostream& operator<<(std::ostream& o, const Graphics::ColorAttachment& colorAttachment)
152 o << "attachmentId:" << colorAttachment.attachmentId
153 << " layerId:" << colorAttachment.layerId
154 << " levelId:" << colorAttachment.levelId
155 << " texture:" << colorAttachment.texture;
159 std::ostream& operator<<(std::ostream& o, const Graphics::DepthStencilAttachment& depthStencilAttachment)
161 o << "depthTexture:" << depthStencilAttachment.depthTexture
162 << "depthLevel:" << depthStencilAttachment.depthLevel
163 << "stencilTexture:" << depthStencilAttachment.stencilTexture
164 << "stencilLevel:" << depthStencilAttachment.stencilLevel;
168 std::ostream& operator<<(std::ostream& o, const Graphics::FramebufferCreateInfo& createInfo)
170 o << "colorAttachments:";
171 for(auto i = 0u; i < createInfo.colorAttachments.size(); ++i)
173 o << "[" << i << "]=" << createInfo.colorAttachments[i] << " ";
175 o << "depthStencilAttachment:" << createInfo.depthStencilAttachment;
176 o << "size: " << createInfo.size;
180 int GetNumComponents(Graphics::VertexInputFormat vertexFormat)
184 case Graphics::VertexInputFormat::UNDEFINED:
185 case Graphics::VertexInputFormat::FLOAT:
186 case Graphics::VertexInputFormat::INTEGER:
188 case Graphics::VertexInputFormat::IVECTOR2:
189 case Graphics::VertexInputFormat::FVECTOR2:
191 case Graphics::VertexInputFormat::IVECTOR3:
192 case Graphics::VertexInputFormat::FVECTOR3:
194 case Graphics::VertexInputFormat::FVECTOR4:
195 case Graphics::VertexInputFormat::IVECTOR4:
201 GLint GetSize(Graphics::VertexInputFormat vertexFormat)
205 case Graphics::VertexInputFormat::UNDEFINED:
207 case Graphics::VertexInputFormat::INTEGER:
208 case Graphics::VertexInputFormat::IVECTOR2:
209 case Graphics::VertexInputFormat::IVECTOR3:
210 case Graphics::VertexInputFormat::IVECTOR4:
212 case Graphics::VertexInputFormat::FLOAT:
213 case Graphics::VertexInputFormat::FVECTOR2:
214 case Graphics::VertexInputFormat::FVECTOR3:
215 case Graphics::VertexInputFormat::FVECTOR4:
221 GLint GetGlType(Graphics::VertexInputFormat vertexFormat)
225 case Graphics::VertexInputFormat::UNDEFINED:
227 case Graphics::VertexInputFormat::INTEGER:
228 case Graphics::VertexInputFormat::IVECTOR2:
229 case Graphics::VertexInputFormat::IVECTOR3:
230 case Graphics::VertexInputFormat::IVECTOR4:
232 case Graphics::VertexInputFormat::FLOAT:
233 case Graphics::VertexInputFormat::FVECTOR2:
234 case Graphics::VertexInputFormat::FVECTOR3:
235 case Graphics::VertexInputFormat::FVECTOR4:
241 GLenum GetTopology(Graphics::PrimitiveTopology topology)
245 case Graphics::PrimitiveTopology::POINT_LIST:
248 case Graphics::PrimitiveTopology::LINE_LIST:
251 case Graphics::PrimitiveTopology::LINE_LOOP:
254 case Graphics::PrimitiveTopology::LINE_STRIP:
255 return GL_LINE_STRIP;
257 case Graphics::PrimitiveTopology::TRIANGLE_LIST:
260 case Graphics::PrimitiveTopology::TRIANGLE_STRIP:
261 return GL_TRIANGLE_STRIP;
263 case Graphics::PrimitiveTopology::TRIANGLE_FAN:
264 return GL_TRIANGLE_FAN;
269 GLenum GetCullFace(Graphics::CullMode cullMode)
273 case Graphics::CullMode::NONE:
275 case Graphics::CullMode::FRONT:
277 case Graphics::CullMode::BACK:
279 case Graphics::CullMode::FRONT_AND_BACK:
280 return GL_FRONT_AND_BACK;
285 GLenum GetFrontFace(Graphics::FrontFace frontFace)
287 if(frontFace == Graphics::FrontFace::CLOCKWISE)
294 GLenum GetBlendFactor(Graphics::BlendFactor blendFactor)
296 GLenum glFactor = GL_ZERO;
300 case Graphics::BlendFactor::ZERO:
303 case Graphics::BlendFactor::ONE:
306 case Graphics::BlendFactor::SRC_COLOR:
307 glFactor = GL_SRC_COLOR;
309 case Graphics::BlendFactor::ONE_MINUS_SRC_COLOR:
310 glFactor = GL_ONE_MINUS_SRC_COLOR;
312 case Graphics::BlendFactor::DST_COLOR:
313 glFactor = GL_DST_COLOR;
315 case Graphics::BlendFactor::ONE_MINUS_DST_COLOR:
316 glFactor = GL_ONE_MINUS_DST_COLOR;
318 case Graphics::BlendFactor::SRC_ALPHA:
319 glFactor = GL_SRC_ALPHA;
321 case Graphics::BlendFactor::ONE_MINUS_SRC_ALPHA:
322 glFactor = GL_ONE_MINUS_SRC_ALPHA;
324 case Graphics::BlendFactor::DST_ALPHA:
325 glFactor = GL_DST_ALPHA;
327 case Graphics::BlendFactor::ONE_MINUS_DST_ALPHA:
328 glFactor = GL_ONE_MINUS_DST_ALPHA;
330 case Graphics::BlendFactor::CONSTANT_COLOR:
331 glFactor = GL_CONSTANT_COLOR;
333 case Graphics::BlendFactor::ONE_MINUS_CONSTANT_COLOR:
334 glFactor = GL_ONE_MINUS_CONSTANT_COLOR;
336 case Graphics::BlendFactor::CONSTANT_ALPHA:
337 glFactor = GL_CONSTANT_ALPHA;
339 case Graphics::BlendFactor::ONE_MINUS_CONSTANT_ALPHA:
340 glFactor = GL_ONE_MINUS_CONSTANT_ALPHA;
342 case Graphics::BlendFactor::SRC_ALPHA_SATURATE:
343 glFactor = GL_SRC_ALPHA_SATURATE;
345 // GLES doesn't appear to have dual source blending.
346 case Graphics::BlendFactor::SRC1_COLOR:
347 glFactor = GL_SRC_COLOR;
349 case Graphics::BlendFactor::ONE_MINUS_SRC1_COLOR:
350 glFactor = GL_ONE_MINUS_SRC_COLOR;
352 case Graphics::BlendFactor::SRC1_ALPHA:
353 glFactor = GL_SRC_ALPHA;
355 case Graphics::BlendFactor::ONE_MINUS_SRC1_ALPHA:
356 glFactor = GL_ONE_MINUS_SRC_ALPHA;
362 GLenum GetBlendOp(Graphics::BlendOp blendOp)
364 GLenum op = GL_FUNC_ADD;
367 case Graphics::BlendOp::ADD:
370 case Graphics::BlendOp::SUBTRACT:
371 op = GL_FUNC_SUBTRACT;
373 case Graphics::BlendOp::REVERSE_SUBTRACT:
374 op = GL_FUNC_REVERSE_SUBTRACT;
376 case Graphics::BlendOp::MIN:
379 case Graphics::BlendOp::MAX:
382 case Graphics::BlendOp::MULTIPLY:
387 case Graphics::BlendOp::SCREEN:
392 case Graphics::BlendOp::OVERLAY:
397 case Graphics::BlendOp::DARKEN:
402 case Graphics::BlendOp::LIGHTEN:
407 case Graphics::BlendOp::COLOR_DODGE:
412 case Graphics::BlendOp::COLOR_BURN:
417 case Graphics::BlendOp::HARD_LIGHT:
422 case Graphics::BlendOp::SOFT_LIGHT:
427 case Graphics::BlendOp::DIFFERENCE:
432 case Graphics::BlendOp::EXCLUSION:
437 case Graphics::BlendOp::HUE:
442 case Graphics::BlendOp::SATURATION:
444 op = GL_HSL_SATURATION;
447 case Graphics::BlendOp::COLOR:
452 case Graphics::BlendOp::LUMINOSITY:
454 op = GL_HSL_LUMINOSITY;
463 constexpr explicit GLCompareOp(Graphics::CompareOp compareOp)
467 case Graphics::CompareOp::NEVER:
470 case Graphics::CompareOp::LESS:
473 case Graphics::CompareOp::EQUAL:
476 case Graphics::CompareOp::LESS_OR_EQUAL:
479 case Graphics::CompareOp::GREATER:
482 case Graphics::CompareOp::NOT_EQUAL:
485 case Graphics::CompareOp::GREATER_OR_EQUAL:
488 case Graphics::CompareOp::ALWAYS:
498 constexpr explicit GLStencilOp(Graphics::StencilOp stencilOp)
502 case Graphics::StencilOp::KEEP:
505 case Graphics::StencilOp::ZERO:
508 case Graphics::StencilOp::REPLACE:
511 case Graphics::StencilOp::INCREMENT_AND_CLAMP:
514 case Graphics::StencilOp::DECREMENT_AND_CLAMP:
517 case Graphics::StencilOp::INVERT:
520 case Graphics::StencilOp::INCREMENT_AND_WRAP:
523 case Graphics::StencilOp::DECREMENT_AND_WRAP:
531 class TestGraphicsMemory : public Graphics::Memory
534 TestGraphicsMemory(TraceCallStack& callStack, TestGraphicsBuffer& buffer, uint32_t mappedOffset, uint32_t mappedSize)
535 : mCallStack(callStack),
537 mMappedOffset(mappedOffset),
538 mMappedSize(mappedSize),
544 void* LockRegion(uint32_t offset, uint32_t size) override
546 std::ostringstream o;
547 o << offset << ", " << size;
548 mCallStack.PushCall("Memory::LockRegion", o.str());
550 if(offset > mMappedOffset + mMappedSize ||
551 size + offset > mMappedOffset + mMappedSize)
553 fprintf(stderr, "TestGraphics.Memory::LockRegion() Out of bounds");
554 mBuffer.memory.resize(mMappedOffset + offset + size); // Grow to prevent memcpy from crashing
556 mLockedOffset = offset;
558 return &mBuffer.memory[mMappedOffset + offset];
561 void Unlock(bool flush) override
563 mCallStack.PushCall("Memory::Unlock", (flush ? "Flush" : "NoFlush"));
570 void Flush() override
572 mCallStack.PushCall("Memory::Flush", "");
574 mBuffer.Upload(mMappedOffset + mLockedOffset, mLockedSize);
578 TraceCallStack& mCallStack;
579 TestGraphicsBuffer& mBuffer;
580 uint32_t mMappedOffset;
581 uint32_t mMappedSize;
582 uint32_t mLockedOffset;
583 uint32_t mLockedSize;
586 TestGraphicsController::TestGraphicsController()
587 : mCallStack(true, "TestGraphicsController."),
588 mCommandBufferCallStack(true, "TestCommandBuffer."),
589 mFrameBufferCallStack(true, "TestFrameBuffer.")
591 mCallStack.Enable(true);
592 mCommandBufferCallStack.Enable(true);
593 auto& trace = mGl.GetTextureTrace();
595 trace.EnableLogging(true);
598 void TestGraphicsController::SubmitCommandBuffers(const Graphics::SubmitInfo& submitInfo)
600 TraceCallStack::NamedParams namedParams;
601 namedParams["submitInfo"] << "cmdBuffer[" << submitInfo.cmdBuffer.size()
602 << "], flags:" << std::hex << submitInfo.flags;
604 mCallStack.PushCall("SubmitCommandBuffers", "", namedParams);
606 mSubmitStack.emplace_back(submitInfo);
608 for(auto& graphicsCommandBuffer : submitInfo.cmdBuffer)
610 auto commandBuffer = Uncast<TestGraphicsCommandBuffer>(graphicsCommandBuffer);
611 ProcessCommandBuffer(*commandBuffer);
615 void TestGraphicsController::ProcessCommandBuffer(TestGraphicsCommandBuffer& commandBuffer)
617 bool scissorEnabled = false;
618 TestGraphicsFramebuffer* currentFramebuffer{nullptr};
619 TestGraphicsPipeline* currentPipeline{nullptr};
621 for(auto& cmd : commandBuffer.GetCommands())
626 case CommandType::FLUSH:
628 // Nothing to do here
631 case CommandType::BIND_TEXTURES:
633 for(auto& binding : cmd.data.bindTextures.textureBindings)
637 auto texture = Uncast<TestGraphicsTexture>(binding.texture);
638 texture->Bind(binding.binding);
642 auto sampler = Uncast<TestGraphicsSampler>(binding.sampler);
645 sampler->Apply(texture->GetTarget());
649 texture->Prepare(); // Ensure native texture is ready
654 case CommandType::BIND_VERTEX_BUFFERS:
656 for(auto& binding : cmd.data.bindVertexBuffers.vertexBufferBindings)
658 auto graphicsBuffer = binding.buffer;
659 auto vertexBuffer = Uncast<TestGraphicsBuffer>(graphicsBuffer);
660 vertexBuffer->Bind();
664 case CommandType::BIND_INDEX_BUFFER:
666 auto& indexBufferBinding = cmd.data.bindIndexBuffer;
667 if(indexBufferBinding.buffer)
669 auto buffer = Uncast<TestGraphicsBuffer>(indexBufferBinding.buffer);
674 case CommandType::BIND_UNIFORM_BUFFER:
678 auto& bindings = cmd.data.bindUniformBuffers;
679 auto buffer = bindings.standaloneUniformsBufferBinding;
681 // based on reflection, issue gl calls
682 buffer.buffer->BindAsUniformBuffer(static_cast<const TestGraphicsProgram*>(currentPipeline->programState.program), bindings.standaloneUniformsBufferBinding);
686 case CommandType::BIND_SAMPLERS:
690 case CommandType::BIND_PIPELINE:
692 currentPipeline = Uncast<TestGraphicsPipeline>(cmd.data.bindPipeline.pipeline);
693 BindPipeline(currentPipeline);
696 case CommandType::DRAW:
700 mGl.DrawArrays(GetTopology(currentPipeline->inputAssemblyState.topology),
702 cmd.data.draw.draw.vertexCount);
706 case CommandType::DRAW_INDEXED:
710 mGl.DrawElements(GetTopology(currentPipeline->inputAssemblyState.topology),
711 static_cast<GLsizei>(cmd.data.draw.drawIndexed.indexCount),
713 reinterpret_cast<void*>(cmd.data.draw.drawIndexed.firstIndex));
717 case CommandType::DRAW_INDEXED_INDIRECT:
721 mGl.DrawElements(GetTopology(currentPipeline->inputAssemblyState.topology),
722 static_cast<GLsizei>(cmd.data.draw.drawIndexed.indexCount),
724 reinterpret_cast<void*>(cmd.data.draw.drawIndexed.firstIndex));
728 case CommandType::SET_SCISSOR:
732 auto& rect = cmd.data.scissor.region;
733 mGl.Scissor(rect.x, rect.y, rect.width, rect.height);
737 case CommandType::SET_SCISSOR_TEST:
739 if(cmd.data.scissorTest.enable)
741 mGl.Enable(GL_SCISSOR_TEST);
742 scissorEnabled = true;
746 mGl.Disable(GL_SCISSOR_TEST);
747 scissorEnabled = false;
751 case CommandType::SET_VIEWPORT_TEST:
755 case CommandType::SET_VIEWPORT: // @todo Consider correcting for orientation here?
757 auto& rect = cmd.data.viewport.region;
758 mGl.Viewport(rect.x, rect.y, rect.width, rect.height);
762 case CommandType::SET_COLOR_MASK:
764 // Set all channels to the same mask
765 const bool mask = cmd.data.colorMask.enabled;
766 mGl.ColorMask(mask, mask, mask, mask);
769 case CommandType::CLEAR_STENCIL_BUFFER:
771 mGl.Clear(GL_STENCIL_BUFFER_BIT);
774 case CommandType::CLEAR_DEPTH_BUFFER:
776 mGl.Clear(GL_DEPTH_BUFFER_BIT);
780 case CommandType::SET_STENCIL_TEST_ENABLE:
782 if(cmd.data.stencilTest.enabled)
784 mGl.Enable(GL_STENCIL_TEST);
788 mGl.Disable(GL_STENCIL_TEST);
793 case CommandType::SET_STENCIL_FUNC:
795 mGl.StencilFunc(GLCompareOp(cmd.data.stencilFunc.compareOp).op,
796 cmd.data.stencilFunc.reference,
797 cmd.data.stencilFunc.compareMask);
801 case CommandType::SET_STENCIL_WRITE_MASK:
803 mGl.StencilMask(cmd.data.stencilWriteMask.mask);
806 case CommandType::SET_STENCIL_OP:
808 mGl.StencilOp(GLStencilOp(cmd.data.stencilOp.failOp).op,
809 GLStencilOp(cmd.data.stencilOp.depthFailOp).op,
810 GLStencilOp(cmd.data.stencilOp.passOp).op);
814 case CommandType::SET_DEPTH_COMPARE_OP:
816 mGl.DepthFunc(GLCompareOp(cmd.data.depth.compareOp).op);
819 case CommandType::SET_DEPTH_TEST_ENABLE:
821 if(cmd.data.depth.testEnabled)
823 mGl.Enable(GL_DEPTH_TEST);
827 mGl.Disable(GL_DEPTH_TEST);
831 case CommandType::SET_DEPTH_WRITE_ENABLE:
833 mGl.DepthMask(cmd.data.depth.writeEnabled);
837 case CommandType::EXECUTE_COMMAND_BUFFERS:
839 // Process secondary command buffers
840 for(auto& buf : cmd.data.executeCommandBuffers.buffers)
842 ProcessCommandBuffer(*Uncast<TestGraphicsCommandBuffer>(buf));
846 case CommandType::BEGIN_RENDER_PASS:
848 auto renderTarget = Uncast<TestGraphicsRenderTarget>(cmd.data.beginRenderPass.renderTarget);
852 auto fb = renderTarget->mCreateInfo.framebuffer;
855 if(currentFramebuffer != fb)
857 currentFramebuffer = Uncast<TestGraphicsFramebuffer>(fb);
858 currentFramebuffer->Bind();
863 mGl.BindFramebuffer(GL_FRAMEBUFFER, 0);
868 mGl.BindFramebuffer(GL_FRAMEBUFFER, 0);
871 auto& clearValues = cmd.data.beginRenderPass.clearValues;
872 if(clearValues.size() > 0)
874 const auto renderPass = static_cast<TestGraphicsRenderPass*>(cmd.data.beginRenderPass.renderPass);
877 const auto& color0 = renderPass->attachments[0];
879 if(color0.loadOp == Graphics::AttachmentLoadOp::CLEAR)
881 mask |= GL_COLOR_BUFFER_BIT;
883 // Set clear color (todo: cache it!)
884 // Something goes wrong here if Alpha mask is GL_TRUE
885 mGl.ColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);
886 mGl.ClearColor(clearValues[0].color.r,
887 clearValues[0].color.g,
888 clearValues[0].color.b,
889 clearValues[0].color.a);
892 // check for depth stencil
893 if(renderPass->attachments.size() > 1)
895 const auto& depthStencil = renderPass->attachments.back();
896 if(depthStencil.loadOp == Graphics::AttachmentLoadOp::CLEAR)
899 uint32_t depthClearColor = 0u;
900 if(clearValues.size() == renderPass->attachments.size())
902 depthClearColor = clearValues.back().depthStencil.depth;
904 mGl.ClearDepthf(depthClearColor);
905 mask |= GL_DEPTH_BUFFER_BIT;
907 if(depthStencil.stencilLoadOp == Graphics::AttachmentLoadOp::CLEAR)
909 uint32_t stencilClearColor = 0u;
910 if(clearValues.size() == renderPass->attachments.size())
912 stencilClearColor = clearValues.back().depthStencil.stencil;
914 mGl.ClearStencil(stencilClearColor);
915 mGl.StencilMask(0xFF); // Clear all the bitplanes (assume 8)
916 mask |= GL_STENCIL_BUFFER_BIT;
922 // Test scissor area and RT size
923 const auto& area = cmd.data.beginRenderPass.renderArea;
927 area.width == renderTarget->mCreateInfo.extent.width &&
928 area.height == renderTarget->mCreateInfo.extent.height)
930 mGl.Disable(GL_SCISSOR_TEST);
935 mGl.Enable(GL_SCISSOR_TEST);
936 mGl.Scissor(cmd.data.beginRenderPass.renderArea.x, cmd.data.beginRenderPass.renderArea.y, cmd.data.beginRenderPass.renderArea.width, cmd.data.beginRenderPass.renderArea.height);
938 mGl.Disable(GL_SCISSOR_TEST);
944 DALI_ASSERT_DEBUG(0 && "BeginRenderPass has no render pass");
949 case CommandType::END_RENDER_PASS:
951 if(cmd.data.endRenderPass.syncObject != nullptr)
953 auto syncObject = Uncast<TestGraphicsSyncObject>(cmd.data.endRenderPass.syncObject);
954 syncObject->InitializeResource(); // create the sync object.
962 void TestGraphicsController::BindPipeline(TestGraphicsPipeline* pipeline)
964 auto& vi = pipeline->vertexInputState;
965 for(auto& attribute : vi.attributes)
967 mGl.EnableVertexAttribArray(attribute.location);
968 uint32_t attributeOffset = attribute.offset;
969 GLsizei stride = vi.bufferBindings[attribute.binding].stride;
971 mGl.VertexAttribPointer(attribute.location,
972 GetNumComponents(attribute.format),
973 GetGlType(attribute.format),
974 GL_FALSE, // Not normalized
976 reinterpret_cast<void*>(attributeOffset));
980 auto& rasterizationState = pipeline->rasterizationState;
981 if(rasterizationState.cullMode == Graphics::CullMode::NONE)
983 mGl.Disable(GL_CULL_FACE);
987 mGl.Enable(GL_CULL_FACE);
988 mGl.CullFace(GetCullFace(rasterizationState.cullMode));
991 mGl.FrontFace(GetFrontFace(rasterizationState.frontFace));
994 auto& colorBlendState = pipeline->colorBlendState;
995 if(colorBlendState.blendEnable)
997 mGl.Enable(GL_BLEND);
999 mGl.BlendFuncSeparate(GetBlendFactor(colorBlendState.srcColorBlendFactor),
1000 GetBlendFactor(colorBlendState.dstColorBlendFactor),
1001 GetBlendFactor(colorBlendState.srcAlphaBlendFactor),
1002 GetBlendFactor(colorBlendState.dstAlphaBlendFactor));
1003 if(colorBlendState.colorBlendOp != colorBlendState.alphaBlendOp)
1005 mGl.BlendEquationSeparate(GetBlendOp(colorBlendState.colorBlendOp), GetBlendOp(colorBlendState.alphaBlendOp));
1009 mGl.BlendEquation(GetBlendOp(colorBlendState.colorBlendOp));
1011 mGl.BlendColor(colorBlendState.blendConstants[0],
1012 colorBlendState.blendConstants[1],
1013 colorBlendState.blendConstants[2],
1014 colorBlendState.blendConstants[3]);
1018 mGl.Disable(GL_BLEND);
1021 auto* program = static_cast<const TestGraphicsProgram*>(pipeline->programState.program);
1022 mGl.UseProgram(program->mImpl->mId);
1026 * @brief Presents render target
1027 * @param renderTarget render target to present
1029 void TestGraphicsController::PresentRenderTarget(Graphics::RenderTarget* renderTarget)
1031 auto* rt = static_cast<const TestGraphicsRenderTarget*>(renderTarget);
1032 TraceCallStack::NamedParams namedParams;
1033 namedParams["renderTarget"] << std::hex << renderTarget;
1034 namedParams["surface"] << std::hex << rt->mCreateInfo.surface;
1035 mCallStack.PushCall("PresentRenderTarget", namedParams.str(), namedParams);
1039 * @brief Waits until the GPU is idle
1041 void TestGraphicsController::WaitIdle()
1043 mCallStack.PushCall("WaitIdle", "");
1047 * @brief Lifecycle pause event
1049 void TestGraphicsController::Pause()
1051 mCallStack.PushCall("Pause", "");
1055 * @brief Lifecycle resume event
1057 void TestGraphicsController::Resume()
1059 mCallStack.PushCall("Resume", "");
1062 void TestGraphicsController::Shutdown()
1064 mCallStack.PushCall("Shutdown", "");
1067 void TestGraphicsController::Destroy()
1069 mCallStack.PushCall("Destroy", "");
1072 void TestGraphicsController::UpdateTextures(const std::vector<Graphics::TextureUpdateInfo>& updateInfoList,
1073 const std::vector<Graphics::TextureUpdateSourceInfo>& sourceList)
1075 TraceCallStack::NamedParams namedParams;
1076 namedParams["updateInfoList"] << "[" << updateInfoList.size() << "]:";
1077 namedParams["sourceList"] << "[" << sourceList.size() << "]:";
1079 mCallStack.PushCall("UpdateTextures", "", namedParams);
1081 // Call either TexImage2D or TexSubImage2D
1082 for(unsigned int i = 0; i < updateInfoList.size(); ++i)
1084 auto& updateInfo = updateInfoList[i];
1085 auto& source = sourceList[i];
1087 auto texture = static_cast<TestGraphicsTexture*>(updateInfo.dstTexture);
1088 texture->Bind(0); // Use first texture unit during resource update
1089 texture->Update(updateInfo, source);
1093 void TestGraphicsController::GenerateTextureMipmaps(const Graphics::Texture& texture)
1095 mCallStack.PushCall("GenerateTextureMipmaps", "");
1097 auto gfxTexture = Uncast<TestGraphicsTexture>(&texture);
1098 mGl.BindTexture(gfxTexture->GetTarget(), 0);
1099 mGl.GenerateMipmap(gfxTexture->GetTarget());
1102 bool TestGraphicsController::EnableDepthStencilBuffer(bool enableDepth, bool enableStencil)
1104 TraceCallStack::NamedParams namedParams;
1105 namedParams["enableDepth"] << (enableDepth ? "T" : "F");
1106 namedParams["enableStencil"] << (enableStencil ? "T" : "F");
1107 mCallStack.PushCall("EnableDepthStencilBuffer", "", namedParams);
1111 void TestGraphicsController::RunGarbageCollector(size_t numberOfDiscardedRenderers)
1113 TraceCallStack::NamedParams namedParams;
1114 namedParams["numberOfDiscardedRenderers"] << numberOfDiscardedRenderers;
1115 mCallStack.PushCall("RunGarbageCollector", "", namedParams);
1118 void TestGraphicsController::DiscardUnusedResources()
1120 mCallStack.PushCall("DiscardUnusedResources", "");
1123 bool TestGraphicsController::IsDiscardQueueEmpty()
1125 mCallStack.PushCall("IsDiscardQueueEmpty", "");
1126 return isDiscardQueueEmptyResult;
1130 * @brief Test if the graphics subsystem has resumed & should force a draw
1132 * @return true if the graphics subsystem requires a re-draw
1134 bool TestGraphicsController::IsDrawOnResumeRequired()
1136 mCallStack.PushCall("IsDrawOnResumeRequired", "");
1137 return isDrawOnResumeRequiredResult;
1140 Graphics::UniquePtr<Graphics::Buffer> TestGraphicsController::CreateBuffer(const Graphics::BufferCreateInfo& createInfo, Graphics::UniquePtr<Graphics::Buffer>&& oldBuffer)
1142 std::ostringstream oss;
1143 oss << "bufferCreateInfo:" << createInfo;
1144 mCallStack.PushCall("CreateBuffer", oss.str());
1145 return Graphics::MakeUnique<TestGraphicsBuffer>(mCallStack, mGl, createInfo.size, createInfo.usage);
1148 Graphics::UniquePtr<Graphics::CommandBuffer> TestGraphicsController::CreateCommandBuffer(const Graphics::CommandBufferCreateInfo& commandBufferCreateInfo, Graphics::UniquePtr<Graphics::CommandBuffer>&& oldCommandBuffer)
1150 std::ostringstream oss;
1151 oss << "commandBufferCreateInfo:" << commandBufferCreateInfo;
1152 mCallStack.PushCall("CreateCommandBuffer", oss.str());
1153 return Graphics::MakeUnique<TestGraphicsCommandBuffer>(mCommandBufferCallStack, mGl);
1156 Graphics::UniquePtr<Graphics::RenderPass> TestGraphicsController::CreateRenderPass(const Graphics::RenderPassCreateInfo& renderPassCreateInfo, Graphics::UniquePtr<Graphics::RenderPass>&& oldRenderPass)
1158 mCallStack.PushCall("CreateRenderPass", "");
1159 return Graphics::MakeUnique<TestGraphicsRenderPass>(mGl, renderPassCreateInfo);
1162 Graphics::UniquePtr<Graphics::Texture> TestGraphicsController::CreateTexture(const Graphics::TextureCreateInfo& textureCreateInfo, Graphics::UniquePtr<Graphics::Texture>&& oldTexture)
1164 TraceCallStack::NamedParams namedParams;
1165 namedParams["textureCreateInfo"] << textureCreateInfo;
1166 mCallStack.PushCall("CreateTexture", namedParams.str(), namedParams);
1168 return Graphics::MakeUnique<TestGraphicsTexture>(mGl, textureCreateInfo);
1171 Graphics::UniquePtr<Graphics::Framebuffer> TestGraphicsController::CreateFramebuffer(
1172 const Graphics::FramebufferCreateInfo& createInfo,
1173 Graphics::UniquePtr<Graphics::Framebuffer>&& oldFramebuffer)
1175 TraceCallStack::NamedParams namedParams;
1176 namedParams["framebufferCreateInfo"] << createInfo;
1177 mCallStack.PushCall("Controller::CreateFramebuffer", namedParams.str(), namedParams);
1179 return Graphics::MakeUnique<TestGraphicsFramebuffer>(mFrameBufferCallStack, mGl, createInfo);
1182 Graphics::UniquePtr<Graphics::Pipeline> TestGraphicsController::CreatePipeline(const Graphics::PipelineCreateInfo& pipelineCreateInfo, Graphics::UniquePtr<Graphics::Pipeline>&& oldPipeline)
1184 mCallStack.PushCall("CreatePipeline", "");
1185 return std::make_unique<TestGraphicsPipeline>(mGl, pipelineCreateInfo);
1188 Graphics::UniquePtr<Graphics::Program> TestGraphicsController::CreateProgram(const Graphics::ProgramCreateInfo& programCreateInfo, Graphics::UniquePtr<Graphics::Program>&& oldProgram)
1190 mCallStack.PushCall("CreateProgram", "");
1192 for(auto cacheEntry : mProgramCache)
1195 for(auto& shader : *(programCreateInfo.shaderState))
1197 auto graphicsShader = Uncast<TestGraphicsShader>(shader.shader);
1198 std::vector<uint8_t> source;
1199 source.resize(graphicsShader->mCreateInfo.sourceSize);
1200 memcpy(&source[0], graphicsShader->mCreateInfo.sourceData, graphicsShader->mCreateInfo.sourceSize);
1202 if(!std::equal(source.begin(), source.end(), cacheEntry.shaders[shader.pipelineStage].begin()))
1210 return Graphics::MakeUnique<TestGraphicsProgram>(cacheEntry.programImpl);
1214 mProgramCache.emplace_back();
1215 mProgramCache.back().programImpl = new TestGraphicsProgramImpl(mGl, programCreateInfo, mVertexFormats, mCustomUniforms);
1216 for(auto& shader : *(programCreateInfo.shaderState))
1218 auto graphicsShader = Uncast<TestGraphicsShader>(shader.shader);
1219 mProgramCache.back().shaders[shader.pipelineStage].resize(graphicsShader->mCreateInfo.sourceSize);
1220 memcpy(&mProgramCache.back().shaders[shader.pipelineStage][0], graphicsShader->mCreateInfo.sourceData, graphicsShader->mCreateInfo.sourceSize);
1222 return Graphics::MakeUnique<TestGraphicsProgram>(mProgramCache.back().programImpl);
1225 Graphics::UniquePtr<Graphics::Shader> TestGraphicsController::CreateShader(const Graphics::ShaderCreateInfo& shaderCreateInfo, Graphics::UniquePtr<Graphics::Shader>&& oldShader)
1227 mCallStack.PushCall("CreateShader", "");
1228 return Graphics::MakeUnique<TestGraphicsShader>(mGl, shaderCreateInfo);
1231 Graphics::UniquePtr<Graphics::Sampler> TestGraphicsController::CreateSampler(const Graphics::SamplerCreateInfo& samplerCreateInfo, Graphics::UniquePtr<Graphics::Sampler>&& oldSampler)
1233 TraceCallStack::NamedParams namedParams;
1234 namedParams["samplerCreateInfo"] << samplerCreateInfo;
1235 mCallStack.PushCall("CreateSampler", namedParams.str(), namedParams);
1237 return Graphics::MakeUnique<TestGraphicsSampler>(mGl, samplerCreateInfo);
1240 Graphics::UniquePtr<Graphics::RenderTarget> TestGraphicsController::CreateRenderTarget(const Graphics::RenderTargetCreateInfo& renderTargetCreateInfo, Graphics::UniquePtr<Graphics::RenderTarget>&& oldRenderTarget)
1242 TraceCallStack::NamedParams namedParams;
1243 namedParams["surface"] << std::hex << renderTargetCreateInfo.surface;
1244 mCallStack.PushCall("CreateRenderTarget", namedParams.str(), namedParams);
1246 return Graphics::MakeUnique<TestGraphicsRenderTarget>(mGl, renderTargetCreateInfo);
1249 Graphics::UniquePtr<Graphics::SyncObject> TestGraphicsController::CreateSyncObject(
1250 const Graphics::SyncObjectCreateInfo& syncObjectCreateInfo,
1251 Graphics::UniquePtr<Graphics::SyncObject>&& oldSyncObject)
1253 mCallStack.PushCall("CreateSyncObject", "");
1254 return Graphics::MakeUnique<TestGraphicsSyncObject>(mGraphicsSyncImpl, syncObjectCreateInfo);
1257 Graphics::UniquePtr<Graphics::Memory> TestGraphicsController::MapBufferRange(const Graphics::MapBufferInfo& mapInfo)
1259 mCallStack.PushCall("MapBufferRange", "");
1261 auto buffer = static_cast<TestGraphicsBuffer*>(mapInfo.buffer);
1262 buffer->memory.resize(mapInfo.offset + mapInfo.size); // For initial testing, allow writes past capacity
1264 return std::make_unique<TestGraphicsMemory>(mCallStack, *buffer, mapInfo.offset, mapInfo.size);
1267 Graphics::UniquePtr<Graphics::Memory> TestGraphicsController::MapTextureRange(const Graphics::MapTextureInfo& mapInfo)
1269 mCallStack.PushCall("MapTextureRange", "");
1273 void TestGraphicsController::UnmapMemory(Graphics::UniquePtr<Graphics::Memory> memory)
1275 mCallStack.PushCall("UnmapMemory", "");
1278 Graphics::MemoryRequirements TestGraphicsController::GetTextureMemoryRequirements(Graphics::Texture& texture) const
1280 mCallStack.PushCall("GetTextureMemoryRequirements", "");
1281 return Graphics::MemoryRequirements{};
1284 Graphics::MemoryRequirements TestGraphicsController::GetBufferMemoryRequirements(Graphics::Buffer& buffer) const
1286 mCallStack.PushCall("GetBufferMemoryRequirements", "");
1287 return Graphics::MemoryRequirements{};
1290 const Graphics::TextureProperties& TestGraphicsController::GetTextureProperties(const Graphics::Texture& texture)
1292 static Graphics::TextureProperties textureProperties{};
1293 mCallStack.PushCall("GetTextureProperties", "");
1295 return textureProperties;
1298 const Graphics::Reflection& TestGraphicsController::GetProgramReflection(const Graphics::Program& program)
1300 mCallStack.PushCall("GetProgramReflection", "");
1302 return static_cast<const TestGraphicsProgram*>(&program)->GetReflection();
1305 bool TestGraphicsController::PipelineEquals(const Graphics::Pipeline& pipeline0, const Graphics::Pipeline& pipeline1) const
1307 mCallStack.PushCall("PipelineEquals", "");
1311 bool TestGraphicsController::GetProgramParameter(Graphics::Program& program, uint32_t parameterId, void* outData)
1313 mCallStack.PushCall("GetProgramParameter", "");
1314 auto graphicsProgram = Uncast<TestGraphicsProgram>(&program);
1315 return graphicsProgram->GetParameter(parameterId, outData);