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;
699 DALI_ASSERT_DEBUG(0 && "BeginRenderPass has no render pass");
704 case CommandType::END_RENDER_PASS:
712 void TestGraphicsController::BindPipeline(TestGraphicsPipeline* pipeline)
714 auto& vi = pipeline->vertexInputState;
715 for(auto& attribute : vi.attributes)
717 mGl.EnableVertexAttribArray(attribute.location);
718 uint32_t attributeOffset = attribute.offset;
719 GLsizei stride = vi.bufferBindings[attribute.binding].stride;
721 mGl.VertexAttribPointer(attribute.location,
722 GetNumComponents(attribute.format),
723 GetGlType(attribute.format),
724 GL_FALSE, // Not normalized
726 reinterpret_cast<void*>(attributeOffset));
730 auto& rasterizationState = pipeline->rasterizationState;
731 if(rasterizationState.cullMode == Graphics::CullMode::NONE)
733 mGl.Disable(GL_CULL_FACE);
737 mGl.Enable(GL_CULL_FACE);
738 mGl.CullFace(GetCullFace(rasterizationState.cullMode));
741 mGl.FrontFace(GetFrontFace(rasterizationState.frontFace));
744 auto& colorBlendState = pipeline->colorBlendState;
745 if(colorBlendState.blendEnable)
747 mGl.Enable(GL_BLEND);
749 mGl.BlendFuncSeparate(GetBlendFactor(colorBlendState.srcColorBlendFactor),
750 GetBlendFactor(colorBlendState.dstColorBlendFactor),
751 GetBlendFactor(colorBlendState.srcAlphaBlendFactor),
752 GetBlendFactor(colorBlendState.dstAlphaBlendFactor));
753 if(colorBlendState.colorBlendOp != colorBlendState.alphaBlendOp)
755 mGl.BlendEquationSeparate(GetBlendOp(colorBlendState.colorBlendOp), GetBlendOp(colorBlendState.alphaBlendOp));
759 mGl.BlendEquation(GetBlendOp(colorBlendState.colorBlendOp));
761 mGl.BlendColor(colorBlendState.blendConstants[0],
762 colorBlendState.blendConstants[1],
763 colorBlendState.blendConstants[2],
764 colorBlendState.blendConstants[3]);
768 mGl.Disable(GL_BLEND);
773 * @brief Presents render target
774 * @param renderTarget render target to present
776 void TestGraphicsController::PresentRenderTarget(Graphics::RenderTarget* renderTarget)
778 TraceCallStack::NamedParams namedParams;
779 namedParams["renderTarget"] << std::hex << renderTarget;
780 mCallStack.PushCall("PresentRenderTarget", "", namedParams);
784 * @brief Waits until the GPU is idle
786 void TestGraphicsController::WaitIdle()
788 mCallStack.PushCall("WaitIdle", "");
792 * @brief Lifecycle pause event
794 void TestGraphicsController::Pause()
796 mCallStack.PushCall("Pause", "");
800 * @brief Lifecycle resume event
802 void TestGraphicsController::Resume()
804 mCallStack.PushCall("Resume", "");
807 void TestGraphicsController::Shutdown()
809 mCallStack.PushCall("Shutdown", "");
812 void TestGraphicsController::Destroy()
814 mCallStack.PushCall("Destroy", "");
817 void TestGraphicsController::UpdateTextures(const std::vector<Graphics::TextureUpdateInfo>& updateInfoList,
818 const std::vector<Graphics::TextureUpdateSourceInfo>& sourceList)
820 TraceCallStack::NamedParams namedParams;
821 namedParams["updateInfoList"] << "[" << updateInfoList.size() << "]:";
822 namedParams["sourceList"] << "[" << sourceList.size() << "]:";
824 mCallStack.PushCall("UpdateTextures", "", namedParams);
826 // Call either TexImage2D or TexSubImage2D
827 for(unsigned int i = 0; i < updateInfoList.size(); ++i)
829 auto& updateInfo = updateInfoList[i];
830 auto& source = sourceList[i];
832 auto texture = static_cast<TestGraphicsTexture*>(updateInfo.dstTexture);
833 texture->Bind(0); // Use first texture unit during resource update
834 texture->Update(updateInfo, source);
838 bool TestGraphicsController::EnableDepthStencilBuffer(bool enableDepth, bool enableStencil)
840 TraceCallStack::NamedParams namedParams;
841 namedParams["enableDepth"] << (enableDepth ? "T" : "F");
842 namedParams["enableStencil"] << (enableStencil ? "T" : "F");
843 mCallStack.PushCall("EnableDepthStencilBuffer", "", namedParams);
847 void TestGraphicsController::RunGarbageCollector(size_t numberOfDiscardedRenderers)
849 TraceCallStack::NamedParams namedParams;
850 namedParams["numberOfDiscardedRenderers"] << numberOfDiscardedRenderers;
851 mCallStack.PushCall("RunGarbageCollector", "", namedParams);
854 void TestGraphicsController::DiscardUnusedResources()
856 mCallStack.PushCall("DiscardUnusedResources", "");
859 bool TestGraphicsController::IsDiscardQueueEmpty()
861 mCallStack.PushCall("IsDiscardQueueEmpty", "");
862 return isDiscardQueueEmptyResult;
866 * @brief Test if the graphics subsystem has resumed & should force a draw
868 * @return true if the graphics subsystem requires a re-draw
870 bool TestGraphicsController::IsDrawOnResumeRequired()
872 mCallStack.PushCall("IsDrawOnResumeRequired", "");
873 return isDrawOnResumeRequiredResult;
876 Graphics::UniquePtr<Graphics::Buffer> TestGraphicsController::CreateBuffer(const Graphics::BufferCreateInfo& createInfo, Graphics::UniquePtr<Graphics::Buffer>&& oldBuffer)
878 std::ostringstream oss;
879 oss << "bufferCreateInfo:" << createInfo;
880 mCallStack.PushCall("CreateBuffer", oss.str());
881 return Graphics::MakeUnique<TestGraphicsBuffer>(mCallStack, mGl, createInfo.size, createInfo.usage);
884 Graphics::UniquePtr<Graphics::CommandBuffer> TestGraphicsController::CreateCommandBuffer(const Graphics::CommandBufferCreateInfo& commandBufferCreateInfo, Graphics::UniquePtr<Graphics::CommandBuffer>&& oldCommandBuffer)
886 std::ostringstream oss;
887 oss << "commandBufferCreateInfo:" << commandBufferCreateInfo;
888 mCallStack.PushCall("CreateCommandBuffer", oss.str());
889 return Graphics::MakeUnique<TestGraphicsCommandBuffer>(mCommandBufferCallStack, mGl);
892 Graphics::UniquePtr<Graphics::RenderPass> TestGraphicsController::CreateRenderPass(const Graphics::RenderPassCreateInfo& renderPassCreateInfo, Graphics::UniquePtr<Graphics::RenderPass>&& oldRenderPass)
894 mCallStack.PushCall("CreateRenderPass", "");
895 return Graphics::MakeUnique<TestGraphicsRenderPass>(mGl, renderPassCreateInfo);
898 Graphics::UniquePtr<Graphics::Texture> TestGraphicsController::CreateTexture(const Graphics::TextureCreateInfo& textureCreateInfo, Graphics::UniquePtr<Graphics::Texture>&& oldTexture)
900 TraceCallStack::NamedParams namedParams;
901 namedParams["textureCreateInfo"] << textureCreateInfo;
902 mCallStack.PushCall("CreateTexture", namedParams.str(), namedParams);
904 return Graphics::MakeUnique<TestGraphicsTexture>(mGl, textureCreateInfo);
907 Graphics::UniquePtr<Graphics::Framebuffer> TestGraphicsController::CreateFramebuffer(
908 const Graphics::FramebufferCreateInfo& createInfo,
909 Graphics::UniquePtr<Graphics::Framebuffer>&& oldFramebuffer)
911 TraceCallStack::NamedParams namedParams;
912 namedParams["framebufferCreateInfo"] << createInfo;
913 mCallStack.PushCall("Controller::CreateFramebuffer", namedParams.str(), namedParams);
915 return Graphics::MakeUnique<TestGraphicsFramebuffer>(mFrameBufferCallStack, mGl, createInfo);
918 Graphics::UniquePtr<Graphics::Pipeline> TestGraphicsController::CreatePipeline(const Graphics::PipelineCreateInfo& pipelineCreateInfo, Graphics::UniquePtr<Graphics::Pipeline>&& oldPipeline)
920 mCallStack.PushCall("CreatePipeline", "");
921 return std::make_unique<TestGraphicsPipeline>(mGl, pipelineCreateInfo);
924 Graphics::UniquePtr<Graphics::Program> TestGraphicsController::CreateProgram(const Graphics::ProgramCreateInfo& programCreateInfo, Graphics::UniquePtr<Graphics::Program>&& oldProgram)
926 mCallStack.PushCall("CreateProgram", "");
928 for(auto cacheEntry : mProgramCache)
931 for(auto& shader : *(programCreateInfo.shaderState))
933 auto graphicsShader = Uncast<TestGraphicsShader>(shader.shader);
934 std::vector<uint8_t> source;
935 source.resize(graphicsShader->mCreateInfo.sourceSize);
936 memcpy(&source[0], graphicsShader->mCreateInfo.sourceData, graphicsShader->mCreateInfo.sourceSize);
938 if(!std::equal(source.begin(), source.end(), cacheEntry.shaders[shader.pipelineStage].begin()))
946 return Graphics::MakeUnique<TestGraphicsProgram>(cacheEntry.programImpl);
950 mProgramCache.emplace_back();
951 mProgramCache.back().programImpl = new TestGraphicsProgramImpl(mGl, programCreateInfo, mVertexFormats, mCustomUniforms);
952 for(auto& shader : *(programCreateInfo.shaderState))
954 auto graphicsShader = Uncast<TestGraphicsShader>(shader.shader);
955 mProgramCache.back().shaders[shader.pipelineStage].resize(graphicsShader->mCreateInfo.sourceSize);
956 memcpy(&mProgramCache.back().shaders[shader.pipelineStage][0], graphicsShader->mCreateInfo.sourceData, graphicsShader->mCreateInfo.sourceSize);
958 return Graphics::MakeUnique<TestGraphicsProgram>(mProgramCache.back().programImpl);
961 Graphics::UniquePtr<Graphics::Shader> TestGraphicsController::CreateShader(const Graphics::ShaderCreateInfo& shaderCreateInfo, Graphics::UniquePtr<Graphics::Shader>&& oldShader)
963 mCallStack.PushCall("CreateShader", "");
964 return Graphics::MakeUnique<TestGraphicsShader>(mGl, shaderCreateInfo);
967 Graphics::UniquePtr<Graphics::Sampler> TestGraphicsController::CreateSampler(const Graphics::SamplerCreateInfo& samplerCreateInfo, Graphics::UniquePtr<Graphics::Sampler>&& oldSampler)
969 TraceCallStack::NamedParams namedParams;
970 namedParams["samplerCreateInfo"] << samplerCreateInfo;
971 mCallStack.PushCall("CreateSampler", namedParams.str(), namedParams);
973 return Graphics::MakeUnique<TestGraphicsSampler>(mGl, samplerCreateInfo);
976 Graphics::UniquePtr<Graphics::RenderTarget> TestGraphicsController::CreateRenderTarget(const Graphics::RenderTargetCreateInfo& renderTargetCreateInfo, Graphics::UniquePtr<Graphics::RenderTarget>&& oldRenderTarget)
978 mCallStack.PushCall("CreateRenderTarget", "");
979 return Graphics::MakeUnique<TestGraphicsRenderTarget>(mGl, renderTargetCreateInfo);
982 Graphics::UniquePtr<Graphics::Memory> TestGraphicsController::MapBufferRange(const Graphics::MapBufferInfo& mapInfo)
984 mCallStack.PushCall("MapBufferRange", "");
986 auto buffer = static_cast<TestGraphicsBuffer*>(mapInfo.buffer);
987 buffer->memory.resize(mapInfo.offset + mapInfo.size); // For initial testing, allow writes past capacity
989 return std::make_unique<TestGraphicsMemory>(mCallStack, *buffer, mapInfo.offset, mapInfo.size);
992 Graphics::UniquePtr<Graphics::Memory> TestGraphicsController::MapTextureRange(const Graphics::MapTextureInfo& mapInfo)
994 mCallStack.PushCall("MapTextureRange", "");
998 void TestGraphicsController::UnmapMemory(Graphics::UniquePtr<Graphics::Memory> memory)
1000 mCallStack.PushCall("UnmapMemory", "");
1003 Graphics::MemoryRequirements TestGraphicsController::GetTextureMemoryRequirements(Graphics::Texture& texture) const
1005 mCallStack.PushCall("GetTextureMemoryRequirements", "");
1006 return Graphics::MemoryRequirements{};
1009 Graphics::MemoryRequirements TestGraphicsController::GetBufferMemoryRequirements(Graphics::Buffer& buffer) const
1011 mCallStack.PushCall("GetBufferMemoryRequirements", "");
1012 return Graphics::MemoryRequirements{};
1015 const Graphics::TextureProperties& TestGraphicsController::GetTextureProperties(const Graphics::Texture& texture)
1017 static Graphics::TextureProperties textureProperties{};
1018 mCallStack.PushCall("GetTextureProperties", "");
1020 return textureProperties;
1023 const Graphics::Reflection& TestGraphicsController::GetProgramReflection(const Graphics::Program& program)
1025 mCallStack.PushCall("GetProgramReflection", "");
1027 return static_cast<const TestGraphicsProgram*>(&program)->GetReflection();
1030 bool TestGraphicsController::PipelineEquals(const Graphics::Pipeline& pipeline0, const Graphics::Pipeline& pipeline1) const
1032 mCallStack.PushCall("PipelineEquals", "");
1036 bool TestGraphicsController::GetProgramParameter(Graphics::Program& program, uint32_t parameterId, void* outData)
1038 mCallStack.PushCall("GetProgramParameter", "");
1039 auto graphicsProgram = Uncast<TestGraphicsProgram>(&program);
1040 return graphicsProgram->GetParameter(parameterId, outData);