From 49ed6b60d662906f290578f802f80b0ead1a2b9d Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Wed, 12 Dec 2018 08:57:48 -0500 Subject: 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 --- tools/render-test/main.cpp | 235 ++++++++++++++------- tools/render-test/options.cpp | 46 ++-- tools/render-test/options.h | 5 +- .../render-test/render-test-shared-library.vcxproj | 210 ++++++++++++++++++ .../render-test-shared-library.vcxproj.filters | 48 +++++ tools/render-test/shader-renderer-util.cpp | 2 +- tools/render-test/slang-support.cpp | 4 +- tools/render-test/slang-support.h | 5 +- 8 files changed, 443 insertions(+), 112 deletions(-) create mode 100644 tools/render-test/render-test-shared-library.vcxproj create mode 100644 tools/render-test/render-test-shared-library.vcxproj.filters (limited to 'tools/render-test') 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 #include +#include "../../source/core/slang-app-context.h" + #define WIN32_LEAN_AND_MEAN #define NOMINMAX #include @@ -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 window(new renderer_test::Window); + SLANG_RETURN_ON_FAIL(window->initialize(gWindowWidth, gWindowHeight)); Slang::RefPtr 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; } diff --git a/tools/render-test/options.cpp b/tools/render-test/options.cpp index d99ba355e..bd5640020 100644 --- a/tools/render-test/options.cpp +++ b/tools/render-test/options.cpp @@ -6,8 +6,12 @@ #include #include +#include "../../source/core/slang-writer.h" + namespace renderer_test { +static const Options gDefaultOptions; + Options gOptions; // Only set it, if the @@ -16,17 +20,20 @@ void setDefaultRendererType(RendererType type) gOptions.rendererType = (gOptions.rendererType == RendererType::Unknown) ? type : gOptions.rendererType; } -SlangResult parseOptions(int* argc, char** argv) +SlangResult parseOptions(int argc, const char*const* argv, Slang::WriterHelper stdError) { + // Reset the options + gOptions = gDefaultOptions; + + List positionalArgs; + typedef Options::ShaderProgramType ShaderProgramType; typedef Options::InputLanguageID InputLanguageID; + //int argCount = argc; - int argCount = *argc; char const* const* argCursor = argv; - char const* const* argEnd = argCursor + argCount; - - char const** writeCursor = (char const**) argv; + char const* const* argEnd = argCursor + argc; // first argument is the application name if( argCursor != argEnd ) @@ -40,7 +47,7 @@ SlangResult parseOptions(int* argc, char** argv) char const* arg = *argCursor++; if( arg[0] != '-' ) { - *writeCursor++ = arg; + positionalArgs.Add(arg); continue; } @@ -48,8 +55,7 @@ SlangResult parseOptions(int* argc, char** argv) { while(argCursor != argEnd) { - char const* arg = *argCursor++; - *writeCursor++ = arg; + positionalArgs.Add(*argCursor++); } break; } @@ -57,7 +63,7 @@ SlangResult parseOptions(int* argc, char** argv) { if( argCursor == argEnd ) { - fprintf(stderr, "expected argument for '%s' option\n", arg); + stdError.print("expected argument for '%s' option\n", arg); return SLANG_FAIL; } gOptions.outputPath = *argCursor++; @@ -98,12 +104,12 @@ SlangResult parseOptions(int* argc, char** argv) if( argCursor == argEnd ) { - fprintf(stderr, "expected argument for '%s' option\n", arg); + stdError.print("expected argument for '%s' option\n", arg); return SLANG_FAIL; } if( gOptions.slangArgCount == Options::kMaxSlangArgs ) { - fprintf(stderr, "maximum number of '%s' options exceeded (%d)\n", arg, Options::kMaxSlangArgs); + stdError.print("maximum number of '%s' options exceeded (%d)\n", arg, Options::kMaxSlangArgs); return SLANG_FAIL; } gOptions.slangArgs[gOptions.slangArgCount++] = *argCursor++; @@ -145,30 +151,26 @@ SlangResult parseOptions(int* argc, char** argv) } else { - fprintf(stderr, "unknown option '%s'\n", arg); + stdError.print("unknown option '%s'\n", arg); return SLANG_FAIL; } } - // any arguments left over were positional arguments - argCount = (int)(writeCursor - (const char**)argv); - argCursor = argv; - argEnd = argCursor + argCount; - + // first positional argument is source shader path - if( argCursor != argEnd ) + if(positionalArgs.Count()) { - gOptions.sourcePath = *argCursor++; + gOptions.sourcePath = positionalArgs[0]; + positionalArgs.RemoveAt(0); } // any remaining arguments represent an error - if(argCursor != argEnd) + if(positionalArgs.Count() != 0) { - fprintf(stderr, "unexpected arguments\n"); + stdError.print("unexpected arguments\n"); return SLANG_FAIL; } - *argc = 0; return SLANG_OK; } diff --git a/tools/render-test/options.h b/tools/render-test/options.h index 76fdf95af..09721def3 100644 --- a/tools/render-test/options.h +++ b/tools/render-test/options.h @@ -1,9 +1,10 @@ -// options.h +// options.h #pragma once #include #include "../../slang-com-helper.h" +#include "../../source/core/slang-writer.h" #include "render.h" @@ -52,6 +53,6 @@ struct Options extern Options gOptions; -SlangResult parseOptions(int* argc, char** argv); +SlangResult parseOptions(int argc, const char*const* argv, Slang::WriterHelper stdError); } // renderer_test diff --git a/tools/render-test/render-test-shared-library.vcxproj b/tools/render-test/render-test-shared-library.vcxproj new file mode 100644 index 000000000..359a35b80 --- /dev/null +++ b/tools/render-test/render-test-shared-library.vcxproj @@ -0,0 +1,210 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {61F7EB00-7281-4BF3-9470-7C2EA92620C3} + true + Win32Proj + render-test-shared-library + 10.0.14393.0 + + + + DynamicLibrary + true + Unicode + v140 + + + DynamicLibrary + true + Unicode + v140 + + + DynamicLibrary + false + Unicode + v140 + + + DynamicLibrary + false + Unicode + v140 + + + + + + + + + + + + + + + + + + + true + ..\..\bin\windows-x86\debug\ + ..\..\intermediate\windows-x86\debug\render-test-shared-library\ + render-test-shared-library + .dll + + + true + ..\..\bin\windows-x64\debug\ + ..\..\intermediate\windows-x64\debug\render-test-shared-library\ + render-test-shared-library + .dll + + + false + ..\..\bin\windows-x86\release\ + ..\..\intermediate\windows-x86\release\render-test-shared-library\ + render-test-shared-library + .dll + + + false + ..\..\bin\windows-x64\release\ + ..\..\intermediate\windows-x64\release\render-test-shared-library\ + render-test-shared-library + .dll + + + + NotUsing + Level3 + _DEBUG;SLANG_SHARED_LIBRARY_TOOL;%(PreprocessorDefinitions) + ..\..;..\..\external;..\..\source;..\gfx;%(AdditionalIncludeDirectories) + EditAndContinue + Disabled + MultiThreadedDebug + + + Windows + true + ..\..\bin\windows-x86\debug\render-test-shared-library.lib + + + "$(SolutionDir)tools\copy-hlsl-libs.bat" "$(WindowsSdkDir)Redist/D3D/x86/" "../../bin/windows-x86/debug/" + + + + + NotUsing + Level3 + _DEBUG;SLANG_SHARED_LIBRARY_TOOL;%(PreprocessorDefinitions) + ..\..;..\..\external;..\..\source;..\gfx;%(AdditionalIncludeDirectories) + EditAndContinue + Disabled + MultiThreadedDebug + + + Windows + true + ..\..\bin\windows-x64\debug\render-test-shared-library.lib + + + "$(SolutionDir)tools\copy-hlsl-libs.bat" "$(WindowsSdkDir)Redist/D3D/x64/" "../../bin/windows-x64/debug/" + + + + + NotUsing + Level3 + NDEBUG;SLANG_SHARED_LIBRARY_TOOL;%(PreprocessorDefinitions) + ..\..;..\..\external;..\..\source;..\gfx;%(AdditionalIncludeDirectories) + Full + true + true + false + true + MultiThreaded + + + Windows + true + true + ..\..\bin\windows-x86\release\render-test-shared-library.lib + + + "$(SolutionDir)tools\copy-hlsl-libs.bat" "$(WindowsSdkDir)Redist/D3D/x86/" "../../bin/windows-x86/release/" + + + + + NotUsing + Level3 + NDEBUG;SLANG_SHARED_LIBRARY_TOOL;%(PreprocessorDefinitions) + ..\..;..\..\external;..\..\source;..\gfx;%(AdditionalIncludeDirectories) + Full + true + true + false + true + MultiThreaded + + + Windows + true + true + ..\..\bin\windows-x64\release\render-test-shared-library.lib + + + "$(SolutionDir)tools\copy-hlsl-libs.bat" "$(WindowsSdkDir)Redist/D3D/x64/" "../../bin/windows-x64/release/" + + + + + + + + + + + + + + + + + + + + {F9BE7957-8399-899E-0C49-E714FDDD4B65} + + + {DB00DA62-0533-4AFD-B59F-A67D5B3A0808} + + + {222F7498-B40C-4F3F-A704-DDEB91A4484A} + + + + + + \ No newline at end of file diff --git a/tools/render-test/render-test-shared-library.vcxproj.filters b/tools/render-test/render-test-shared-library.vcxproj.filters new file mode 100644 index 000000000..ff3d52a7e --- /dev/null +++ b/tools/render-test/render-test-shared-library.vcxproj.filters @@ -0,0 +1,48 @@ + + + + + {21EB8090-0D4E-1035-B6D3-48EBA215DCB7} + + + {E9C7FDCE-D52A-8D73-7EB0-C5296AF258F6} + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + \ No newline at end of file diff --git a/tools/render-test/shader-renderer-util.cpp b/tools/render-test/shader-renderer-util.cpp index f6c0366bb..0d0f8a3a5 100644 --- a/tools/render-test/shader-renderer-util.cpp +++ b/tools/render-test/shader-renderer-util.cpp @@ -185,7 +185,7 @@ static RefPtr _createSamplerState( { if (baseIndex + i != entry.glslBinding[i]) { - assert("Bindings must be contiguous"); + assert(!"Bindings must be contiguous"); break; } } diff --git a/tools/render-test/slang-support.cpp b/tools/render-test/slang-support.cpp index 26e856295..1dc7323a5 100644 --- a/tools/render-test/slang-support.cpp +++ b/tools/render-test/slang-support.cpp @@ -14,7 +14,6 @@ namespace renderer_test { RefPtr ShaderCompiler::compileProgram( ShaderCompileRequest const& request) { - SlangSession* slangSession = spCreateSession(NULL); SlangCompileRequest* slangRequest = spCreateCompileRequest(slangSession); spSetCodeGenTarget(slangRequest, target); @@ -173,8 +172,7 @@ RefPtr ShaderCompiler::compileProgram( // owns the memory allocation for the generated text, and will // free it when we destroy the compilation result. spDestroyCompileRequest(slangRequest); - spDestroySession(slangSession); - + return shaderProgram; } diff --git a/tools/render-test/slang-support.h b/tools/render-test/slang-support.h index 03de062d1..a9b8c8871 100644 --- a/tools/render-test/slang-support.h +++ b/tools/render-test/slang-support.h @@ -16,8 +16,9 @@ struct ShaderCompiler SlangSourceLanguage sourceLanguage; SlangPassThrough passThrough; char const* profile; - - RefPtr compileProgram( + SlangSession* slangSession; + + RefPtr compileProgram( ShaderCompileRequest const& request); }; -- cgit v1.2.3