summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorAnders Leino <aleino@nvidia.com>2024-12-18 14:39:17 +0200
committerGitHub <noreply@github.com>2024-12-18 12:39:17 +0000
commit41c627fd420a644f0ae86e36f4752e820e2d683c (patch)
tree03c7f119271eec616cf192b573b2487d5b1c2df3 /examples
parent45af2467289bd39baff0269bb7de8a538f617dec (diff)
Add slang example tests to CI (#5879)
* Examples: Don't proceed if 'initializeBase' fails * Examples: Only access gWindow if it's been initialized * Examples: Free memory from CommandLineToArgvW * Add example run step to CI Lots of examples are still unexpectedly failing, but is one small step towards addressing issue #5520.
Diffstat (limited to 'examples')
-rw-r--r--examples/autodiff-texture/main.cpp2
-rw-r--r--examples/example-base/test-base.cpp5
-rw-r--r--examples/model-viewer/main.cpp2
-rw-r--r--examples/platform-test/main.cpp37
-rw-r--r--examples/ray-tracing-pipeline/main.cpp2
-rw-r--r--examples/ray-tracing/main.cpp2
-rw-r--r--examples/shader-toy/main.cpp22
-rw-r--r--examples/triangle/main.cpp2
8 files changed, 51 insertions, 23 deletions
diff --git a/examples/autodiff-texture/main.cpp b/examples/autodiff-texture/main.cpp
index 647929e70..d0c35d003 100644
--- a/examples/autodiff-texture/main.cpp
+++ b/examples/autodiff-texture/main.cpp
@@ -285,7 +285,7 @@ struct AutoDiffTexture : public WindowedAppBase
}
Slang::Result initialize()
{
- initializeBase("autodiff-texture", 1024, 768);
+ SLANG_RETURN_ON_FAIL(initializeBase("autodiff-texture", 1024, 768));
srand(20421);
if (!isTestMode())
diff --git a/examples/example-base/test-base.cpp b/examples/example-base/test-base.cpp
index 5d40f2d80..bfbfd6b15 100644
--- a/examples/example-base/test-base.cpp
+++ b/examples/example-base/test-base.cpp
@@ -27,6 +27,11 @@ int TestBase::parseOption(int argc, char** argv)
m_isTestMode = true;
}
}
+
+#ifdef _WIN32
+ LocalFree(szArglist);
+#endif
+
return 0;
}
diff --git a/examples/model-viewer/main.cpp b/examples/model-viewer/main.cpp
index 8b75381be..ecca818f1 100644
--- a/examples/model-viewer/main.cpp
+++ b/examples/model-viewer/main.cpp
@@ -745,7 +745,7 @@ struct ModelViewer : WindowedAppBase
//
Result initialize()
{
- initializeBase("Model Viewer", 1024, 768);
+ SLANG_RETURN_ON_FAIL(initializeBase("Model Viewer", 1024, 768));
if (!isTestMode())
{
gWindow->events.mouseMove = [this](const platform::MouseEventArgs& e)
diff --git a/examples/platform-test/main.cpp b/examples/platform-test/main.cpp
index 373c15e09..159e26c55 100644
--- a/examples/platform-test/main.cpp
+++ b/examples/platform-test/main.cpp
@@ -71,18 +71,26 @@ struct PlatformTest : public WindowedAppBase
Slang::Result initialize()
{
- initializeBase("platform-test", 1024, 768);
-
- gWindow->events.sizeChanged = [this]() { onSizeChanged(); };
- gWindow->events.focus = [this]() { onFocus(); };
- gWindow->events.lostFocus = [this]() { onLostFocus(); };
- gWindow->events.keyDown = [this](const platform::KeyEventArgs& e) { onKeyDown(e); };
- gWindow->events.keyUp = [this](const platform::KeyEventArgs& e) { onKeyUp(e); };
- gWindow->events.keyPress = [this](const platform::KeyEventArgs& e) { onKeyPress(e); };
- gWindow->events.mouseMove = [this](const platform::MouseEventArgs& e) { onMouseMove(e); };
- gWindow->events.mouseDown = [this](const platform::MouseEventArgs& e) { onMouseDown(e); };
- gWindow->events.mouseUp = [this](const platform::MouseEventArgs& e) { onMouseUp(e); };
- gWindow->events.mouseWheel = [this](const platform::MouseEventArgs& e) { onMouseWheel(e); };
+ SLANG_RETURN_ON_FAIL(initializeBase("platform-test", 1024, 768));
+
+ // We may not have a window if we're running in test mode
+ SLANG_ASSERT(isTestMode() || gWindow);
+ if (gWindow)
+ {
+ gWindow->events.sizeChanged = [this]() { onSizeChanged(); };
+ gWindow->events.focus = [this]() { onFocus(); };
+ gWindow->events.lostFocus = [this]() { onLostFocus(); };
+ gWindow->events.keyDown = [this](const platform::KeyEventArgs& e) { onKeyDown(e); };
+ gWindow->events.keyUp = [this](const platform::KeyEventArgs& e) { onKeyUp(e); };
+ gWindow->events.keyPress = [this](const platform::KeyEventArgs& e) { onKeyPress(e); };
+ gWindow->events.mouseMove = [this](const platform::MouseEventArgs& e)
+ { onMouseMove(e); };
+ gWindow->events.mouseDown = [this](const platform::MouseEventArgs& e)
+ { onMouseDown(e); };
+ gWindow->events.mouseUp = [this](const platform::MouseEventArgs& e) { onMouseUp(e); };
+ gWindow->events.mouseWheel = [this](const platform::MouseEventArgs& e)
+ { onMouseWheel(e); };
+ }
return SLANG_OK;
}
@@ -105,7 +113,10 @@ struct PlatformTest : public WindowedAppBase
commandBuffer->close();
gQueue->executeCommandBuffer(commandBuffer);
- gSwapchain->present();
+ // We may not have a swapchain if we're running in test mode
+ SLANG_ASSERT(isTestMode() || gSwapchain);
+ if (gSwapchain)
+ gSwapchain->present();
}
};
diff --git a/examples/ray-tracing-pipeline/main.cpp b/examples/ray-tracing-pipeline/main.cpp
index 1e55c7eb1..0fbb857f0 100644
--- a/examples/ray-tracing-pipeline/main.cpp
+++ b/examples/ray-tracing-pipeline/main.cpp
@@ -298,7 +298,7 @@ struct RayTracing : public WindowedAppBase
Slang::Result initialize()
{
- initializeBase("Ray Tracing Pipeline", 1024, 768);
+ SLANG_RETURN_ON_FAIL(initializeBase("Ray Tracing Pipeline", 1024, 768));
if (!isTestMode())
{
gWindow->events.mouseMove = [this](const platform::MouseEventArgs& e)
diff --git a/examples/ray-tracing/main.cpp b/examples/ray-tracing/main.cpp
index 7878550f8..11529a753 100644
--- a/examples/ray-tracing/main.cpp
+++ b/examples/ray-tracing/main.cpp
@@ -289,7 +289,7 @@ struct RayTracing : public WindowedAppBase
Slang::Result initialize()
{
- initializeBase("Ray Tracing", 1024, 768);
+ SLANG_RETURN_ON_FAIL(initializeBase("Ray Tracing", 1024, 768));
if (!isTestMode())
{
diff --git a/examples/shader-toy/main.cpp b/examples/shader-toy/main.cpp
index 1ab85c0b2..185d18246 100644
--- a/examples/shader-toy/main.cpp
+++ b/examples/shader-toy/main.cpp
@@ -282,10 +282,18 @@ struct ShaderToyApp : public WindowedAppBase
Result initialize()
{
- initializeBase("Shader Toy", 1024, 768);
- gWindow->events.mouseMove = [this](const platform::MouseEventArgs& e) { handleEvent(e); };
- gWindow->events.mouseUp = [this](const platform::MouseEventArgs& e) { handleEvent(e); };
- gWindow->events.mouseDown = [this](const platform::MouseEventArgs& e) { handleEvent(e); };
+ SLANG_RETURN_ON_FAIL(initializeBase("Shader Toy", 1024, 768));
+
+ // We may not have a window if we're running in test mode
+ SLANG_ASSERT(isTestMode() || gWindow);
+ if (gWindow)
+ {
+ gWindow->events.mouseMove = [this](const platform::MouseEventArgs& e)
+ { handleEvent(e); };
+ gWindow->events.mouseUp = [this](const platform::MouseEventArgs& e) { handleEvent(e); };
+ gWindow->events.mouseDown = [this](const platform::MouseEventArgs& e)
+ { handleEvent(e); };
+ }
InputElementDesc inputElements[] = {
{"POSITION", 0, Format::R32G32_FLOAT, offsetof(FullScreenTriangle::Vertex, position)},
@@ -383,7 +391,11 @@ struct ShaderToyApp : public WindowedAppBase
commandBuffer->close();
gQueue->executeCommandBuffer(commandBuffer);
- gSwapchain->present();
+
+ // We may not have a swapchain if we're running in test mode
+ SLANG_ASSERT(isTestMode() || gSwapchain);
+ if (gSwapchain)
+ gSwapchain->present();
}
void handleEvent(const platform::MouseEventArgs& event)
diff --git a/examples/triangle/main.cpp b/examples/triangle/main.cpp
index e77f488cc..f757b59c7 100644
--- a/examples/triangle/main.cpp
+++ b/examples/triangle/main.cpp
@@ -223,7 +223,7 @@ struct HelloWorld : public WindowedAppBase
{
// Create a window for our application to render into.
//
- initializeBase("hello-world", 1024, 768);
+ SLANG_RETURN_ON_FAIL(initializeBase("hello-world", 1024, 768));
// We will create objects needed to configur the "input assembler"
// (IA) stage of the D3D pipeline.