diff options
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/render-test/main.cpp | 235 | ||||
| -rw-r--r-- | tools/render-test/options.cpp | 46 | ||||
| -rw-r--r-- | tools/render-test/options.h | 5 | ||||
| -rw-r--r-- | tools/render-test/render-test-shared-library.vcxproj | 210 | ||||
| -rw-r--r-- | tools/render-test/render-test-shared-library.vcxproj.filters | 48 | ||||
| -rw-r--r-- | tools/render-test/shader-renderer-util.cpp | 2 | ||||
| -rw-r--r-- | tools/render-test/slang-support.cpp | 4 | ||||
| -rw-r--r-- | tools/render-test/slang-support.h | 5 | ||||
| -rw-r--r-- | tools/slang-reflection-test/main.cpp | 28 | ||||
| -rw-r--r-- | tools/slang-reflection-test/slang-reflection-test-shared-library.vcxproj | 182 | ||||
| -rw-r--r-- | tools/slang-reflection-test/slang-reflection-test-shared-library.vcxproj.filters | 13 | ||||
| -rw-r--r-- | tools/slang-reflection-test/slang-reflection-test.vcxproj | 3 | ||||
| -rw-r--r-- | tools/slang-test/main.cpp | 131 | ||||
| -rw-r--r-- | tools/slang-test/os.cpp | 8 | ||||
| -rw-r--r-- | tools/slang-test/os.h | 5 | ||||
| -rw-r--r-- | tools/slang-test/test-context.cpp | 30 | ||||
| -rw-r--r-- | tools/slang-test/test-context.h | 21 |
17 files changed, 810 insertions, 166 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; } 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 <stdlib.h> #include <string.h> +#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<const char*> 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 <stdint.h> #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 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup Label="ProjectConfigurations"> + <ProjectConfiguration Include="Debug|Win32"> + <Configuration>Debug</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Debug|x64"> + <Configuration>Debug</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|Win32"> + <Configuration>Release</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|x64"> + <Configuration>Release</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + </ItemGroup> + <PropertyGroup Label="Globals"> + <ProjectGuid>{61F7EB00-7281-4BF3-9470-7C2EA92620C3}</ProjectGuid> + <IgnoreWarnCompileDuplicatedFilename>true</IgnoreWarnCompileDuplicatedFilename> + <Keyword>Win32Proj</Keyword> + <RootNamespace>render-test-shared-library</RootNamespace> + <WindowsTargetPlatformVersion>10.0.14393.0</WindowsTargetPlatformVersion> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <CharacterSet>Unicode</CharacterSet> + <PlatformToolset>v140</PlatformToolset> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <CharacterSet>Unicode</CharacterSet> + <PlatformToolset>v140</PlatformToolset> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <CharacterSet>Unicode</CharacterSet> + <PlatformToolset>v140</PlatformToolset> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <CharacterSet>Unicode</CharacterSet> + <PlatformToolset>v140</PlatformToolset> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> + <ImportGroup Label="ExtensionSettings"> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <PropertyGroup Label="UserMacros" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <LinkIncremental>true</LinkIncremental> + <OutDir>..\..\bin\windows-x86\debug\</OutDir> + <IntDir>..\..\intermediate\windows-x86\debug\render-test-shared-library\</IntDir> + <TargetName>render-test-shared-library</TargetName> + <TargetExt>.dll</TargetExt> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <LinkIncremental>true</LinkIncremental> + <OutDir>..\..\bin\windows-x64\debug\</OutDir> + <IntDir>..\..\intermediate\windows-x64\debug\render-test-shared-library\</IntDir> + <TargetName>render-test-shared-library</TargetName> + <TargetExt>.dll</TargetExt> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <LinkIncremental>false</LinkIncremental> + <OutDir>..\..\bin\windows-x86\release\</OutDir> + <IntDir>..\..\intermediate\windows-x86\release\render-test-shared-library\</IntDir> + <TargetName>render-test-shared-library</TargetName> + <TargetExt>.dll</TargetExt> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <LinkIncremental>false</LinkIncremental> + <OutDir>..\..\bin\windows-x64\release\</OutDir> + <IntDir>..\..\intermediate\windows-x64\release\render-test-shared-library\</IntDir> + <TargetName>render-test-shared-library</TargetName> + <TargetExt>.dll</TargetExt> + </PropertyGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <ClCompile> + <PrecompiledHeader>NotUsing</PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <PreprocessorDefinitions>_DEBUG;SLANG_SHARED_LIBRARY_TOOL;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <AdditionalIncludeDirectories>..\..;..\..\external;..\..\source;..\gfx;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <DebugInformationFormat>EditAndContinue</DebugInformationFormat> + <Optimization>Disabled</Optimization> + <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + <ImportLibrary>..\..\bin\windows-x86\debug\render-test-shared-library.lib</ImportLibrary> + </Link> + <PostBuildEvent> + <Command>"$(SolutionDir)tools\copy-hlsl-libs.bat" "$(WindowsSdkDir)Redist/D3D/x86/" "../../bin/windows-x86/debug/"</Command> + </PostBuildEvent> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <ClCompile> + <PrecompiledHeader>NotUsing</PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <PreprocessorDefinitions>_DEBUG;SLANG_SHARED_LIBRARY_TOOL;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <AdditionalIncludeDirectories>..\..;..\..\external;..\..\source;..\gfx;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <DebugInformationFormat>EditAndContinue</DebugInformationFormat> + <Optimization>Disabled</Optimization> + <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + <ImportLibrary>..\..\bin\windows-x64\debug\render-test-shared-library.lib</ImportLibrary> + </Link> + <PostBuildEvent> + <Command>"$(SolutionDir)tools\copy-hlsl-libs.bat" "$(WindowsSdkDir)Redist/D3D/x64/" "../../bin/windows-x64/debug/"</Command> + </PostBuildEvent> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <ClCompile> + <PrecompiledHeader>NotUsing</PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <PreprocessorDefinitions>NDEBUG;SLANG_SHARED_LIBRARY_TOOL;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <AdditionalIncludeDirectories>..\..;..\..\external;..\..\source;..\gfx;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <Optimization>Full</Optimization> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <MinimalRebuild>false</MinimalRebuild> + <StringPooling>true</StringPooling> + <RuntimeLibrary>MultiThreaded</RuntimeLibrary> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + <ImportLibrary>..\..\bin\windows-x86\release\render-test-shared-library.lib</ImportLibrary> + </Link> + <PostBuildEvent> + <Command>"$(SolutionDir)tools\copy-hlsl-libs.bat" "$(WindowsSdkDir)Redist/D3D/x86/" "../../bin/windows-x86/release/"</Command> + </PostBuildEvent> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <ClCompile> + <PrecompiledHeader>NotUsing</PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <PreprocessorDefinitions>NDEBUG;SLANG_SHARED_LIBRARY_TOOL;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <AdditionalIncludeDirectories>..\..;..\..\external;..\..\source;..\gfx;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <Optimization>Full</Optimization> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <MinimalRebuild>false</MinimalRebuild> + <StringPooling>true</StringPooling> + <RuntimeLibrary>MultiThreaded</RuntimeLibrary> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + <ImportLibrary>..\..\bin\windows-x64\release\render-test-shared-library.lib</ImportLibrary> + </Link> + <PostBuildEvent> + <Command>"$(SolutionDir)tools\copy-hlsl-libs.bat" "$(WindowsSdkDir)Redist/D3D/x64/" "../../bin/windows-x64/release/"</Command> + </PostBuildEvent> + </ItemDefinitionGroup> + <ItemGroup> + <ClInclude Include="options.h" /> + <ClInclude Include="png-serialize-util.h" /> + <ClInclude Include="shader-input-layout.h" /> + <ClInclude Include="shader-renderer-util.h" /> + <ClInclude Include="slang-support.h" /> + </ItemGroup> + <ItemGroup> + <ClCompile Include="main.cpp" /> + <ClCompile Include="options.cpp" /> + <ClCompile Include="png-serialize-util.cpp" /> + <ClCompile Include="shader-input-layout.cpp" /> + <ClCompile Include="shader-renderer-util.cpp" /> + <ClCompile Include="slang-support.cpp" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\..\source\core\core.vcxproj"> + <Project>{F9BE7957-8399-899E-0C49-E714FDDD4B65}</Project> + </ProjectReference> + <ProjectReference Include="..\..\source\slang\slang.vcxproj"> + <Project>{DB00DA62-0533-4AFD-B59F-A67D5B3A0808}</Project> + </ProjectReference> + <ProjectReference Include="..\gfx\gfx.vcxproj"> + <Project>{222F7498-B40C-4F3F-A704-DDEB91A4484A}</Project> + </ProjectReference> + </ItemGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets"> + </ImportGroup> +</Project>
\ 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 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup> + <Filter Include="Header Files"> + <UniqueIdentifier>{21EB8090-0D4E-1035-B6D3-48EBA215DCB7}</UniqueIdentifier> + </Filter> + <Filter Include="Source Files"> + <UniqueIdentifier>{E9C7FDCE-D52A-8D73-7EB0-C5296AF258F6}</UniqueIdentifier> + </Filter> + </ItemGroup> + <ItemGroup> + <ClInclude Include="options.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="png-serialize-util.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="shader-input-layout.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="shader-renderer-util.h"> + <Filter>Header Files</Filter> + </ClInclude> + <ClInclude Include="slang-support.h"> + <Filter>Header Files</Filter> + </ClInclude> + </ItemGroup> + <ItemGroup> + <ClCompile Include="main.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="options.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="png-serialize-util.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="shader-input-layout.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="shader-renderer-util.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + <ClCompile Include="slang-support.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + </ItemGroup> +</Project>
\ 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<SamplerState> _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<ShaderProgram> ShaderCompiler::compileProgram( ShaderCompileRequest const& request) { - SlangSession* slangSession = spCreateSession(NULL); SlangCompileRequest* slangRequest = spCreateCompileRequest(slangSession); spSetCodeGenTarget(slangRequest, target); @@ -173,8 +172,7 @@ RefPtr<ShaderProgram> 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<ShaderProgram> compileProgram( + SlangSession* slangSession; + + RefPtr<ShaderProgram> compileProgram( ShaderCompileRequest const& request); }; diff --git a/tools/slang-reflection-test/main.cpp b/tools/slang-reflection-test/main.cpp index 872d2ff3a..41a21eee8 100644 --- a/tools/slang-reflection-test/main.cpp +++ b/tools/slang-reflection-test/main.cpp @@ -8,6 +8,8 @@ #include <slang.h> #include <slang-com-helper.h> +#include "../../source/core/slang-app-context.h" + struct PrettyWriter { bool startOfLine = true; @@ -16,7 +18,7 @@ struct PrettyWriter static void writeRaw(PrettyWriter& writer, char const* begin, char const* end) { - fprintf(stdout, "%.*s", int(end - begin), begin); + Slang::AppContext::getStdOut().print("%.*s", int(end - begin), begin); } static void writeRaw(PrettyWriter& writer, char const* begin) @@ -27,7 +29,7 @@ static void writeRaw(PrettyWriter& writer, char const* begin) static void writeRawChar(PrettyWriter& writer, int c) { char buffer[] = { (char) c, 0 }; - writeRaw(writer, buffer); + writeRaw(writer, buffer, buffer + 1); } static void adjust(PrettyWriter& writer) @@ -77,7 +79,7 @@ static void write(PrettyWriter& writer, char const* text) static void write(PrettyWriter& writer, SlangUInt val) { adjust(writer); - fprintf(stdout, "%llu", (unsigned long long)val); + Slang::AppContext::getStdOut().print("%llu", (unsigned long long)val); } static void emitReflectionVarInfoJSON(PrettyWriter& writer, slang::VariableReflection* var); @@ -881,6 +883,7 @@ void emitReflectionJSON( auto programReflection = (slang::ShaderReflection*) reflection; PrettyWriter writer; + emitReflectionJSON(writer, programReflection); } @@ -889,18 +892,19 @@ static SlangResult maybeDumpDiagnostic(SlangResult res, SlangCompileRequest* req const char* diagnostic; if (SLANG_FAILED(res) && (diagnostic = spGetDiagnosticOutput(request))) { - fputs(diagnostic, stderr); + Slang::AppContext::getStdError().put(diagnostic); } return res; } -static SlangResult innerMain(int argc, char*const*argv) +SLANG_SHARED_LIBRARY_TOOL_API SlangResult innerMain(Slang::AppContext* appContext, SlangSession* session, int argc, const char*const* argv) { - // Parse any command-line options - - SlangSession* session = spCreateSession(nullptr); + Slang::AppContext::setSingleton(appContext); + SlangCompileRequest* request = spCreateCompileRequest(session); + appContext->configureRequest(request); + char const* appName = "slang-reflection-test"; if (argc > 0) appName = argv[0]; @@ -914,8 +918,7 @@ static SlangResult innerMain(int argc, char*const*argv) emitReflectionJSON(reflection); spDestroyCompileRequest(request); - spDestroySession(session); - + return SLANG_OK; } @@ -923,6 +926,9 @@ int main( int argc, char** argv) { - SlangResult res = 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/slang-reflection-test/slang-reflection-test-shared-library.vcxproj b/tools/slang-reflection-test/slang-reflection-test-shared-library.vcxproj new file mode 100644 index 000000000..48d08b94e --- /dev/null +++ b/tools/slang-reflection-test/slang-reflection-test-shared-library.vcxproj @@ -0,0 +1,182 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup Label="ProjectConfigurations"> + <ProjectConfiguration Include="Debug|Win32"> + <Configuration>Debug</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Debug|x64"> + <Configuration>Debug</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|Win32"> + <Configuration>Release</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|x64"> + <Configuration>Release</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + </ItemGroup> + <PropertyGroup Label="Globals"> + <ProjectGuid>{C5ACCA6E-C04D-4B36-8516-3752B3C13C2F}</ProjectGuid> + <IgnoreWarnCompileDuplicatedFilename>true</IgnoreWarnCompileDuplicatedFilename> + <Keyword>Win32Proj</Keyword> + <RootNamespace>slang-reflection-test-shared-library</RootNamespace> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <CharacterSet>Unicode</CharacterSet> + <PlatformToolset>v140</PlatformToolset> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <CharacterSet>Unicode</CharacterSet> + <PlatformToolset>v140</PlatformToolset> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <CharacterSet>Unicode</CharacterSet> + <PlatformToolset>v140</PlatformToolset> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <CharacterSet>Unicode</CharacterSet> + <PlatformToolset>v140</PlatformToolset> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> + <ImportGroup Label="ExtensionSettings"> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <PropertyGroup Label="UserMacros" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <LinkIncremental>true</LinkIncremental> + <OutDir>..\..\bin\windows-x86\debug\</OutDir> + <IntDir>..\..\intermediate\windows-x86\debug\slang-reflection-test-shared-library\</IntDir> + <TargetName>slang-reflection-test-shared-library</TargetName> + <TargetExt>.dll</TargetExt> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <LinkIncremental>true</LinkIncremental> + <OutDir>..\..\bin\windows-x64\debug\</OutDir> + <IntDir>..\..\intermediate\windows-x64\debug\slang-reflection-test-shared-library\</IntDir> + <TargetName>slang-reflection-test-shared-library</TargetName> + <TargetExt>.dll</TargetExt> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <LinkIncremental>false</LinkIncremental> + <OutDir>..\..\bin\windows-x86\release\</OutDir> + <IntDir>..\..\intermediate\windows-x86\release\slang-reflection-test-shared-library\</IntDir> + <TargetName>slang-reflection-test-shared-library</TargetName> + <TargetExt>.dll</TargetExt> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <LinkIncremental>false</LinkIncremental> + <OutDir>..\..\bin\windows-x64\release\</OutDir> + <IntDir>..\..\intermediate\windows-x64\release\slang-reflection-test-shared-library\</IntDir> + <TargetName>slang-reflection-test-shared-library</TargetName> + <TargetExt>.dll</TargetExt> + </PropertyGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <ClCompile> + <PrecompiledHeader>NotUsing</PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <PreprocessorDefinitions>_DEBUG;SLANG_SHARED_LIBRARY_TOOL;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <AdditionalIncludeDirectories>..\..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <DebugInformationFormat>EditAndContinue</DebugInformationFormat> + <Optimization>Disabled</Optimization> + <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + <ImportLibrary>..\..\bin\windows-x86\debug\slang-reflection-test-shared-library.lib</ImportLibrary> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <ClCompile> + <PrecompiledHeader>NotUsing</PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <PreprocessorDefinitions>_DEBUG;SLANG_SHARED_LIBRARY_TOOL;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <AdditionalIncludeDirectories>..\..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <DebugInformationFormat>EditAndContinue</DebugInformationFormat> + <Optimization>Disabled</Optimization> + <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + <ImportLibrary>..\..\bin\windows-x64\debug\slang-reflection-test-shared-library.lib</ImportLibrary> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <ClCompile> + <PrecompiledHeader>NotUsing</PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <PreprocessorDefinitions>NDEBUG;SLANG_SHARED_LIBRARY_TOOL;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <AdditionalIncludeDirectories>..\..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <Optimization>Full</Optimization> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <MinimalRebuild>false</MinimalRebuild> + <StringPooling>true</StringPooling> + <RuntimeLibrary>MultiThreaded</RuntimeLibrary> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + <ImportLibrary>..\..\bin\windows-x86\release\slang-reflection-test-shared-library.lib</ImportLibrary> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <ClCompile> + <PrecompiledHeader>NotUsing</PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <PreprocessorDefinitions>NDEBUG;SLANG_SHARED_LIBRARY_TOOL;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <AdditionalIncludeDirectories>..\..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <Optimization>Full</Optimization> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <MinimalRebuild>false</MinimalRebuild> + <StringPooling>true</StringPooling> + <RuntimeLibrary>MultiThreaded</RuntimeLibrary> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + <ImportLibrary>..\..\bin\windows-x64\release\slang-reflection-test-shared-library.lib</ImportLibrary> + </Link> + </ItemDefinitionGroup> + <ItemGroup> + <ClCompile Include="main.cpp" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\..\source\core\core.vcxproj"> + <Project>{F9BE7957-8399-899E-0C49-E714FDDD4B65}</Project> + </ProjectReference> + <ProjectReference Include="..\..\source\slang\slang.vcxproj"> + <Project>{DB00DA62-0533-4AFD-B59F-A67D5B3A0808}</Project> + </ProjectReference> + </ItemGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets"> + </ImportGroup> +</Project>
\ No newline at end of file diff --git a/tools/slang-reflection-test/slang-reflection-test-shared-library.vcxproj.filters b/tools/slang-reflection-test/slang-reflection-test-shared-library.vcxproj.filters new file mode 100644 index 000000000..e9ae1c092 --- /dev/null +++ b/tools/slang-reflection-test/slang-reflection-test-shared-library.vcxproj.filters @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup> + <Filter Include="Source Files"> + <UniqueIdentifier>{E9C7FDCE-D52A-8D73-7EB0-C5296AF258F6}</UniqueIdentifier> + </Filter> + </ItemGroup> + <ItemGroup> + <ClCompile Include="main.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + </ItemGroup> +</Project>
\ No newline at end of file diff --git a/tools/slang-reflection-test/slang-reflection-test.vcxproj b/tools/slang-reflection-test/slang-reflection-test.vcxproj index 78e562401..8a40290e6 100644 --- a/tools/slang-reflection-test/slang-reflection-test.vcxproj +++ b/tools/slang-reflection-test/slang-reflection-test.vcxproj @@ -168,6 +168,9 @@ <ProjectReference Include="..\..\source\slang\slang.vcxproj"> <Project>{DB00DA62-0533-4AFD-B59F-A67D5B3A0808}</Project> </ProjectReference> + <ProjectReference Include="..\..\source\core\core.vcxproj"> + <Project>{F9BE7957-8399-899E-0C49-E714FDDD4B65}</Project> + </ProjectReference> </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> diff --git a/tools/slang-test/main.cpp b/tools/slang-test/main.cpp index 943e82cef..77005d03b 100644 --- a/tools/slang-test/main.cpp +++ b/tools/slang-test/main.cpp @@ -2,6 +2,7 @@ #include "../../source/core/slang-io.h" #include "../../source/core/token-reader.h" +#include "../../source/core/slang-app-context.h" #include "../../slang-com-helper.h" @@ -95,6 +96,9 @@ struct Options // integration builds. bool dumpOutputOnFailure = false; + // If set, will force using of executables (not shared library) for tests + bool useExes = false; + // kind of output to generate TestOutputMode outputMode = TestOutputMode::Default; @@ -114,6 +118,8 @@ struct Options // Globals +static const Options g_defaultOptions; + Options g_options; Dictionary<String, TestCategory*> g_testCategories; TestCategory* g_defaultTestCategory; @@ -125,14 +131,16 @@ TestCategory* findTestCategory(String const& name); /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!! Functions !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ -Result parseOptions(int* argc, char** argv) +Result parseOptions(int argc, char** argv, Slang::WriterHelper stdError) { - int argCount = *argc; + g_options = g_defaultOptions; + + List<const char*> positionalArgs; + + int argCount = argc; char const* const* argCursor = argv; char const* const* argEnd = argCursor + argCount; - char const** writeCursor = (char const**) argv; - // first argument is the application name if( argCursor != argEnd ) { @@ -145,7 +153,7 @@ Result parseOptions(int* argc, char** argv) char const* arg = *argCursor++; if( arg[0] != '-' ) { - *writeCursor++ = arg; + positionalArgs.Add(arg); continue; } @@ -153,8 +161,7 @@ Result parseOptions(int* argc, char** argv) { while(argCursor != argEnd) { - char const* nxtArg = *argCursor++; - *writeCursor++ = nxtArg; + positionalArgs.Add(*argCursor++); } break; } @@ -163,11 +170,15 @@ Result parseOptions(int* argc, char** argv) { if( argCursor == argEnd ) { - fprintf(stderr, "error: expected operand for '%s'\n", arg); + stdError.print("error: expected operand for '%s'\n", arg); return SLANG_FAIL; } g_options.binDir = *argCursor++; } + else if (strcmp(arg, "-useexes") == 0) + { + g_options.useExes = true; + } else if( strcmp(arg, "-v") == 0 ) { g_options.shouldBeVerbose = true; @@ -188,7 +199,7 @@ Result parseOptions(int* argc, char** argv) { if( argCursor == argEnd ) { - fprintf(stderr, "error: expected operand for '%s'\n", arg); + stdError.print("error: expected operand for '%s'\n", arg); return SLANG_FAIL; } argCursor++; @@ -198,7 +209,7 @@ Result parseOptions(int* argc, char** argv) { if( argCursor == argEnd ) { - fprintf(stderr, "error: expected operand for '%s'\n", arg); + stdError.print("error: expected operand for '%s'\n", arg); return SLANG_FAIL; } argCursor++; @@ -230,7 +241,7 @@ Result parseOptions(int* argc, char** argv) { if( argCursor == argEnd ) { - fprintf(stderr, "error: expected operand for '%s'\n", arg); + stdError.print("error: expected operand for '%s'\n", arg); return SLANG_FAIL; } auto category = findTestCategory(*argCursor++); @@ -243,7 +254,7 @@ Result parseOptions(int* argc, char** argv) { if( argCursor == argEnd ) { - fprintf(stderr, "error: expected operand for '%s'\n", arg); + stdError.print("error: expected operand for '%s'\n", arg); return SLANG_FAIL; } auto category = findTestCategory(*argCursor++); @@ -256,7 +267,7 @@ Result parseOptions(int* argc, char** argv) { if (argCursor == argEnd) { - fprintf(stderr, "error: expecting an api expression (eg 'vk+dx12' or '+dx11') '%s'\n", arg); + stdError.print("error: expecting an api expression (eg 'vk+dx12' or '+dx11') '%s'\n", arg); return SLANG_FAIL; } const char* apiList = *argCursor++; @@ -264,7 +275,7 @@ Result parseOptions(int* argc, char** argv) SlangResult res = RenderApiUtil::parseApiFlags(UnownedStringSlice(apiList), g_options.enabledApis, &g_options.enabledApis); if (SLANG_FAILED(res)) { - fprintf(stderr, "error: unable to parse api expression '%s'\n", apiList); + stdError.print("error: unable to parse api expression '%s'\n", apiList); return res; } } @@ -272,7 +283,7 @@ Result parseOptions(int* argc, char** argv) { if (argCursor == argEnd) { - fprintf(stderr, "error: expected an api expression (eg 'vk+dx12' or '+dx11') '%s'\n", arg); + stdError.print("error: expected an api expression (eg 'vk+dx12' or '+dx11') '%s'\n", arg); return SLANG_FAIL; } const char* apiList = *argCursor++; @@ -280,13 +291,13 @@ Result parseOptions(int* argc, char** argv) SlangResult res = RenderApiUtil::parseApiFlags(UnownedStringSlice(apiList), g_options.synthesizedTestApis, &g_options.synthesizedTestApis); if (SLANG_FAILED(res)) { - fprintf(stderr, "error: unable to parse api expression '%s'\n", apiList); + stdError.print("error: unable to parse api expression '%s'\n", apiList); return res; } } else { - fprintf(stderr, "unknown option '%s'\n", arg); + stdError.print("unknown option '%s'\n", arg); return SLANG_FAIL; } } @@ -301,25 +312,21 @@ Result parseOptions(int* argc, char** argv) g_options.synthesizedTestApis &= g_options.enabledApis; } - // any arguments left over were positional arguments - argCount = (int)((char**)writeCursor - argv); - argCursor = argv; - argEnd = argCursor + argCount; - // first positional argument is a "filter" to apply - if( argCursor != argEnd ) + // first positional argument is source shader path + if (positionalArgs.Count()) { - g_options.testPrefix = *argCursor++; + g_options.testPrefix = 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; } @@ -638,7 +645,48 @@ OSError spawnAndWait(TestContext* context, const String& testPath, OSProcessSpaw String commandLine = spawner.getCommandLine(); context->messageFormat(TestMessageType::Info, "%s\n", commandLine.begin()); } - + + if (!context->m_useExes) + { + String exeName = Path::GetFileNameWithoutEXT(spawner.executableName_); + + auto func = context->getInnerMainFunc(String(g_options.binDir), exeName); + if (func) + { + StringBuilder stdErrorString; + StringBuilder stdOutString; + + // Say static so not released + StringWriter stdError(&stdErrorString, WriterFlag::IsConsole | WriterFlag::IsStatic); + StringWriter stdOut(&stdOutString, WriterFlag::IsConsole | WriterFlag::IsStatic); + + AppContext appContext; + appContext.setWriter(SLANG_WRITER_CHANNEL_STD_ERROR, &stdError); + appContext.setWriter(SLANG_WRITER_CHANNEL_STD_OUTPUT, &stdOut); + + if (exeName == "slangc") + { + appContext.setWriter(SLANG_WRITER_CHANNEL_DIAGNOSTIC, &stdError); + } + appContext.setReplaceWriterFlagsAll(); + + List<const char*> args; + args.Add(exeName.Buffer()); + for (int i = 0; i < int(spawner.argumentList_.Count()); ++i) + { + args.Add(spawner.argumentList_[i].Buffer()); + } + + SlangResult res = func(&appContext, context->getSession(), int(args.Count()), args.begin()); + + spawner.standardError_ = stdErrorString; + spawner.standardOutput_ = stdOutString; + spawner.resultCode_ = AppContext::getReturnCode(res); + + return kOSError_None; + } + } + OSError err = spawner.spawnAndWaitForCompletion(); if (err != kOSError_None) { @@ -1214,7 +1262,7 @@ TestResult runGLSLComparisonTest(TestContext* context, TestInput& input) } -TestResult runComputeComparisonImpl(TestContext* context, TestInput& input, const char * langOption) +TestResult runComputeComparisonImpl(TestContext* context, TestInput& input, const char *const* langOpts, size_t numLangOpts) { // TODO: delete any existing files at the output path(s) to avoid stale outputs leading to a false pass auto filePath999 = input.filePath; @@ -1236,7 +1284,10 @@ TestResult runComputeComparisonImpl(TestContext* context, TestInput& input, cons spawner.pushArgument(arg); } - spawner.pushArgument(langOption); + for (int i = 0; i < int(numLangOpts); ++i) + { + spawner.pushArgument(langOpts[i]); + } spawner.pushArgument("-o"); auto actualOutputFile = outputStem + ".actual.txt"; spawner.pushArgument(actualOutputFile); @@ -1309,22 +1360,25 @@ TestResult runComputeComparisonImpl(TestContext* context, TestInput& input, cons TestResult runSlangComputeComparisonTest(TestContext* context, TestInput& input) { - return runComputeComparisonImpl(context, input, "-slang -compute"); + const char* langOpts[] = { "-slang", "-compute" }; + return runComputeComparisonImpl(context, input, langOpts, SLANG_COUNT_OF(langOpts)); } TestResult runSlangComputeComparisonTestEx(TestContext* context, TestInput& input) { - return runComputeComparisonImpl(context, input, ""); + return runComputeComparisonImpl(context, input, nullptr, 0); } TestResult runHLSLComputeTest(TestContext* context, TestInput& input) { - return runComputeComparisonImpl(context, input, "-hlsl-rewrite -compute"); + const char* langOpts[] = { "--hlsl-rewrite", "-compute" }; + return runComputeComparisonImpl(context, input, langOpts, SLANG_COUNT_OF(langOpts)); } TestResult runSlangRenderComputeComparisonTest(TestContext* context, TestInput& input) { - return runComputeComparisonImpl(context, input, "-slang -gcompute"); + const char* langOpts[] = { "-slang", "-gcompute" }; + return runComputeComparisonImpl(context, input, langOpts, SLANG_COUNT_OF(langOpts)); } TestResult doRenderComparisonTestRun(TestContext* context, TestInput& input, char const* langOption, char const* outputKind, String* outOutput) @@ -1913,9 +1967,11 @@ void runTestsInDirectory( // int main( - int argc, - char** argv) + int argcIn, + char** argvIn) { + AppContext::initDefault(); + // Set up our test categories here auto fullTestCategory = addTestCategory("full", nullptr); @@ -1939,7 +1995,7 @@ int main( // - if (SLANG_FAILED(parseOptions(&argc, argv))) + if (SLANG_FAILED(parseOptions(argcIn, argvIn, AppContext::getStdError()))) { // Return exit code with error return 1; @@ -1968,6 +2024,7 @@ int main( } context.m_dumpOutputOnFailure = g_options.dumpOutputOnFailure; + context.m_useExes = g_options.useExes; context.m_isVerbose = g_options.shouldBeVerbose; { diff --git a/tools/slang-test/os.cpp b/tools/slang-test/os.cpp index 8cb49248c..9ecf50557 100644 --- a/tools/slang-test/os.cpp +++ b/tools/slang-test/os.cpp @@ -222,6 +222,8 @@ void OSProcessSpawner::pushArgument( // TODO(tfoley): handle cases where arguments need some escaping commandLine_.Append(" "); commandLine_.Append(argument); + + argumentList_.Add(argument); } Slang::String OSProcessSpawner::getCommandLine() @@ -480,7 +482,7 @@ void OSProcessSpawner::pushExecutableName( Slang::String executableName) { executableName_ = executableName; - pushArgument(executableName); + arguments_.Add(executableName); isExecutablePath_ = false; } @@ -488,7 +490,7 @@ void OSProcessSpawner::pushExecutablePath( Slang::String executablePath) { executableName_ = executablePath; - pushArgument(executablePath); + arguments_.Add(executablePath); isExecutablePath_ = true; } @@ -496,6 +498,7 @@ void OSProcessSpawner::pushArgument( Slang::String argument) { arguments_.Add(argument); + argumentList_.Add(argument); } Slang::String OSProcessSpawner::getCommandLine() @@ -507,7 +510,6 @@ Slang::String OSProcessSpawner::getCommandLine() { if(ii != 0) sb << " "; sb << arguments_[ii]; - } return sb.ProduceString(); } diff --git a/tools/slang-test/os.h b/tools/slang-test/os.h index 3466f818c..3e6d93942 100644 --- a/tools/slang-test/os.h +++ b/tools/slang-test/os.h @@ -178,8 +178,11 @@ struct OSProcessSpawner Slang::StringBuilder commandLine_; #else Slang::List<Slang::String> arguments_; - #endif + + // Only holds the argumements in order + Slang::List<Slang::String> argumentList_; + // Is the executable specified by path, rather than just by name? bool isExecutablePath_; }; diff --git a/tools/slang-test/test-context.cpp b/tools/slang-test/test-context.cpp index b94435a8e..efbbb4f65 100644 --- a/tools/slang-test/test-context.cpp +++ b/tools/slang-test/test-context.cpp @@ -82,6 +82,7 @@ TestContext::TestContext() : m_inTest = false; m_dumpOutputOnFailure = false; m_isVerbose = false; + m_useExes = false; m_session = nullptr; } @@ -480,6 +481,35 @@ bool TestContext::didAllSucceed() const return m_passedTestCount == (m_totalTestCount - m_ignoredTestCount); } +TestContext::InnerMainFunc TestContext::getInnerMainFunc(const String& dirPath, const String& name) +{ + { + SharedLibraryTool* tool = m_sharedLibTools.TryGetValue(name); + if (tool) + { + return tool->m_func; + } + } + + StringBuilder sharedLibToolBuilder; + sharedLibToolBuilder.append(name); + sharedLibToolBuilder.append("-shared-library"); + + StringBuilder builder; + SharedLibrary::appendPlatformFileName(sharedLibToolBuilder.getUnownedSlice(), builder); + String path = Path::Combine(dirPath, builder); + + SharedLibraryTool tool = {}; + + if (SLANG_SUCCEEDED(SharedLibrary::loadWithPlatformFilename(path.begin(), tool.m_sharedLibrary))) + { + tool.m_func = (InnerMainFunc)SharedLibrary::findFuncByName(tool.m_sharedLibrary, "innerMain"); + } + + m_sharedLibTools.Add(name, tool); + return tool.m_func; +} + void TestContext::outputSummary() { auto passCount = m_passedTestCount; diff --git a/tools/slang-test/test-context.h b/tools/slang-test/test-context.h index a81473efa..cf047cec7 100644 --- a/tools/slang-test/test-context.h +++ b/tools/slang-test/test-context.h @@ -1,6 +1,10 @@ // test-context.h #include "../../source/core/slang-string-util.h" +#include "../../source/core/platform.h" +#include "../../source/core/slang-app-context.h" +#include "../../source/core/dictionary.h" + #define SLANG_CHECK(x) TestContext::get()->addResultWithLocation((x), #x, __FILE__, __LINE__); @@ -54,6 +58,7 @@ enum class TestMessageType class TestContext { public: + typedef SlangResult(*InnerMainFunc)(Slang::AppContext* appContext, SlangSession* session, int argc, const char*const* argv); struct TestInfo { @@ -124,6 +129,9 @@ class TestContext /// Returns true if all run tests succeeded bool didAllSucceed() const; + /// Get the InnerMain function from a shared library tool + InnerMainFunc getInnerMainFunc(const Slang::String& dirPath, const Slang::String& name); + /// Get the slang session SlangSession* getSession() const { return m_session; } @@ -134,7 +142,6 @@ class TestContext /// Dtor ~TestContext(); - static TestResult combine(TestResult a, TestResult b) { return (a > b) ? a : b; } static TestContext* get() { return s_context; } @@ -155,9 +162,17 @@ class TestContext bool m_dumpOutputOnFailure; bool m_isVerbose; + bool m_useExes; + void outputSummary(); protected: + struct SharedLibraryTool + { + Slang::SharedLibrary::Handle m_sharedLibrary; + InnerMainFunc m_func; + }; + void _addResult(const TestInfo& info); Slang::StringBuilder m_currentMessage; @@ -168,7 +183,9 @@ protected: bool m_inTest; SlangSession* m_session; - + + Slang::Dictionary<Slang::String, SharedLibraryTool> m_sharedLibTools; + static TestContext* s_context; }; |
