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-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-texture.h"
29 #include <dali/integration-api/gl-defines.h>
36 std::ostream& operator<<(std::ostream& o, const Graphics::BufferCreateInfo& bufferCreateInfo)
38 return o << "usage:" << std::hex << bufferCreateInfo.usage << ", size:" << std::dec << bufferCreateInfo.size;
41 std::ostream& operator<<(std::ostream& o, const Graphics::CommandBufferCreateInfo& commandBufferCreateInfo)
43 return o << "level:" << (commandBufferCreateInfo.level == Graphics::CommandBufferLevel::PRIMARY ? "PRIMARY" : "SECONDARY")
44 << ", fixedCapacity:" << std::dec << commandBufferCreateInfo.fixedCapacity;
47 std::ostream& operator<<(std::ostream& o, const Graphics::TextureType& textureType)
51 case Graphics::TextureType::TEXTURE_2D:
54 case Graphics::TextureType::TEXTURE_3D:
57 case Graphics::TextureType::TEXTURE_CUBEMAP:
58 o << "TEXTURE_CUBEMAP";
64 std::ostream& operator<<(std::ostream& o, const Graphics::Extent2D extent)
66 o << "width:" << extent.width << ", height:" << extent.height;
70 std::ostream& operator<<(std::ostream& o, const Graphics::TextureCreateInfo& createInfo)
72 o << "textureType:" << createInfo.textureType
73 << " size:" << createInfo.size
74 << " format:" << static_cast<uint32_t>(createInfo.format)
75 << " mipMapFlag:" << createInfo.mipMapFlag
76 << " layout:" << (createInfo.layout == Graphics::TextureLayout::LINEAR ? "LINEAR" : "OPTIMAL")
77 << " usageFlags:" << std::hex << createInfo.usageFlags
78 << " data:" << std::hex << createInfo.data
79 << " dataSize:" << std::dec << createInfo.dataSize
80 << " nativeImagePtr:" << std::hex << createInfo.nativeImagePtr;
84 std::ostream& operator<<(std::ostream& o, Graphics::SamplerAddressMode addressMode)
88 case Graphics::SamplerAddressMode::REPEAT:
91 case Graphics::SamplerAddressMode::MIRRORED_REPEAT:
92 o << "MIRRORED_REPEAT";
94 case Graphics::SamplerAddressMode::CLAMP_TO_EDGE:
97 case Graphics::SamplerAddressMode::CLAMP_TO_BORDER:
98 o << "CLAMP_TO_BORDER";
100 case Graphics::SamplerAddressMode::MIRROR_CLAMP_TO_EDGE:
101 o << "MIRROR_CLAMP_TO_EDGE";
107 std::ostream& operator<<(std::ostream& o, Graphics::SamplerFilter filterMode)
111 case Graphics::SamplerFilter::LINEAR:
114 case Graphics::SamplerFilter::NEAREST:
121 std::ostream& operator<<(std::ostream& o, Graphics::SamplerMipmapMode mipmapMode)
125 case Graphics::SamplerMipmapMode::NONE:
128 case Graphics::SamplerMipmapMode::LINEAR:
131 case Graphics::SamplerMipmapMode::NEAREST:
138 std::ostream& operator<<(std::ostream& o, const Graphics::SamplerCreateInfo& createInfo)
140 o << "minFilter:" << createInfo.minFilter
141 << " magFilter:" << createInfo.magFilter
142 << " wrapModeU:" << createInfo.addressModeU
143 << " wrapModeV:" << createInfo.addressModeV
144 << " wrapModeW:" << createInfo.addressModeW
145 << " mipMapMode:" << createInfo.mipMapMode;
149 std::ostream& operator<<(std::ostream& o, const Graphics::ColorAttachment& colorAttachment)
151 o << "attachmentId:" << colorAttachment.attachmentId
152 << " layerId:" << colorAttachment.layerId
153 << " levelId:" << colorAttachment.levelId
154 << " texture:" << colorAttachment.texture;
158 std::ostream& operator<<(std::ostream& o, const Graphics::DepthStencilAttachment& depthStencilAttachment)
160 o << "depthTexture:" << depthStencilAttachment.depthTexture
161 << "depthLevel:" << depthStencilAttachment.depthLevel
162 << "stencilTexture:" << depthStencilAttachment.stencilTexture
163 << "stencilLevel:" << depthStencilAttachment.stencilLevel;
167 std::ostream& operator<<(std::ostream& o, const Graphics::FramebufferCreateInfo& createInfo)
169 o << "colorAttachments:";
170 for(auto i = 0u; i < createInfo.colorAttachments.size(); ++i)
172 o << "[" << i << "]=" << createInfo.colorAttachments[i] << " ";
174 o << "depthStencilAttachment:" << createInfo.depthStencilAttachment;
175 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:
383 // @todo Add advanced blend equations
389 class TestGraphicsMemory : public Graphics::Memory
392 TestGraphicsMemory(TraceCallStack& callStack, TestGraphicsBuffer& buffer, uint32_t mappedOffset, uint32_t mappedSize)
393 : mCallStack(callStack),
395 mMappedOffset(mappedOffset),
396 mMappedSize(mappedSize),
402 void* LockRegion(uint32_t offset, uint32_t size) override
404 std::ostringstream o;
405 o << offset << ", " << size;
406 mCallStack.PushCall("Memory::LockRegion", o.str());
408 if(offset > mMappedOffset + mMappedSize ||
409 size + offset > mMappedOffset + mMappedSize)
411 fprintf(stderr, "TestGraphics.Memory::LockRegion() Out of bounds");
412 mBuffer.memory.resize(mMappedOffset + offset + size); // Grow to prevent memcpy from crashing
414 mLockedOffset = offset;
416 return &mBuffer.memory[mMappedOffset + offset];
419 void Unlock(bool flush) override
421 mCallStack.PushCall("Memory::Unlock", (flush ? "Flush" : "NoFlush"));
428 void Flush() override
430 mCallStack.PushCall("Memory::Flush", "");
432 mBuffer.Upload(mMappedOffset + mLockedOffset, mLockedSize);
436 TraceCallStack& mCallStack;
437 TestGraphicsBuffer& mBuffer;
438 uint32_t mMappedOffset;
439 uint32_t mMappedSize;
440 uint32_t mLockedOffset;
441 uint32_t mLockedSize;
444 TestGraphicsController::TestGraphicsController()
445 : mCallStack(true, "TestGraphicsController."),
446 mCommandBufferCallStack(true, "TestCommandBuffer."),
447 mFrameBufferCallStack(true, "TestFrameBuffer.")
449 mCallStack.Enable(true);
450 mCommandBufferCallStack.Enable(true);
451 auto& trace = mGl.GetTextureTrace();
453 trace.EnableLogging(true);
457 void TestGraphicsController::SubmitCommandBuffers(const Graphics::SubmitInfo& submitInfo)
459 TraceCallStack::NamedParams namedParams;
460 namedParams["submitInfo"] << "cmdBuffer[" << submitInfo.cmdBuffer.size()
461 << "], flags:" << std::hex << submitInfo.flags;
463 mCallStack.PushCall("SubmitCommandBuffers", "", namedParams);
465 mSubmitStack.emplace_back(submitInfo);
467 for(auto& graphicsCommandBuffer : submitInfo.cmdBuffer)
469 auto commandBuffer = Uncast<TestGraphicsCommandBuffer>(graphicsCommandBuffer);
470 ProcessCommandBuffer(*commandBuffer);
474 void TestGraphicsController::ProcessCommandBuffer(TestGraphicsCommandBuffer& commandBuffer)
476 bool scissorEnabled = false;
477 TestGraphicsFramebuffer* currentFramebuffer{nullptr};
478 TestGraphicsPipeline* currentPipeline{nullptr};
480 for(auto& cmd : commandBuffer.GetCommands())
485 case CommandType::FLUSH:
487 // Nothing to do here
490 case CommandType::BIND_TEXTURES:
492 for(auto& binding : cmd.data.bindTextures.textureBindings)
496 auto texture = Uncast<TestGraphicsTexture>(binding.texture);
497 texture->Bind(binding.binding);
501 auto sampler = Uncast<TestGraphicsSampler>(binding.sampler);
504 sampler->Apply(texture->GetTarget());
508 texture->Prepare(); // Ensure native texture is ready
513 case CommandType::BIND_VERTEX_BUFFERS:
515 for(auto& binding : cmd.data.bindVertexBuffers.vertexBufferBindings)
517 auto graphicsBuffer = binding.buffer;
518 auto vertexBuffer = Uncast<TestGraphicsBuffer>(graphicsBuffer);
519 vertexBuffer->Bind();
523 case CommandType::BIND_INDEX_BUFFER:
525 auto& indexBufferBinding = cmd.data.bindIndexBuffer;
526 if(indexBufferBinding.buffer)
528 auto buffer = Uncast<TestGraphicsBuffer>(indexBufferBinding.buffer);
533 case CommandType::BIND_UNIFORM_BUFFER:
535 auto& bindings = cmd.data.bindUniformBuffers;
536 auto buffer = bindings.standaloneUniformsBufferBinding;
538 // based on reflection, issue gl calls
539 buffer.buffer->BindAsUniformBuffer(static_cast<const TestGraphicsProgram*>(currentPipeline->programState.program));
542 case CommandType::BIND_SAMPLERS:
546 case CommandType::BIND_PIPELINE:
548 currentPipeline = Uncast<TestGraphicsPipeline>(cmd.data.bindPipeline.pipeline);
550 // Bind framebuffer if different. @todo Move to RenderPass
551 auto framebuffer = currentPipeline->framebufferState.framebuffer;
552 if(framebuffer && framebuffer != currentFramebuffer)
554 auto graphicsFramebuffer = Uncast<TestGraphicsFramebuffer>(framebuffer);
555 graphicsFramebuffer->Bind();
559 if(currentFramebuffer)
560 currentFramebuffer->Bind();
562 mGl.BindFramebuffer(GL_FRAMEBUFFER, 0);
564 BindPipeline(currentPipeline);
567 case CommandType::DRAW:
569 mGl.DrawArrays(GetTopology(currentPipeline->inputAssemblyState.topology),
571 cmd.data.draw.draw.vertexCount);
574 case CommandType::DRAW_INDEXED:
576 mGl.DrawElements(GetTopology(currentPipeline->inputAssemblyState.topology),
577 static_cast<GLsizei>(cmd.data.draw.drawIndexed.indexCount),
579 reinterpret_cast<void*>(cmd.data.draw.drawIndexed.firstIndex));
582 case CommandType::DRAW_INDEXED_INDIRECT:
584 mGl.DrawElements(GetTopology(currentPipeline->inputAssemblyState.topology),
585 static_cast<GLsizei>(cmd.data.draw.drawIndexed.indexCount),
587 reinterpret_cast<void*>(cmd.data.draw.drawIndexed.firstIndex));
590 case CommandType::SET_SCISSOR:
594 auto& rect = cmd.data.scissor.region;
595 mGl.Scissor(rect.x, rect.y, rect.width, rect.height);
599 case CommandType::SET_SCISSOR_TEST:
601 if(cmd.data.scissorTest.enable)
603 mGl.Enable(GL_SCISSOR_TEST);
604 scissorEnabled = true;
608 mGl.Disable(GL_SCISSOR_TEST);
609 scissorEnabled = false;
613 case CommandType::SET_VIEWPORT_TEST:
617 case CommandType::SET_VIEWPORT: // @todo Consider correcting for orientation here?
619 auto& rect = cmd.data.viewport.region;
620 mGl.Viewport(rect.x, rect.y, rect.width, rect.height);
623 case CommandType::EXECUTE_COMMAND_BUFFERS:
625 // Process secondary command buffers
626 for(auto& buf : cmd.data.executeCommandBuffers.buffers)
628 ProcessCommandBuffer(*static_cast<TestGraphicsCommandBuffer*>(buf));
632 case CommandType::BEGIN_RENDER_PASS:
634 auto renderTarget = Uncast<TestGraphicsRenderTarget>(cmd.data.beginRenderPass.renderTarget);
638 auto fb = renderTarget->mCreateInfo.framebuffer;
641 if(currentFramebuffer != fb)
643 currentFramebuffer = Uncast<TestGraphicsFramebuffer>(fb);
644 currentFramebuffer->Bind();
649 mGl.BindFramebuffer(GL_FRAMEBUFFER, 0);
654 mGl.BindFramebuffer(GL_FRAMEBUFFER, 0);
657 auto& clearValues = cmd.data.beginRenderPass.clearValues;
658 if(clearValues.size() > 0)
660 const auto renderPass = static_cast<TestGraphicsRenderPass*>(cmd.data.beginRenderPass.renderPass);
663 const auto& color0 = renderPass->attachments[0];
665 if(color0.loadOp == Graphics::AttachmentLoadOp::CLEAR)
667 mask |= GL_COLOR_BUFFER_BIT;
669 // Set clear color (todo: cache it!)
670 // Something goes wrong here if Alpha mask is GL_TRUE
671 mGl.ColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);
672 mGl.ClearColor(clearValues[0].color.r,
673 clearValues[0].color.g,
674 clearValues[0].color.b,
675 clearValues[0].color.a);
678 // check for depth stencil
679 if(renderPass->attachments.size() > 1)
681 const auto& depthStencil = renderPass->attachments.back();
682 if(depthStencil.loadOp == Graphics::AttachmentLoadOp::CLEAR)
684 mask |= GL_DEPTH_BUFFER_BIT;
686 if(depthStencil.stencilLoadOp == Graphics::AttachmentLoadOp::CLEAR)
688 mask |= GL_STENCIL_BUFFER_BIT;
694 // Test scissor area and RT size
695 const auto& area = cmd.data.beginRenderPass.renderArea;
698 area.width == renderTarget->mCreateInfo.extent.width &&
699 area.height == renderTarget->mCreateInfo.extent.height )
701 mGl.Disable(GL_SCISSOR_TEST);
706 mGl.Enable(GL_SCISSOR_TEST);
707 mGl.Scissor(cmd.data.beginRenderPass.renderArea.x, cmd.data.beginRenderPass.renderArea.y,
708 cmd.data.beginRenderPass.renderArea.width, cmd.data.beginRenderPass.renderArea.height);
710 mGl.Disable(GL_SCISSOR_TEST);
716 DALI_ASSERT_DEBUG(0 && "BeginRenderPass has no render pass");
721 case CommandType::END_RENDER_PASS:
729 void TestGraphicsController::BindPipeline(TestGraphicsPipeline* pipeline)
731 auto& vi = pipeline->vertexInputState;
732 for(auto& attribute : vi.attributes)
734 mGl.EnableVertexAttribArray(attribute.location);
735 uint32_t attributeOffset = attribute.offset;
736 GLsizei stride = vi.bufferBindings[attribute.binding].stride;
738 mGl.VertexAttribPointer(attribute.location,
739 GetNumComponents(attribute.format),
740 GetGlType(attribute.format),
741 GL_FALSE, // Not normalized
743 reinterpret_cast<void*>(attributeOffset));
747 auto& rasterizationState = pipeline->rasterizationState;
748 if(rasterizationState.cullMode == Graphics::CullMode::NONE)
750 mGl.Disable(GL_CULL_FACE);
754 mGl.Enable(GL_CULL_FACE);
755 mGl.CullFace(GetCullFace(rasterizationState.cullMode));
758 mGl.FrontFace(GetFrontFace(rasterizationState.frontFace));
761 auto& colorBlendState = pipeline->colorBlendState;
762 if(colorBlendState.blendEnable)
764 mGl.Enable(GL_BLEND);
766 mGl.BlendFuncSeparate(GetBlendFactor(colorBlendState.srcColorBlendFactor),
767 GetBlendFactor(colorBlendState.dstColorBlendFactor),
768 GetBlendFactor(colorBlendState.srcAlphaBlendFactor),
769 GetBlendFactor(colorBlendState.dstAlphaBlendFactor));
770 if(colorBlendState.colorBlendOp != colorBlendState.alphaBlendOp)
772 mGl.BlendEquationSeparate(GetBlendOp(colorBlendState.colorBlendOp), GetBlendOp(colorBlendState.alphaBlendOp));
776 mGl.BlendEquation(GetBlendOp(colorBlendState.colorBlendOp));
778 mGl.BlendColor(colorBlendState.blendConstants[0],
779 colorBlendState.blendConstants[1],
780 colorBlendState.blendConstants[2],
781 colorBlendState.blendConstants[3]);
785 mGl.Disable(GL_BLEND);
790 * @brief Presents render target
791 * @param renderTarget render target to present
793 void TestGraphicsController::PresentRenderTarget(Graphics::RenderTarget* renderTarget)
795 TraceCallStack::NamedParams namedParams;
796 namedParams["renderTarget"] << std::hex << renderTarget;
797 mCallStack.PushCall("PresentRenderTarget", "", namedParams);
801 * @brief Waits until the GPU is idle
803 void TestGraphicsController::WaitIdle()
805 mCallStack.PushCall("WaitIdle", "");
809 * @brief Lifecycle pause event
811 void TestGraphicsController::Pause()
813 mCallStack.PushCall("Pause", "");
817 * @brief Lifecycle resume event
819 void TestGraphicsController::Resume()
821 mCallStack.PushCall("Resume", "");
824 void TestGraphicsController::Shutdown()
826 mCallStack.PushCall("Shutdown", "");
829 void TestGraphicsController::Destroy()
831 mCallStack.PushCall("Destroy", "");
834 void TestGraphicsController::UpdateTextures(const std::vector<Graphics::TextureUpdateInfo>& updateInfoList,
835 const std::vector<Graphics::TextureUpdateSourceInfo>& sourceList)
837 TraceCallStack::NamedParams namedParams;
838 namedParams["updateInfoList"] << "[" << updateInfoList.size() << "]:";
839 namedParams["sourceList"] << "[" << sourceList.size() << "]:";
841 mCallStack.PushCall("UpdateTextures", "", namedParams);
843 // Call either TexImage2D or TexSubImage2D
844 for(unsigned int i = 0; i < updateInfoList.size(); ++i)
846 auto& updateInfo = updateInfoList[i];
847 auto& source = sourceList[i];
849 auto texture = static_cast<TestGraphicsTexture*>(updateInfo.dstTexture);
850 texture->Bind(0); // Use first texture unit during resource update
851 texture->Update(updateInfo, source);
855 bool TestGraphicsController::EnableDepthStencilBuffer(bool enableDepth, bool enableStencil)
857 TraceCallStack::NamedParams namedParams;
858 namedParams["enableDepth"] << (enableDepth ? "T" : "F");
859 namedParams["enableStencil"] << (enableStencil ? "T" : "F");
860 mCallStack.PushCall("EnableDepthStencilBuffer", "", namedParams);
864 void TestGraphicsController::RunGarbageCollector(size_t numberOfDiscardedRenderers)
866 TraceCallStack::NamedParams namedParams;
867 namedParams["numberOfDiscardedRenderers"] << numberOfDiscardedRenderers;
868 mCallStack.PushCall("RunGarbageCollector", "", namedParams);
871 void TestGraphicsController::DiscardUnusedResources()
873 mCallStack.PushCall("DiscardUnusedResources", "");
876 bool TestGraphicsController::IsDiscardQueueEmpty()
878 mCallStack.PushCall("IsDiscardQueueEmpty", "");
879 return isDiscardQueueEmptyResult;
883 * @brief Test if the graphics subsystem has resumed & should force a draw
885 * @return true if the graphics subsystem requires a re-draw
887 bool TestGraphicsController::IsDrawOnResumeRequired()
889 mCallStack.PushCall("IsDrawOnResumeRequired", "");
890 return isDrawOnResumeRequiredResult;
893 Graphics::UniquePtr<Graphics::Buffer> TestGraphicsController::CreateBuffer(const Graphics::BufferCreateInfo& createInfo, Graphics::UniquePtr<Graphics::Buffer>&& oldBuffer)
895 std::ostringstream oss;
896 oss << "bufferCreateInfo:" << createInfo;
897 mCallStack.PushCall("CreateBuffer", oss.str());
898 return Graphics::MakeUnique<TestGraphicsBuffer>(mCallStack, mGl, createInfo.size, createInfo.usage);
901 Graphics::UniquePtr<Graphics::CommandBuffer> TestGraphicsController::CreateCommandBuffer(const Graphics::CommandBufferCreateInfo& commandBufferCreateInfo, Graphics::UniquePtr<Graphics::CommandBuffer>&& oldCommandBuffer)
903 std::ostringstream oss;
904 oss << "commandBufferCreateInfo:" << commandBufferCreateInfo;
905 mCallStack.PushCall("CreateCommandBuffer", oss.str());
906 return Graphics::MakeUnique<TestGraphicsCommandBuffer>(mCommandBufferCallStack, mGl);
909 Graphics::UniquePtr<Graphics::RenderPass> TestGraphicsController::CreateRenderPass(const Graphics::RenderPassCreateInfo& renderPassCreateInfo, Graphics::UniquePtr<Graphics::RenderPass>&& oldRenderPass)
911 mCallStack.PushCall("CreateRenderPass", "");
912 return Graphics::MakeUnique<TestGraphicsRenderPass>(mGl, renderPassCreateInfo);
915 Graphics::UniquePtr<Graphics::Texture> TestGraphicsController::CreateTexture(const Graphics::TextureCreateInfo& textureCreateInfo, Graphics::UniquePtr<Graphics::Texture>&& oldTexture)
917 TraceCallStack::NamedParams namedParams;
918 namedParams["textureCreateInfo"] << textureCreateInfo;
919 mCallStack.PushCall("CreateTexture", namedParams.str(), namedParams);
921 return Graphics::MakeUnique<TestGraphicsTexture>(mGl, textureCreateInfo);
924 Graphics::UniquePtr<Graphics::Framebuffer> TestGraphicsController::CreateFramebuffer(
925 const Graphics::FramebufferCreateInfo& createInfo,
926 Graphics::UniquePtr<Graphics::Framebuffer>&& oldFramebuffer)
928 TraceCallStack::NamedParams namedParams;
929 namedParams["framebufferCreateInfo"] << createInfo;
930 mCallStack.PushCall("Controller::CreateFramebuffer", namedParams.str(), namedParams);
932 return Graphics::MakeUnique<TestGraphicsFramebuffer>(mFrameBufferCallStack, mGl, createInfo);
935 Graphics::UniquePtr<Graphics::Pipeline> TestGraphicsController::CreatePipeline(const Graphics::PipelineCreateInfo& pipelineCreateInfo, Graphics::UniquePtr<Graphics::Pipeline>&& oldPipeline)
937 mCallStack.PushCall("CreatePipeline", "");
938 return std::make_unique<TestGraphicsPipeline>(mGl, pipelineCreateInfo);
941 Graphics::UniquePtr<Graphics::Program> TestGraphicsController::CreateProgram(const Graphics::ProgramCreateInfo& programCreateInfo, Graphics::UniquePtr<Graphics::Program>&& oldProgram)
943 mCallStack.PushCall("CreateProgram", "");
945 for(auto cacheEntry : mProgramCache)
948 for(auto& shader : *(programCreateInfo.shaderState))
950 auto graphicsShader = Uncast<TestGraphicsShader>(shader.shader);
951 std::vector<uint8_t> source;
952 source.resize(graphicsShader->mCreateInfo.sourceSize);
953 memcpy(&source[0], graphicsShader->mCreateInfo.sourceData, graphicsShader->mCreateInfo.sourceSize);
955 if(!std::equal(source.begin(), source.end(), cacheEntry.shaders[shader.pipelineStage].begin()))
963 return Graphics::MakeUnique<TestGraphicsProgram>(cacheEntry.programImpl);
967 mProgramCache.emplace_back();
968 mProgramCache.back().programImpl = new TestGraphicsProgramImpl(mGl, programCreateInfo, mVertexFormats, mCustomUniforms);
969 for(auto& shader : *(programCreateInfo.shaderState))
971 auto graphicsShader = Uncast<TestGraphicsShader>(shader.shader);
972 mProgramCache.back().shaders[shader.pipelineStage].resize(graphicsShader->mCreateInfo.sourceSize);
973 memcpy(&mProgramCache.back().shaders[shader.pipelineStage][0], graphicsShader->mCreateInfo.sourceData, graphicsShader->mCreateInfo.sourceSize);
975 return Graphics::MakeUnique<TestGraphicsProgram>(mProgramCache.back().programImpl);
978 Graphics::UniquePtr<Graphics::Shader> TestGraphicsController::CreateShader(const Graphics::ShaderCreateInfo& shaderCreateInfo, Graphics::UniquePtr<Graphics::Shader>&& oldShader)
980 mCallStack.PushCall("CreateShader", "");
981 return Graphics::MakeUnique<TestGraphicsShader>(mGl, shaderCreateInfo);
984 Graphics::UniquePtr<Graphics::Sampler> TestGraphicsController::CreateSampler(const Graphics::SamplerCreateInfo& samplerCreateInfo, Graphics::UniquePtr<Graphics::Sampler>&& oldSampler)
986 TraceCallStack::NamedParams namedParams;
987 namedParams["samplerCreateInfo"] << samplerCreateInfo;
988 mCallStack.PushCall("CreateSampler", namedParams.str(), namedParams);
990 return Graphics::MakeUnique<TestGraphicsSampler>(mGl, samplerCreateInfo);
993 Graphics::UniquePtr<Graphics::RenderTarget> TestGraphicsController::CreateRenderTarget(const Graphics::RenderTargetCreateInfo& renderTargetCreateInfo, Graphics::UniquePtr<Graphics::RenderTarget>&& oldRenderTarget)
995 mCallStack.PushCall("CreateRenderTarget", "");
996 return Graphics::MakeUnique<TestGraphicsRenderTarget>(mGl, renderTargetCreateInfo);
999 Graphics::UniquePtr<Graphics::Memory> TestGraphicsController::MapBufferRange(const Graphics::MapBufferInfo& mapInfo)
1001 mCallStack.PushCall("MapBufferRange", "");
1003 auto buffer = static_cast<TestGraphicsBuffer*>(mapInfo.buffer);
1004 buffer->memory.resize(mapInfo.offset + mapInfo.size); // For initial testing, allow writes past capacity
1006 return std::make_unique<TestGraphicsMemory>(mCallStack, *buffer, mapInfo.offset, mapInfo.size);
1009 Graphics::UniquePtr<Graphics::Memory> TestGraphicsController::MapTextureRange(const Graphics::MapTextureInfo& mapInfo)
1011 mCallStack.PushCall("MapTextureRange", "");
1015 void TestGraphicsController::UnmapMemory(Graphics::UniquePtr<Graphics::Memory> memory)
1017 mCallStack.PushCall("UnmapMemory", "");
1020 Graphics::MemoryRequirements TestGraphicsController::GetTextureMemoryRequirements(Graphics::Texture& texture) const
1022 mCallStack.PushCall("GetTextureMemoryRequirements", "");
1023 return Graphics::MemoryRequirements{};
1026 Graphics::MemoryRequirements TestGraphicsController::GetBufferMemoryRequirements(Graphics::Buffer& buffer) const
1028 mCallStack.PushCall("GetBufferMemoryRequirements", "");
1029 return Graphics::MemoryRequirements{};
1032 const Graphics::TextureProperties& TestGraphicsController::GetTextureProperties(const Graphics::Texture& texture)
1034 static Graphics::TextureProperties textureProperties{};
1035 mCallStack.PushCall("GetTextureProperties", "");
1037 return textureProperties;
1040 const Graphics::Reflection& TestGraphicsController::GetProgramReflection(const Graphics::Program& program)
1042 mCallStack.PushCall("GetProgramReflection", "");
1044 return static_cast<const TestGraphicsProgram*>(&program)->GetReflection();
1047 bool TestGraphicsController::PipelineEquals(const Graphics::Pipeline& pipeline0, const Graphics::Pipeline& pipeline1) const
1049 mCallStack.PushCall("PipelineEquals", "");
1053 bool TestGraphicsController::GetProgramParameter(Graphics::Program& program, uint32_t parameterId, void* outData)
1055 mCallStack.PushCall("GetProgramParameter", "");
1056 auto graphicsProgram = Uncast<TestGraphicsProgram>(&program);
1057 return graphicsProgram->GetParameter(parameterId, outData);