From b5bb82411cc6101b66283f7d0abca7ceb58aa2f6 Mon Sep 17 00:00:00 2001 From: kaizhangNV <149626564+kaizhangNV@users.noreply.github.com> Date: Thu, 22 Aug 2024 12:18:44 -0500 Subject: Feature/capture unit test (#4898) * record/replay: Add tests Modify the hello-world example to generate the hash code for the entry point spirv code, so that we can compare it with replaying the example. Add the test script to run the example and compare the hash code with replaying it. * Check nullptr for out Diagnostics We need to check whether the output Diagnostics is a nullptr, because it's allowed. * Fix the double free pointers * Add triangle example as the new test for record-replay Change the example base to add the offline rendering path because we don't want to display anything when we're in the test mode. This change involves introducing a TestBase that will parse the command line option. It will decide whether we are in the test mode. Disable all the swapchain and windows related creation, instead we will only create one single framebuffer for the render target. * Address comments TODO: In the follow up patches, I will add more tests and integrate the test flow into slang-unit-test. --- examples/example-base/example-base.h | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'examples/example-base/example-base.h') diff --git a/examples/example-base/example-base.h b/examples/example-base/example-base.h index 8943323da..b97728e17 100644 --- a/examples/example-base/example-base.h +++ b/examples/example-base/example-base.h @@ -4,12 +4,13 @@ #include "tools/platform/window.h" #include "source/core/slang-basic.h" #include "source/core/slang-io.h" +#include "test-base.h" #ifdef _WIN32 void _Win32OutputDebugString(const char* str); #endif -struct WindowedAppBase +struct WindowedAppBase : public TestBase { protected: static const int kSwapchainImageCount = 2; @@ -32,8 +33,13 @@ protected: int width, int height, gfx::DeviceType deviceType = gfx::DeviceType::Default); + + void createFramebuffers(uint32_t width, uint32_t height, gfx::Format colorFormat, uint32_t frameBufferCount); void createSwapchainFramebuffers(); + void createOfflineFramebuffers(); + void mainLoop(); + Slang::ComPtr createTextureFromFile(Slang::String fileName, int& textureWidth, int& textureHeight); virtual void windowSizeChanged(); @@ -42,6 +48,7 @@ protected: public: platform::Window* getWindow() { return gWindow.Ptr(); } virtual void finalize() { gQueue->waitOnHost(); } + void offlineRender(); }; struct ExampleResources { @@ -103,18 +110,26 @@ inline void diagnoseIfNeeded(slang::IBlob* diagnosticsBlob) void initDebugCallback(); template -int innerMain() +int innerMain(int argc, char** argv) { initDebugCallback(); TApp app; + app.parseOption(argc, argv); if (SLANG_FAILED(app.initialize())) { return -1; } - platform::Application::run(app.getWindow()); + if (!app.isTestMode()) + { + platform::Application::run(app.getWindow()); + } + else + { + app.offlineRender(); + } app.finalize(); return 0; -- cgit v1.2.3