diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2018-12-12 08:57:48 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-12-12 08:57:48 -0500 |
| commit | 49ed6b60d662906f290578f802f80b0ead1a2b9d (patch) | |
| tree | e47050f6508a4b3a4d38b756e9b3c53e0d159507 /tools/render-test/main.cpp | |
| parent | 62d3e387774255be4d507cca045ac97dabac9970 (diff) | |
Running tests in slang-test process (#740)
* First pass at having an interface to write text to that can be replaced.
Simplifed and made more rigerous the interface used to write formatted strings.
* Added AppContext to simplify setting up and parsing around of streams.
* Added more simplified way to get the std error/out from AppContext.
* Work in progress using dll for tools to speed up testing.
* First pass at ISlangWriter interface.
* Added support for writing VaArgs.
Added NullWriter.
* Use ISlangWriter for output.
* Use ISlangWriter for output - replacing OutputCallback.
Make IRDump go to ISlangWriter
* SlangWriterTargetType -> SlangWriterChannel
Improvements around AppContext
* Shared library working with slang-reflection-test.
* Dll testing working for render-test.
* Include va_list definintion from header.
* Fix errors from clang.
* Fix typo for linux.
* Added -usexes option
* Fix typo.
* Fix arguments problem on linux.
* Fix typo for linux.
* Add windows tool shared library projects.
* Fix warning from x86 win build.
Fix signed warning from slang-test/main.cpp
* First attempt at getting premake to work on travis, and run tests.
* Try moving build out into script.
* Invoke bash scripts so they don't have to be executable.
* Drive configuration/tests from env parameters set by travis
* Try using source to run travis tests.
* Remove the build.linux directory - but doing so will overwrite Makefile.
* Made -fno-delete-null-pointer-checks gcc only.
* Try to fix warning from -fno-delete-null-pointer-checks
* Turn of warnings for unknown switches.
* Try to make premake choose the correct tooling.
* Disabled missing braces warning.
* Disable -Wundefined-var-template on clang.
* -Wunused-function disabled for clang.
* Fix typo due to SlangBool.
* Remove this nullptr tests.
* "-Wno-unused-private-field" for clang.
* Added "-Wno-undefined-bool-conversion"
* Add DominatorList::end fix.
* Split scripts into travis_build.sh travis_test.sh
* Fix gcc/clang template pre-declaration issue around QualType.
* Fix premake to build such that pthread correctly links with slang-glslang
Diffstat (limited to 'tools/render-test/main.cpp')
| -rw-r--r-- | tools/render-test/main.cpp | 235 |
1 files changed, 153 insertions, 82 deletions
diff --git a/tools/render-test/main.cpp b/tools/render-test/main.cpp index 93de67907..631085c2b 100644 --- a/tools/render-test/main.cpp +++ b/tools/render-test/main.cpp @@ -17,6 +17,8 @@ #include <stdio.h> #include <stdlib.h> +#include "../../source/core/slang-app-context.h" + #define WIN32_LEAN_AND_MEAN #define NOMINMAX #include <Windows.h> @@ -34,6 +36,141 @@ using Slang::Result; int gWindowWidth = 1024; int gWindowHeight = 768; +class Window: public RefObject +{ +public: + SlangResult initialize(int width, int height); + + void show(); + + void* getHandle() const { return m_hwnd; } + + Window() {} + ~Window(); + + static LRESULT CALLBACK windowProc(HWND windowHandle, + UINT message, + WPARAM wParam, + LPARAM lParam); + +protected: + + HINSTANCE m_hinst = nullptr; + HWND m_hwnd = nullptr; +}; + +// +// We use a bare-minimum window procedure to get things up and running. +// + +/* static */LRESULT CALLBACK Window::windowProc( + HWND windowHandle, + UINT message, + WPARAM wParam, + LPARAM lParam) +{ + switch (message) + { + case WM_CLOSE: + PostQuitMessage(0); + return 0; + } + + return DefWindowProcW(windowHandle, message, wParam, lParam); +} + +static ATOM _getWindowClassAtom(HINSTANCE hinst) +{ + static ATOM s_windowClassAtom; + + if (s_windowClassAtom) + { + return s_windowClassAtom; + } + WNDCLASSEXW windowClassDesc; + windowClassDesc.cbSize = sizeof(windowClassDesc); + windowClassDesc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW; + windowClassDesc.lpfnWndProc = &Window::windowProc; + windowClassDesc.cbClsExtra = 0; + windowClassDesc.cbWndExtra = 0; + windowClassDesc.hInstance = hinst; + windowClassDesc.hIcon = 0; + windowClassDesc.hCursor = 0; + windowClassDesc.hbrBackground = 0; + windowClassDesc.lpszMenuName = 0; + windowClassDesc.lpszClassName = L"SlangRenderTest"; + windowClassDesc.hIconSm = 0; + s_windowClassAtom = RegisterClassExW(&windowClassDesc); + + return s_windowClassAtom; +} + +SlangResult Window::initialize(int widthIn, int heightIn) +{ + // Do initial window-creation stuff here, rather than in the renderer-specific files + + m_hinst = GetModuleHandleA(0); + + // First we register a window class. + ATOM windowClassAtom = _getWindowClassAtom(m_hinst); + if (!windowClassAtom) + { + fprintf(stderr, "error: failed to register window class\n"); + return SLANG_FAIL; + } + + // Next, we create a window using that window class. + + // We will create a borderless window since our screen-capture logic in GL + // seems to get thrown off by having to deal with a window frame. + DWORD windowStyle = WS_POPUP; + DWORD windowExtendedStyle = 0; + + RECT windowRect = { 0, 0, widthIn, heightIn }; + AdjustWindowRectEx(&windowRect, windowStyle, /*hasMenu=*/false, windowExtendedStyle); + + { + auto width = windowRect.right - windowRect.left; + auto height = windowRect.bottom - windowRect.top; + + LPWSTR windowName = L"Slang Render Test"; + m_hwnd = CreateWindowExW( + windowExtendedStyle, + (LPWSTR)windowClassAtom, + windowName, + windowStyle, + 0, 0, // x, y + width, height, + NULL, // parent + NULL, // menu + m_hinst, + NULL); + } + if (!m_hwnd) + { + fprintf(stderr, "error: failed to create window\n"); + return SLANG_FAIL; + } + + return SLANG_OK; +} + + +void Window::show() +{ + // Once initialization is all complete, we show the window... + int showCommand = SW_SHOW; + ShowWindow(m_hwnd, showCommand); +} + +Window::~Window() +{ + if (m_hwnd) + { + DestroyWindow(m_hwnd); + } +} + // // For the purposes of a small example, we will define the vertex data for a // single triangle directly in the source file. It should be easy to extend @@ -355,88 +492,20 @@ Result RenderTestApp::writeScreen(const char* filename) return PngSerializeUtil::write(filename, surface); } -// -// We use a bare-minimum window procedure to get things up and running. -// +} // namespace renderer_test -static LRESULT CALLBACK windowProc( - HWND windowHandle, - UINT message, - WPARAM wParam, - LPARAM lParam) +SLANG_SHARED_LIBRARY_TOOL_API SlangResult innerMain(Slang::AppContext* appContext, SlangSession* session, int argcIn, const char*const* argvIn) { - switch (message) - { - case WM_CLOSE: - PostQuitMessage(0); - return 0; - } + using namespace renderer_test; + using namespace Slang; - return DefWindowProcW(windowHandle, message, wParam, lParam); -} + AppContext::setSingleton(appContext); -SlangResult innerMain(int argc, char** argv) -{ // Parse command-line options - SLANG_RETURN_ON_FAIL(parseOptions(&argc, argv)); - - // Do initial window-creation stuff here, rather than in the renderer-specific files - - HINSTANCE instance = GetModuleHandleA(0); - int showCommand = SW_SHOW; - - // First we register a window class. - - WNDCLASSEXW windowClassDesc; - windowClassDesc.cbSize = sizeof(windowClassDesc); - windowClassDesc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW; - windowClassDesc.lpfnWndProc = &windowProc; - windowClassDesc.cbClsExtra = 0; - windowClassDesc.cbWndExtra = 0; - windowClassDesc.hInstance = instance; - windowClassDesc.hIcon = 0; - windowClassDesc.hCursor = 0; - windowClassDesc.hbrBackground = 0; - windowClassDesc.lpszMenuName = 0; - windowClassDesc.lpszClassName = L"HelloWorld"; - windowClassDesc.hIconSm = 0; - ATOM windowClassAtom = RegisterClassExW(&windowClassDesc); - if (!windowClassAtom) - { - fprintf(stderr, "error: failed to register window class\n"); - return SLANG_FAIL; - } + SLANG_RETURN_ON_FAIL(parseOptions(argcIn, argvIn, AppContext::getStdError())); - // Next, we create a window using that window class. - - // We will create a borderless window since our screen-capture logic in GL - // seems to get thrown off by having to deal with a window frame. - DWORD windowStyle = WS_POPUP; - DWORD windowExtendedStyle = 0; - - RECT windowRect = { 0, 0, gWindowWidth, gWindowHeight }; - AdjustWindowRectEx(&windowRect, windowStyle, /*hasMenu=*/false, windowExtendedStyle); - - auto width = windowRect.right - windowRect.left; - auto height = windowRect.bottom - windowRect.top; - - LPWSTR windowName = L"Slang Render Test"; - HWND windowHandle = CreateWindowExW( - windowExtendedStyle, - (LPWSTR)windowClassAtom, - windowName, - windowStyle, - 0, 0, // x, y - width, height, - NULL, // parent - NULL, // menu - instance, - NULL); - if (!windowHandle) - { - fprintf(stderr, "error: failed to create window\n"); - return SLANG_FAIL; - } + RefPtr<renderer_test::Window> window(new renderer_test::Window); + SLANG_RETURN_ON_FAIL(window->initialize(gWindowWidth, gWindowHeight)); Slang::RefPtr<Renderer> renderer; @@ -500,7 +569,7 @@ SlangResult innerMain(int argc, char** argv) desc.height = gWindowHeight; { - Result res = renderer->initialize(desc, windowHandle); + SlangResult res = renderer->initialize(desc, (HWND)window->getHandle()); if (SLANG_FAILED(res)) { fprintf(stderr, "Unable to initialize renderer\n"); @@ -512,6 +581,8 @@ SlangResult innerMain(int argc, char** argv) shaderCompiler.renderer = renderer; shaderCompiler.target = slangTarget; shaderCompiler.profile = profileName; + shaderCompiler.slangSession = session; + switch (gOptions.inputLanguageID) { case Options::InputLanguageID::Slang: @@ -533,8 +604,7 @@ SlangResult innerMain(int argc, char** argv) SLANG_RETURN_ON_FAIL(app.initialize(renderer, &shaderCompiler)); - // Once initialization is all complete, we show the window... - ShowWindow(windowHandle, showCommand); + window->show(); // ... and enter the event loop: for (;;) @@ -581,7 +651,7 @@ SlangResult innerMain(int argc, char** argv) } else { - Result res = app.writeScreen(gOptions.outputPath); + SlangResult res = app.writeScreen(gOptions.outputPath); if (SLANG_FAILED(res)) { @@ -600,11 +670,12 @@ SlangResult innerMain(int argc, char** argv) return SLANG_OK; } -} // namespace renderer_test int main(int argc, char** argv) { - SlangResult res = renderer_test::innerMain(argc, argv); + SlangSession* session = spCreateSession(nullptr); + SlangResult res = innerMain(Slang::AppContext::initDefault(), session, argc, argv); + spDestroySession(session); return SLANG_FAILED(res) ? 1 : 0; } |
