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-reflection.h"
22 #include "test-graphics-sampler.h"
23 #include "test-graphics-shader.h"
24 #include "test-graphics-texture.h"
26 #include <dali/integration-api/gl-defines.h>
34 T* Uncast(const Graphics::CommandBuffer* object)
36 return const_cast<T*>(static_cast<const T*>(object));
40 T* Uncast(const Graphics::Texture* object)
42 return const_cast<T*>(static_cast<const T*>(object));
46 T* Uncast(const Graphics::Sampler* object)
48 return const_cast<T*>(static_cast<const T*>(object));
52 T* Uncast(const Graphics::Buffer* object)
54 return const_cast<T*>(static_cast<const T*>(object));
58 T* Uncast(const Graphics::Shader* object)
60 return const_cast<T*>(static_cast<const T*>(object));
63 std::ostream& operator<<(std::ostream& o, const Graphics::BufferCreateInfo& bufferCreateInfo)
65 return o << "usage:" << std::hex << bufferCreateInfo.usage << ", size:" << std::dec << bufferCreateInfo.size;
68 std::ostream& operator<<(std::ostream& o, const Graphics::CommandBufferCreateInfo& commandBufferCreateInfo)
70 return o << "level:" << (commandBufferCreateInfo.level == Graphics::CommandBufferLevel::PRIMARY ? "PRIMARY" : "SECONDARY")
71 << ", fixedCapacity:" << std::dec << commandBufferCreateInfo.fixedCapacity;
74 std::ostream& operator<<(std::ostream& o, const Graphics::TextureType& textureType)
78 case Graphics::TextureType::TEXTURE_2D:
81 case Graphics::TextureType::TEXTURE_3D:
84 case Graphics::TextureType::TEXTURE_CUBEMAP:
85 o << "TEXTURE_CUBEMAP";
91 std::ostream& operator<<(std::ostream& o, const Graphics::Extent2D extent)
93 o << "width:" << extent.width << ", height:" << extent.height;
97 std::ostream& operator<<(std::ostream& o, const Graphics::TextureCreateInfo& createInfo)
99 o << "textureType:" << createInfo.textureType
100 << " size:" << createInfo.size
101 << " format:" << static_cast<uint32_t>(createInfo.format)
102 << " mipMapFlag:" << createInfo.mipMapFlag
103 << " layout:" << (createInfo.layout == Graphics::TextureLayout::LINEAR ? "LINEAR" : "OPTIMAL")
104 << " usageFlags:" << std::hex << createInfo.usageFlags
105 << " data:" << std::hex << createInfo.data
106 << " dataSize:" << std::dec << createInfo.dataSize
107 << " nativeImagePtr:" << std::hex << createInfo.nativeImagePtr;
111 std::ostream& operator<<(std::ostream& o, Graphics::SamplerAddressMode addressMode)
115 case Graphics::SamplerAddressMode::REPEAT:
118 case Graphics::SamplerAddressMode::MIRRORED_REPEAT:
119 o << "MIRRORED_REPEAT";
121 case Graphics::SamplerAddressMode::CLAMP_TO_EDGE:
122 o << "CLAMP_TO_EDGE";
124 case Graphics::SamplerAddressMode::CLAMP_TO_BORDER:
125 o << "CLAMP_TO_BORDER";
127 case Graphics::SamplerAddressMode::MIRROR_CLAMP_TO_EDGE:
128 o << "MIRROR_CLAMP_TO_EDGE";
134 std::ostream& operator<<(std::ostream& o, Graphics::SamplerFilter filterMode)
138 case Graphics::SamplerFilter::LINEAR:
141 case Graphics::SamplerFilter::NEAREST:
148 std::ostream& operator<<(std::ostream& o, Graphics::SamplerMipmapMode mipmapMode)
152 case Graphics::SamplerMipmapMode::NONE:
155 case Graphics::SamplerMipmapMode::LINEAR:
158 case Graphics::SamplerMipmapMode::NEAREST:
165 std::ostream& operator<<(std::ostream& o, const Graphics::SamplerCreateInfo& createInfo)
167 o << "minFilter:" << createInfo.minFilter
168 << " magFilter:" << createInfo.magFilter
169 << " wrapModeU:" << createInfo.addressModeU
170 << " wrapModeV:" << createInfo.addressModeV
171 << " wrapModeW:" << createInfo.addressModeW
172 << " mipMapMode:" << createInfo.mipMapMode;
176 class TestGraphicsMemory : public Graphics::Memory
179 TestGraphicsMemory(TraceCallStack& callStack, TestGraphicsBuffer& buffer, uint32_t mappedOffset, uint32_t mappedSize)
180 : mCallStack(callStack),
182 mMappedOffset(mappedOffset),
183 mMappedSize(mappedSize)
187 void* LockRegion(uint32_t offset, uint32_t size) override
189 std::ostringstream o;
190 o << offset << ", " << size;
191 mCallStack.PushCall("Memory::LockRegion", o.str());
193 if(offset > mMappedOffset + mMappedSize ||
194 size + offset > mMappedOffset + mMappedSize)
196 fprintf(stderr, "TestGraphics.Memory::LockRegion() Out of bounds");
197 mBuffer.memory.resize(mMappedOffset + offset + size); // Grow to prevent memcpy from crashing
199 mLockedOffset = offset;
201 return &mBuffer.memory[mMappedOffset + offset];
204 void Unlock(bool flush) override
206 mCallStack.PushCall("Memory::Unlock", (flush ? "Flush" : "NoFlush"));
213 void Flush() override
215 mCallStack.PushCall("Memory::Flush", "");
217 mBuffer.Upload(mMappedOffset + mLockedOffset, mLockedSize);
221 TraceCallStack& mCallStack;
222 TestGraphicsBuffer& mBuffer;
223 uint32_t mMappedOffset;
224 uint32_t mMappedSize;
225 uint32_t mLockedOffset;
226 uint32_t mLockedSize;
229 TestGraphicsController::TestGraphicsController()
230 : mCallStack(true, "TestGraphicsController."),
231 mCommandBufferCallStack(true, "TestCommandBuffer.")
233 mCallStack.Enable(true);
234 mCommandBufferCallStack.Enable(true);
235 auto& trace = mGl.GetTextureTrace();
237 trace.EnableLogging(true);
240 int GetNumComponents(Graphics::VertexInputFormat vertexFormat)
244 case Graphics::VertexInputFormat::UNDEFINED:
245 case Graphics::VertexInputFormat::FLOAT:
246 case Graphics::VertexInputFormat::INTEGER:
248 case Graphics::VertexInputFormat::IVECTOR2:
249 case Graphics::VertexInputFormat::FVECTOR2:
251 case Graphics::VertexInputFormat::IVECTOR3:
252 case Graphics::VertexInputFormat::FVECTOR3:
254 case Graphics::VertexInputFormat::FVECTOR4:
255 case Graphics::VertexInputFormat::IVECTOR4:
261 GLint GetSize(Graphics::VertexInputFormat vertexFormat)
265 case Graphics::VertexInputFormat::UNDEFINED:
267 case Graphics::VertexInputFormat::INTEGER:
268 case Graphics::VertexInputFormat::IVECTOR2:
269 case Graphics::VertexInputFormat::IVECTOR3:
270 case Graphics::VertexInputFormat::IVECTOR4:
272 case Graphics::VertexInputFormat::FLOAT:
273 case Graphics::VertexInputFormat::FVECTOR2:
274 case Graphics::VertexInputFormat::FVECTOR3:
275 case Graphics::VertexInputFormat::FVECTOR4:
281 GLint GetGlType(Graphics::VertexInputFormat vertexFormat)
285 case Graphics::VertexInputFormat::UNDEFINED:
287 case Graphics::VertexInputFormat::INTEGER:
288 case Graphics::VertexInputFormat::IVECTOR2:
289 case Graphics::VertexInputFormat::IVECTOR3:
290 case Graphics::VertexInputFormat::IVECTOR4:
292 case Graphics::VertexInputFormat::FLOAT:
293 case Graphics::VertexInputFormat::FVECTOR2:
294 case Graphics::VertexInputFormat::FVECTOR3:
295 case Graphics::VertexInputFormat::FVECTOR4:
301 GLenum GetTopology(Graphics::PrimitiveTopology topology)
305 case Graphics::PrimitiveTopology::POINT_LIST:
308 case Graphics::PrimitiveTopology::LINE_LIST:
311 case Graphics::PrimitiveTopology::LINE_LOOP:
314 case Graphics::PrimitiveTopology::LINE_STRIP:
315 return GL_LINE_STRIP;
317 case Graphics::PrimitiveTopology::TRIANGLE_LIST:
320 case Graphics::PrimitiveTopology::TRIANGLE_STRIP:
321 return GL_TRIANGLE_STRIP;
323 case Graphics::PrimitiveTopology::TRIANGLE_FAN:
324 return GL_TRIANGLE_FAN;
329 GLenum GetCullFace(Graphics::CullMode cullMode)
333 case Graphics::CullMode::NONE:
335 case Graphics::CullMode::FRONT:
337 case Graphics::CullMode::BACK:
339 case Graphics::CullMode::FRONT_AND_BACK:
340 return GL_FRONT_AND_BACK;
345 GLenum GetFrontFace(Graphics::FrontFace frontFace)
347 if(frontFace == Graphics::FrontFace::CLOCKWISE)
354 GLenum GetBlendFactor(Graphics::BlendFactor blendFactor)
356 GLenum glFactor = GL_ZERO;
360 case Graphics::BlendFactor::ZERO:
363 case Graphics::BlendFactor::ONE:
366 case Graphics::BlendFactor::SRC_COLOR:
367 glFactor = GL_SRC_COLOR;
369 case Graphics::BlendFactor::ONE_MINUS_SRC_COLOR:
370 glFactor = GL_ONE_MINUS_SRC_COLOR;
372 case Graphics::BlendFactor::DST_COLOR:
373 glFactor = GL_DST_COLOR;
375 case Graphics::BlendFactor::ONE_MINUS_DST_COLOR:
376 glFactor = GL_ONE_MINUS_DST_COLOR;
378 case Graphics::BlendFactor::SRC_ALPHA:
379 glFactor = GL_SRC_ALPHA;
381 case Graphics::BlendFactor::ONE_MINUS_SRC_ALPHA:
382 glFactor = GL_ONE_MINUS_SRC_ALPHA;
384 case Graphics::BlendFactor::DST_ALPHA:
385 glFactor = GL_DST_ALPHA;
387 case Graphics::BlendFactor::ONE_MINUS_DST_ALPHA:
388 glFactor = GL_ONE_MINUS_DST_ALPHA;
390 case Graphics::BlendFactor::CONSTANT_COLOR:
391 glFactor = GL_CONSTANT_COLOR;
393 case Graphics::BlendFactor::ONE_MINUS_CONSTANT_COLOR:
394 glFactor = GL_ONE_MINUS_CONSTANT_COLOR;
396 case Graphics::BlendFactor::CONSTANT_ALPHA:
397 glFactor = GL_CONSTANT_ALPHA;
399 case Graphics::BlendFactor::ONE_MINUS_CONSTANT_ALPHA:
400 glFactor = GL_ONE_MINUS_CONSTANT_ALPHA;
402 case Graphics::BlendFactor::SRC_ALPHA_SATURATE:
403 glFactor = GL_SRC_ALPHA_SATURATE;
405 // GLES doesn't appear to have dual source blending.
406 case Graphics::BlendFactor::SRC1_COLOR:
407 glFactor = GL_SRC_COLOR;
409 case Graphics::BlendFactor::ONE_MINUS_SRC1_COLOR:
410 glFactor = GL_ONE_MINUS_SRC_COLOR;
412 case Graphics::BlendFactor::SRC1_ALPHA:
413 glFactor = GL_SRC_ALPHA;
415 case Graphics::BlendFactor::ONE_MINUS_SRC1_ALPHA:
416 glFactor = GL_ONE_MINUS_SRC_ALPHA;
422 GLenum GetBlendOp(Graphics::BlendOp blendOp)
424 GLenum op = GL_FUNC_ADD;
427 case Graphics::BlendOp::ADD:
430 case Graphics::BlendOp::SUBTRACT:
431 op = GL_FUNC_SUBTRACT;
433 case Graphics::BlendOp::REVERSE_SUBTRACT:
434 op = GL_FUNC_REVERSE_SUBTRACT;
436 case Graphics::BlendOp::MIN:
439 case Graphics::BlendOp::MAX:
443 // @todo Add advanced blend equations
448 void TestGraphicsController::SubmitCommandBuffers(const Graphics::SubmitInfo& submitInfo)
450 TraceCallStack::NamedParams namedParams;
451 namedParams["submitInfo"] << "cmdBuffer[" << submitInfo.cmdBuffer.size()
452 << "], flags:" << std::hex << submitInfo.flags;
454 mCallStack.PushCall("SubmitCommandBuffers", "", namedParams);
456 mSubmitStack.emplace_back(submitInfo);
458 for(auto& graphicsCommandBuffer : submitInfo.cmdBuffer)
460 auto commandBuffer = Uncast<TestGraphicsCommandBuffer>(graphicsCommandBuffer);
462 auto value = commandBuffer->GetCommandsByType(0 | CommandType::BIND_TEXTURES);
466 for (auto &binding : value[0]->bindTextures.textureBindings)
470 auto texture = Uncast<TestGraphicsTexture>(binding.texture);
472 texture->Bind(binding.binding);
476 auto sampler = Uncast<TestGraphicsSampler>(binding.sampler);
479 sampler->Apply(texture->GetTarget());
483 texture->Prepare(); // Ensure native texture is ready
488 // IndexBuffer binding,
489 auto bindIndexBufferCmds = commandBuffer->GetCommandsByType(0 | CommandType::BIND_INDEX_BUFFER);
490 if (!bindIndexBufferCmds.empty())
492 auto &indexBufferBinding = bindIndexBufferCmds[0]->bindIndexBuffer;
493 if (indexBufferBinding.buffer)
495 auto buffer = Uncast<TestGraphicsBuffer>(indexBufferBinding.buffer);
500 // VertexBuffer binding,
501 auto bindVertexBufferCmds = commandBuffer->GetCommandsByType(0 | CommandType::BIND_VERTEX_BUFFERS);
502 if (!bindVertexBufferCmds.empty())
504 for (auto &binding : bindVertexBufferCmds[0]->bindVertexBuffers.vertexBufferBindings)
506 auto graphicsBuffer = binding.buffer;
507 auto vertexBuffer = Uncast<TestGraphicsBuffer>(graphicsBuffer);
508 vertexBuffer->Bind();
511 // Pipeline attribute setup
512 auto bindPipelineCmds = commandBuffer->GetCommandsByType(0 | CommandType::BIND_PIPELINE);
513 if (!bindPipelineCmds.empty())
515 auto pipeline = bindPipelineCmds[0]->bindPipeline.pipeline;
516 auto &vi = pipeline->vertexInputState;
517 for (auto &attribute : vi.attributes)
519 mGl.EnableVertexAttribArray(attribute.location);
520 uint32_t attributeOffset = attribute.offset;
521 GLsizei stride = vi.bufferBindings[attribute.binding].stride;
523 mGl.VertexAttribPointer(attribute.location,
524 GetNumComponents(attribute.format),
525 GetGlType(attribute.format),
526 GL_FALSE, // Not normalized
528 reinterpret_cast<void *>(attributeOffset));
531 auto &rasterizationState = pipeline->rasterizationState;
532 if (rasterizationState.cullMode == Graphics::CullMode::NONE)
534 mGl.Disable(GL_CULL_FACE);
538 mGl.Enable(GL_CULL_FACE);
539 mGl.CullFace(GetCullFace(rasterizationState.cullMode));
542 mGl.FrontFace(GetFrontFace(rasterizationState.frontFace));
543 // We don't modify glPolygonMode in our context/abstraction from GL_FILL (the GL default),
544 // so it isn't present in the API (and won't have any tests!)
547 auto &colorBlendState = pipeline->colorBlendState;
548 if (colorBlendState.blendEnable)
550 mGl.Enable(GL_BLEND);
552 mGl.BlendFuncSeparate(GetBlendFactor(colorBlendState.srcColorBlendFactor),
553 GetBlendFactor(colorBlendState.dstColorBlendFactor),
554 GetBlendFactor(colorBlendState.srcAlphaBlendFactor),
555 GetBlendFactor(colorBlendState.dstAlphaBlendFactor));
556 if (colorBlendState.colorBlendOp != colorBlendState.alphaBlendOp)
558 mGl.BlendEquationSeparate(GetBlendOp(colorBlendState.colorBlendOp), GetBlendOp(colorBlendState.alphaBlendOp));
562 mGl.BlendEquation(GetBlendOp(colorBlendState.colorBlendOp));
564 mGl.BlendColor(colorBlendState.blendConstants[0],
565 colorBlendState.blendConstants[1],
566 colorBlendState.blendConstants[2],
567 colorBlendState.blendConstants[3]);
571 mGl.Disable(GL_BLEND);
575 auto topology = pipeline->inputAssemblyState.topology;
577 // UniformBuffer binding (once we know pipeline)
578 auto bindUniformBuffersCmds = commandBuffer->GetCommandsByType(0 | CommandType::BIND_UNIFORM_BUFFER);
579 if (!bindUniformBuffersCmds.empty())
581 auto buffer = bindUniformBuffersCmds[0]->bindUniformBuffers.standaloneUniformsBufferBinding;
583 // based on reflection, issue gl calls
584 buffer.buffer->BindAsUniformBuffer( static_cast<const TestGraphicsProgram*>(pipeline->programState.program) );
587 auto drawCmds = commandBuffer->GetCommandsByType( 0 |
589 CommandType::DRAW_INDEXED_INDIRECT |
590 CommandType::DRAW_INDEXED );
592 if(!drawCmds.empty())
594 if (drawCmds[0]->draw.type == DrawCallDescriptor::Type::DRAW_INDEXED )
596 mGl.DrawElements(GetTopology(topology),
597 static_cast<GLsizei>(drawCmds[0]->draw.drawIndexed.indexCount),
599 reinterpret_cast<void *>(drawCmds[0]->draw.drawIndexed.firstIndex));
603 mGl.DrawArrays(GetTopology(topology), 0, drawCmds[0]->draw.draw.vertexCount);
607 for (auto &attribute : vi.attributes)
609 mGl.DisableVertexAttribArray(attribute.location);
616 * @brief Presents render target
617 * @param renderTarget render target to present
619 void TestGraphicsController::PresentRenderTarget(Graphics::RenderTarget* renderTarget)
621 TraceCallStack::NamedParams namedParams;
622 namedParams["renderTarget"] << std::hex << renderTarget;
623 mCallStack.PushCall("PresentRenderTarget", "", namedParams);
627 * @brief Waits until the GPU is idle
629 void TestGraphicsController::WaitIdle()
631 mCallStack.PushCall("WaitIdle", "");
635 * @brief Lifecycle pause event
637 void TestGraphicsController::Pause()
639 mCallStack.PushCall("Pause", "");
643 * @brief Lifecycle resume event
645 void TestGraphicsController::Resume()
647 mCallStack.PushCall("Resume", "");
650 void TestGraphicsController::UpdateTextures(const std::vector<Graphics::TextureUpdateInfo>& updateInfoList,
651 const std::vector<Graphics::TextureUpdateSourceInfo>& sourceList)
653 TraceCallStack::NamedParams namedParams;
654 namedParams["updateInfoList"] << "[" << updateInfoList.size() << "]:";
655 namedParams["sourceList"] << "[" << sourceList.size() << "]:";
657 mCallStack.PushCall("UpdateTextures", "", namedParams);
659 // Call either TexImage2D or TexSubImage2D
660 for(unsigned int i = 0; i < updateInfoList.size(); ++i)
662 auto& updateInfo = updateInfoList[i];
663 auto& source = sourceList[i];
665 auto texture = static_cast<TestGraphicsTexture*>(updateInfo.dstTexture);
666 texture->Bind(0); // Use first texture unit during resource update
667 texture->Update(updateInfo, source);
671 bool TestGraphicsController::EnableDepthStencilBuffer(bool enableDepth, bool enableStencil)
673 TraceCallStack::NamedParams namedParams;
674 namedParams["enableDepth"] << (enableDepth ? "T" : "F");
675 namedParams["enableStencil"] << (enableStencil ? "T" : "F");
676 mCallStack.PushCall("EnableDepthStencilBuffer", "", namedParams);
680 void TestGraphicsController::RunGarbageCollector(size_t numberOfDiscardedRenderers)
682 TraceCallStack::NamedParams namedParams;
683 namedParams["numberOfDiscardedRenderers"] << numberOfDiscardedRenderers;
684 mCallStack.PushCall("RunGarbageCollector", "", namedParams);
687 void TestGraphicsController::DiscardUnusedResources()
689 mCallStack.PushCall("DiscardUnusedResources", "");
692 bool TestGraphicsController::IsDiscardQueueEmpty()
694 mCallStack.PushCall("IsDiscardQueueEmpty", "");
695 return isDiscardQueueEmptyResult;
699 * @brief Test if the graphics subsystem has resumed & should force a draw
701 * @return true if the graphics subsystem requires a re-draw
703 bool TestGraphicsController::IsDrawOnResumeRequired()
705 mCallStack.PushCall("IsDrawOnResumeRequired", "");
706 return isDrawOnResumeRequiredResult;
709 Graphics::UniquePtr<Graphics::Buffer> TestGraphicsController::CreateBuffer(const Graphics::BufferCreateInfo& createInfo, Graphics::UniquePtr<Graphics::Buffer>&& oldBuffer)
711 std::ostringstream oss;
712 oss << "bufferCreateInfo:" << createInfo;
713 mCallStack.PushCall("CreateBuffer", oss.str());
714 return Graphics::MakeUnique<TestGraphicsBuffer>(mCallStack, mGl, createInfo.size, createInfo.usage);
717 Graphics::UniquePtr<Graphics::CommandBuffer> TestGraphicsController::CreateCommandBuffer(const Graphics::CommandBufferCreateInfo& commandBufferCreateInfo, Graphics::UniquePtr<Graphics::CommandBuffer>&& oldCommandBuffer)
719 std::ostringstream oss;
720 oss << "commandBufferCreateInfo:" << commandBufferCreateInfo;
721 mCallStack.PushCall("CreateCommandBuffer", oss.str());
722 return Graphics::MakeUnique<TestGraphicsCommandBuffer>(mCommandBufferCallStack, mGl);
725 Graphics::UniquePtr<Graphics::RenderPass> TestGraphicsController::CreateRenderPass(const Graphics::RenderPassCreateInfo& renderPassCreateInfo, Graphics::UniquePtr<Graphics::RenderPass>&& oldRenderPass)
727 mCallStack.PushCall("CreateRenderPass", "");
731 Graphics::UniquePtr<Graphics::Texture> TestGraphicsController::CreateTexture(const Graphics::TextureCreateInfo& textureCreateInfo, Graphics::UniquePtr<Graphics::Texture>&& oldTexture)
733 TraceCallStack::NamedParams namedParams;
734 namedParams["textureCreateInfo"] << textureCreateInfo;
735 mCallStack.PushCall("CreateTexture", namedParams.str(), namedParams);
737 return Graphics::MakeUnique<TestGraphicsTexture>(mGl, textureCreateInfo);
740 Graphics::UniquePtr<Graphics::Framebuffer> TestGraphicsController::CreateFramebuffer(const Graphics::FramebufferCreateInfo& framebufferCreateInfo, Graphics::UniquePtr<Graphics::Framebuffer>&& oldFramebuffer)
742 mCallStack.PushCall("CreateFramebuffer", "");
746 Graphics::UniquePtr<Graphics::Pipeline> TestGraphicsController::CreatePipeline(const Graphics::PipelineCreateInfo& pipelineCreateInfo, Graphics::UniquePtr<Graphics::Pipeline>&& oldPipeline)
748 mCallStack.PushCall("CreatePipeline", "");
749 return std::make_unique<TestGraphicsPipeline>(mGl, pipelineCreateInfo);
752 Graphics::UniquePtr<Graphics::Program> TestGraphicsController::CreateProgram(const Graphics::ProgramCreateInfo& programCreateInfo, Graphics::UniquePtr<Graphics::Program>&& oldProgram)
754 mCallStack.PushCall("CreateProgram", "");
756 for(auto cacheEntry : mProgramCache)
759 for(auto& shader : *(programCreateInfo.shaderState))
761 auto graphicsShader = Uncast<TestGraphicsShader>(shader.shader);
762 std::vector<uint8_t> source;
763 source.resize(graphicsShader->mCreateInfo.sourceSize);
764 memcpy(&source[0], graphicsShader->mCreateInfo.sourceData, graphicsShader->mCreateInfo.sourceSize);
766 if(!std::equal(source.begin(), source.end(), cacheEntry.shaders[shader.pipelineStage].begin()))
774 return Graphics::MakeUnique<TestGraphicsProgram>(cacheEntry.programImpl);
778 mProgramCache.emplace_back();
779 mProgramCache.back().programImpl = new TestGraphicsProgramImpl(mGl, programCreateInfo, mVertexFormats, mCustomUniforms);
780 for(auto& shader : *(programCreateInfo.shaderState))
782 auto graphicsShader = Uncast<TestGraphicsShader>(shader.shader);
783 mProgramCache.back().shaders[shader.pipelineStage].resize( graphicsShader->mCreateInfo.sourceSize );
784 memcpy(&mProgramCache.back().shaders[shader.pipelineStage][0], graphicsShader->mCreateInfo.sourceData, graphicsShader->mCreateInfo.sourceSize);
786 return Graphics::MakeUnique<TestGraphicsProgram>(mProgramCache.back().programImpl);
789 Graphics::UniquePtr<Graphics::Shader> TestGraphicsController::CreateShader(const Graphics::ShaderCreateInfo& shaderCreateInfo, Graphics::UniquePtr<Graphics::Shader>&& oldShader)
791 mCallStack.PushCall("CreateShader", "");
792 return Graphics::MakeUnique<TestGraphicsShader>(mGl, shaderCreateInfo);
795 Graphics::UniquePtr<Graphics::Sampler> TestGraphicsController::CreateSampler(const Graphics::SamplerCreateInfo& samplerCreateInfo, Graphics::UniquePtr<Graphics::Sampler>&& oldSampler)
797 TraceCallStack::NamedParams namedParams;
798 namedParams["samplerCreateInfo"] << samplerCreateInfo;
799 mCallStack.PushCall("CreateSampler", namedParams.str(), namedParams);
801 return Graphics::MakeUnique<TestGraphicsSampler>(mGl, samplerCreateInfo);
804 Graphics::UniquePtr<Graphics::RenderTarget> TestGraphicsController::CreateRenderTarget(const Graphics::RenderTargetCreateInfo& renderTargetCreateInfo, Graphics::UniquePtr<Graphics::RenderTarget>&& oldRenderTarget)
806 mCallStack.PushCall("CreateRenderTarget", "");
810 Graphics::UniquePtr<Graphics::Memory> TestGraphicsController::MapBufferRange(const Graphics::MapBufferInfo& mapInfo)
812 mCallStack.PushCall("MapBufferRange", "");
814 auto buffer = static_cast<TestGraphicsBuffer*>(mapInfo.buffer);
815 buffer->memory.resize(mapInfo.offset + mapInfo.size); // For initial testing, allow writes past capacity
817 return std::make_unique<TestGraphicsMemory>(mCallStack, *buffer, mapInfo.offset, mapInfo.size);
820 Graphics::UniquePtr<Graphics::Memory> TestGraphicsController::MapTextureRange(const Graphics::MapTextureInfo& mapInfo)
822 mCallStack.PushCall("MapTextureRange", "");
826 void TestGraphicsController::UnmapMemory(Graphics::UniquePtr<Graphics::Memory> memory)
828 mCallStack.PushCall("UnmapMemory", "");
831 Graphics::MemoryRequirements TestGraphicsController::GetTextureMemoryRequirements(Graphics::Texture& texture) const
833 mCallStack.PushCall("GetTextureMemoryRequirements", "");
834 return Graphics::MemoryRequirements{};
837 Graphics::MemoryRequirements TestGraphicsController::GetBufferMemoryRequirements(Graphics::Buffer& buffer) const
839 mCallStack.PushCall("GetBufferMemoryRequirements", "");
840 return Graphics::MemoryRequirements{};
843 const Graphics::TextureProperties& TestGraphicsController::GetTextureProperties(const Graphics::Texture& texture)
845 static Graphics::TextureProperties textureProperties{};
846 mCallStack.PushCall("GetTextureProperties", "");
848 return textureProperties;
851 const Graphics::Reflection& TestGraphicsController::GetProgramReflection(const Graphics::Program& program)
853 mCallStack.PushCall("GetProgramReflection", "");
855 return static_cast<const TestGraphicsProgram*>(&program)->GetReflection();
858 bool TestGraphicsController::PipelineEquals(const Graphics::Pipeline& pipeline0, const Graphics::Pipeline& pipeline1) const
860 mCallStack.PushCall("PipelineEquals", "");
864 bool TestGraphicsController::GetProgramParameter(Graphics::Program& program, uint32_t parameterId, void* outData)
866 mCallStack.PushCall("GetProgramParameter", "");
867 auto graphicsProgram = Uncast<TestGraphicsProgram>(&program);
868 return graphicsProgram->GetParameter(parameterId, outData);