diff options
32 files changed, 456 insertions, 120 deletions
diff --git a/build/visual-studio/cpu-hello-world/cpu-hello-world.vcxproj b/build/visual-studio/cpu-hello-world/cpu-hello-world.vcxproj index 9d4c819cf..2fb93b42c 100644 --- a/build/visual-studio/cpu-hello-world/cpu-hello-world.vcxproj +++ b/build/visual-studio/cpu-hello-world/cpu-hello-world.vcxproj @@ -177,6 +177,9 @@ <ProjectReference Include="..\gfx\gfx.vcxproj"> <Project>{222F7498-B40C-4F3F-A704-DDEB91A4484A}</Project> </ProjectReference> + <ProjectReference Include="..\gfx-util\gfx-util.vcxproj"> + <Project>{F5ADB74E-02A7-44FB-AA3B-FC02F8AC7A4B}</Project> + </ProjectReference> <ProjectReference Include="..\graphics-app-framework\graphics-app-framework.vcxproj"> <Project>{3565FE5E-4FA3-11EB-AE93-0242AC130002}</Project> </ProjectReference> diff --git a/build/visual-studio/gfx-util/gfx-util.vcxproj b/build/visual-studio/gfx-util/gfx-util.vcxproj new file mode 100644 index 000000000..d75105524 --- /dev/null +++ b/build/visual-studio/gfx-util/gfx-util.vcxproj @@ -0,0 +1,169 @@ +<?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>{F5ADB74E-02A7-44FB-AA3B-FC02F8AC7A4B}</ProjectGuid> + <IgnoreWarnCompileDuplicatedFilename>true</IgnoreWarnCompileDuplicatedFilename> + <Keyword>Win32Proj</Keyword> + <RootNamespace>gfx-util</RootNamespace> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> + <ConfigurationType>StaticLibrary</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <CharacterSet>Unicode</CharacterSet> + <PlatformToolset>v140</PlatformToolset> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> + <ConfigurationType>StaticLibrary</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <CharacterSet>Unicode</CharacterSet> + <PlatformToolset>v140</PlatformToolset> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> + <ConfigurationType>StaticLibrary</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <CharacterSet>Unicode</CharacterSet> + <PlatformToolset>v140</PlatformToolset> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> + <ConfigurationType>StaticLibrary</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'"> + <OutDir>..\..\..\bin\windows-x86\debug\</OutDir> + <IntDir>..\..\..\intermediate\windows-x86\debug\gfx-util\</IntDir> + <TargetName>gfx-util</TargetName> + <TargetExt>.lib</TargetExt> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <OutDir>..\..\..\bin\windows-x64\debug\</OutDir> + <IntDir>..\..\..\intermediate\windows-x64\debug\gfx-util\</IntDir> + <TargetName>gfx-util</TargetName> + <TargetExt>.lib</TargetExt> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <OutDir>..\..\..\bin\windows-x86\release\</OutDir> + <IntDir>..\..\..\intermediate\windows-x86\release\gfx-util\</IntDir> + <TargetName>gfx-util</TargetName> + <TargetExt>.lib</TargetExt> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <OutDir>..\..\..\bin\windows-x64\release\</OutDir> + <IntDir>..\..\..\intermediate\windows-x64\release\gfx-util\</IntDir> + <TargetName>gfx-util</TargetName> + <TargetExt>.lib</TargetExt> + </PropertyGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <ClCompile> + <PrecompiledHeader>NotUsing</PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <AdditionalIncludeDirectories>..\..\..;..\..\..\source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <DebugInformationFormat>EditAndContinue</DebugInformationFormat> + <Optimization>Disabled</Optimization> + <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <ClCompile> + <PrecompiledHeader>NotUsing</PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <AdditionalIncludeDirectories>..\..\..;..\..\..\source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <DebugInformationFormat>EditAndContinue</DebugInformationFormat> + <Optimization>Disabled</Optimization> + <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <ClCompile> + <PrecompiledHeader>NotUsing</PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <AdditionalIncludeDirectories>..\..\..;..\..\..\source;%(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> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <ClCompile> + <PrecompiledHeader>NotUsing</PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <AdditionalIncludeDirectories>..\..\..;..\..\..\source;%(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> + </Link> + </ItemDefinitionGroup> + <ItemGroup> + <ClInclude Include="..\..\..\tools\gfx-util\shader-cursor.h" /> + </ItemGroup> + <ItemGroup> + <ClCompile Include="..\..\..\tools\gfx-util\shader-cursor.cpp" /> + </ItemGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets"> + </ImportGroup> +</Project>
\ No newline at end of file diff --git a/build/visual-studio/gfx-util/gfx-util.vcxproj.filters b/build/visual-studio/gfx-util/gfx-util.vcxproj.filters new file mode 100644 index 000000000..23e932b8c --- /dev/null +++ b/build/visual-studio/gfx-util/gfx-util.vcxproj.filters @@ -0,0 +1,21 @@ +<?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="..\..\..\tools\gfx-util\shader-cursor.h"> + <Filter>Header Files</Filter> + </ClInclude> + </ItemGroup> + <ItemGroup> + <ClCompile Include="..\..\..\tools\gfx-util\shader-cursor.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + </ItemGroup> +</Project>
\ No newline at end of file diff --git a/build/visual-studio/gfx/gfx.vcxproj b/build/visual-studio/gfx/gfx.vcxproj index 789440fb7..0ed5ed233 100644 --- a/build/visual-studio/gfx/gfx.vcxproj +++ b/build/visual-studio/gfx/gfx.vcxproj @@ -27,25 +27,25 @@ </PropertyGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> - <ConfigurationType>StaticLibrary</ConfigurationType> + <ConfigurationType>DynamicLibrary</ConfigurationType> <UseDebugLibraries>true</UseDebugLibraries> <CharacterSet>Unicode</CharacterSet> <PlatformToolset>v140</PlatformToolset> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> - <ConfigurationType>StaticLibrary</ConfigurationType> + <ConfigurationType>DynamicLibrary</ConfigurationType> <UseDebugLibraries>true</UseDebugLibraries> <CharacterSet>Unicode</CharacterSet> <PlatformToolset>v140</PlatformToolset> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> - <ConfigurationType>StaticLibrary</ConfigurationType> + <ConfigurationType>DynamicLibrary</ConfigurationType> <UseDebugLibraries>false</UseDebugLibraries> <CharacterSet>Unicode</CharacterSet> <PlatformToolset>v140</PlatformToolset> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> - <ConfigurationType>StaticLibrary</ConfigurationType> + <ConfigurationType>DynamicLibrary</ConfigurationType> <UseDebugLibraries>false</UseDebugLibraries> <CharacterSet>Unicode</CharacterSet> <PlatformToolset>v140</PlatformToolset> @@ -67,34 +67,38 @@ </ImportGroup> <PropertyGroup Label="UserMacros" /> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <LinkIncremental>true</LinkIncremental> <OutDir>..\..\..\bin\windows-x86\debug\</OutDir> <IntDir>..\..\..\intermediate\windows-x86\debug\gfx\</IntDir> <TargetName>gfx</TargetName> - <TargetExt>.lib</TargetExt> + <TargetExt>.dll</TargetExt> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <LinkIncremental>true</LinkIncremental> <OutDir>..\..\..\bin\windows-x64\debug\</OutDir> <IntDir>..\..\..\intermediate\windows-x64\debug\gfx\</IntDir> <TargetName>gfx</TargetName> - <TargetExt>.lib</TargetExt> + <TargetExt>.dll</TargetExt> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <LinkIncremental>false</LinkIncremental> <OutDir>..\..\..\bin\windows-x86\release\</OutDir> <IntDir>..\..\..\intermediate\windows-x86\release\gfx\</IntDir> <TargetName>gfx</TargetName> - <TargetExt>.lib</TargetExt> + <TargetExt>.dll</TargetExt> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <LinkIncremental>false</LinkIncremental> <OutDir>..\..\..\bin\windows-x64\release\</OutDir> <IntDir>..\..\..\intermediate\windows-x64\release\gfx\</IntDir> <TargetName>gfx</TargetName> - <TargetExt>.lib</TargetExt> + <TargetExt>.dll</TargetExt> </PropertyGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ClCompile> <PrecompiledHeader>NotUsing</PrecompiledHeader> <WarningLevel>Level3</WarningLevel> - <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <PreprocessorDefinitions>_DEBUG;SLANG_GFX_DYNAMIC;SLANG_GFX_DYNAMIC_EXPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions> <AdditionalIncludeDirectories>..\..\..;..\..\..\external;..\..\..\source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <DebugInformationFormat>EditAndContinue</DebugInformationFormat> <Optimization>Disabled</Optimization> @@ -103,6 +107,7 @@ <Link> <SubSystem>Windows</SubSystem> <GenerateDebugInformation>true</GenerateDebugInformation> + <ImportLibrary>..\..\..\bin\windows-x86\debug\gfx.lib</ImportLibrary> </Link> <PostBuildEvent> <Command>"$(SolutionDir)tools\copy-hlsl-libs.bat" "$(WindowsSdkDir)Redist/D3D/x86/" "../../../bin/windows-x86/debug/"</Command> @@ -112,7 +117,7 @@ <ClCompile> <PrecompiledHeader>NotUsing</PrecompiledHeader> <WarningLevel>Level3</WarningLevel> - <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <PreprocessorDefinitions>_DEBUG;SLANG_GFX_DYNAMIC;SLANG_GFX_DYNAMIC_EXPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions> <AdditionalIncludeDirectories>..\..\..;..\..\..\external;..\..\..\source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <DebugInformationFormat>EditAndContinue</DebugInformationFormat> <Optimization>Disabled</Optimization> @@ -121,6 +126,7 @@ <Link> <SubSystem>Windows</SubSystem> <GenerateDebugInformation>true</GenerateDebugInformation> + <ImportLibrary>..\..\..\bin\windows-x64\debug\gfx.lib</ImportLibrary> </Link> <PostBuildEvent> <Command>"$(SolutionDir)tools\copy-hlsl-libs.bat" "$(WindowsSdkDir)Redist/D3D/x64/" "../../../bin/windows-x64/debug/"</Command> @@ -130,7 +136,7 @@ <ClCompile> <PrecompiledHeader>NotUsing</PrecompiledHeader> <WarningLevel>Level3</WarningLevel> - <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <PreprocessorDefinitions>NDEBUG;SLANG_GFX_DYNAMIC;SLANG_GFX_DYNAMIC_EXPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions> <AdditionalIncludeDirectories>..\..\..;..\..\..\external;..\..\..\source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <Optimization>Full</Optimization> <FunctionLevelLinking>true</FunctionLevelLinking> @@ -143,6 +149,7 @@ <SubSystem>Windows</SubSystem> <EnableCOMDATFolding>true</EnableCOMDATFolding> <OptimizeReferences>true</OptimizeReferences> + <ImportLibrary>..\..\..\bin\windows-x86\release\gfx.lib</ImportLibrary> </Link> <PostBuildEvent> <Command>"$(SolutionDir)tools\copy-hlsl-libs.bat" "$(WindowsSdkDir)Redist/D3D/x86/" "../../../bin/windows-x86/release/"</Command> @@ -152,7 +159,7 @@ <ClCompile> <PrecompiledHeader>NotUsing</PrecompiledHeader> <WarningLevel>Level3</WarningLevel> - <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <PreprocessorDefinitions>NDEBUG;SLANG_GFX_DYNAMIC;SLANG_GFX_DYNAMIC_EXPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions> <AdditionalIncludeDirectories>..\..\..;..\..\..\external;..\..\..\source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <Optimization>Full</Optimization> <FunctionLevelLinking>true</FunctionLevelLinking> @@ -165,6 +172,7 @@ <SubSystem>Windows</SubSystem> <EnableCOMDATFolding>true</EnableCOMDATFolding> <OptimizeReferences>true</OptimizeReferences> + <ImportLibrary>..\..\..\bin\windows-x64\release\gfx.lib</ImportLibrary> </Link> <PostBuildEvent> <Command>"$(SolutionDir)tools\copy-hlsl-libs.bat" "$(WindowsSdkDir)Redist/D3D/x64/" "../../../bin/windows-x64/release/"</Command> @@ -185,9 +193,6 @@ <ClInclude Include="..\..\..\tools\gfx\render-graphics-common.h" /> <ClInclude Include="..\..\..\tools\gfx\render.h" /> <ClInclude Include="..\..\..\tools\gfx\renderer-shared.h" /> - <ClInclude Include="..\..\..\tools\gfx\shader-cursor.h" /> - <ClInclude Include="..\..\..\tools\gfx\slang-gfx-helper.h" /> - <ClInclude Include="..\..\..\tools\gfx\surface.h" /> <ClInclude Include="..\..\..\tools\gfx\vulkan\render-vk.h" /> <ClInclude Include="..\..\..\tools\gfx\vulkan\vk-api.h" /> <ClInclude Include="..\..\..\tools\gfx\vulkan\vk-device-queue.h" /> @@ -209,9 +214,6 @@ <ClCompile Include="..\..\..\tools\gfx\render-graphics-common.cpp" /> <ClCompile Include="..\..\..\tools\gfx\render.cpp" /> <ClCompile Include="..\..\..\tools\gfx\renderer-shared.cpp" /> - <ClCompile Include="..\..\..\tools\gfx\shader-cursor.cpp" /> - <ClCompile Include="..\..\..\tools\gfx\slang-gfx-helper.cpp" /> - <ClCompile Include="..\..\..\tools\gfx\surface.cpp" /> <ClCompile Include="..\..\..\tools\gfx\vulkan\render-vk.cpp" /> <ClCompile Include="..\..\..\tools\gfx\vulkan\vk-api.cpp" /> <ClCompile Include="..\..\..\tools\gfx\vulkan\vk-device-queue.cpp" /> @@ -219,6 +221,14 @@ <ClCompile Include="..\..\..\tools\gfx\vulkan\vk-swap-chain.cpp" /> <ClCompile Include="..\..\..\tools\gfx\vulkan\vk-util.cpp" /> </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\core\core.vcxproj"> + <Project>{F9BE7957-8399-899E-0C49-E714FDDD4B65}</Project> + </ProjectReference> + <ProjectReference Include="..\slang\slang.vcxproj"> + <Project>{DB00DA62-0533-4AFD-B59F-A67D5B3A0808}</Project> + </ProjectReference> + </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> </ImportGroup> diff --git a/build/visual-studio/gfx/gfx.vcxproj.filters b/build/visual-studio/gfx/gfx.vcxproj.filters index 90caef2f9..97658fffa 100644 --- a/build/visual-studio/gfx/gfx.vcxproj.filters +++ b/build/visual-studio/gfx/gfx.vcxproj.filters @@ -51,15 +51,6 @@ <ClInclude Include="..\..\..\tools\gfx\renderer-shared.h"> <Filter>Header Files</Filter> </ClInclude> - <ClInclude Include="..\..\..\tools\gfx\shader-cursor.h"> - <Filter>Header Files</Filter> - </ClInclude> - <ClInclude Include="..\..\..\tools\gfx\slang-gfx-helper.h"> - <Filter>Header Files</Filter> - </ClInclude> - <ClInclude Include="..\..\..\tools\gfx\surface.h"> - <Filter>Header Files</Filter> - </ClInclude> <ClInclude Include="..\..\..\tools\gfx\vulkan\render-vk.h"> <Filter>Header Files</Filter> </ClInclude> @@ -119,15 +110,6 @@ <ClCompile Include="..\..\..\tools\gfx\renderer-shared.cpp"> <Filter>Source Files</Filter> </ClCompile> - <ClCompile Include="..\..\..\tools\gfx\shader-cursor.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="..\..\..\tools\gfx\slang-gfx-helper.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="..\..\..\tools\gfx\surface.cpp"> - <Filter>Source Files</Filter> - </ClCompile> <ClCompile Include="..\..\..\tools\gfx\vulkan\render-vk.cpp"> <Filter>Source Files</Filter> </ClCompile> diff --git a/build/visual-studio/gpu-printing/gpu-printing.vcxproj b/build/visual-studio/gpu-printing/gpu-printing.vcxproj index 9b8834666..f7b783f39 100644 --- a/build/visual-studio/gpu-printing/gpu-printing.vcxproj +++ b/build/visual-studio/gpu-printing/gpu-printing.vcxproj @@ -183,6 +183,9 @@ <ProjectReference Include="..\gfx\gfx.vcxproj"> <Project>{222F7498-B40C-4F3F-A704-DDEB91A4484A}</Project> </ProjectReference> + <ProjectReference Include="..\gfx-util\gfx-util.vcxproj"> + <Project>{F5ADB74E-02A7-44FB-AA3B-FC02F8AC7A4B}</Project> + </ProjectReference> <ProjectReference Include="..\graphics-app-framework\graphics-app-framework.vcxproj"> <Project>{3565FE5E-4FA3-11EB-AE93-0242AC130002}</Project> </ProjectReference> diff --git a/build/visual-studio/hello-world/hello-world.vcxproj b/build/visual-studio/hello-world/hello-world.vcxproj index 60dde7007..a7a51362b 100644 --- a/build/visual-studio/hello-world/hello-world.vcxproj +++ b/build/visual-studio/hello-world/hello-world.vcxproj @@ -177,6 +177,9 @@ <ProjectReference Include="..\gfx\gfx.vcxproj"> <Project>{222F7498-B40C-4F3F-A704-DDEB91A4484A}</Project> </ProjectReference> + <ProjectReference Include="..\gfx-util\gfx-util.vcxproj"> + <Project>{F5ADB74E-02A7-44FB-AA3B-FC02F8AC7A4B}</Project> + </ProjectReference> <ProjectReference Include="..\graphics-app-framework\graphics-app-framework.vcxproj"> <Project>{3565FE5E-4FA3-11EB-AE93-0242AC130002}</Project> </ProjectReference> diff --git a/build/visual-studio/heterogeneous-hello-world/heterogeneous-hello-world.vcxproj b/build/visual-studio/heterogeneous-hello-world/heterogeneous-hello-world.vcxproj index 74bd9213b..78bdb1f3e 100644 --- a/build/visual-studio/heterogeneous-hello-world/heterogeneous-hello-world.vcxproj +++ b/build/visual-studio/heterogeneous-hello-world/heterogeneous-hello-world.vcxproj @@ -178,6 +178,9 @@ <ProjectReference Include="..\gfx\gfx.vcxproj"> <Project>{222F7498-B40C-4F3F-A704-DDEB91A4484A}</Project> </ProjectReference> + <ProjectReference Include="..\gfx-util\gfx-util.vcxproj"> + <Project>{F5ADB74E-02A7-44FB-AA3B-FC02F8AC7A4B}</Project> + </ProjectReference> <ProjectReference Include="..\graphics-app-framework\graphics-app-framework.vcxproj"> <Project>{3565FE5E-4FA3-11EB-AE93-0242AC130002}</Project> </ProjectReference> diff --git a/build/visual-studio/model-viewer/model-viewer.vcxproj b/build/visual-studio/model-viewer/model-viewer.vcxproj index b7523fe4f..8c8044d48 100644 --- a/build/visual-studio/model-viewer/model-viewer.vcxproj +++ b/build/visual-studio/model-viewer/model-viewer.vcxproj @@ -177,6 +177,9 @@ <ProjectReference Include="..\gfx\gfx.vcxproj"> <Project>{222F7498-B40C-4F3F-A704-DDEB91A4484A}</Project> </ProjectReference> + <ProjectReference Include="..\gfx-util\gfx-util.vcxproj"> + <Project>{F5ADB74E-02A7-44FB-AA3B-FC02F8AC7A4B}</Project> + </ProjectReference> <ProjectReference Include="..\graphics-app-framework\graphics-app-framework.vcxproj"> <Project>{3565FE5E-4FA3-11EB-AE93-0242AC130002}</Project> </ProjectReference> diff --git a/build/visual-studio/render-test-tool/render-test-tool.vcxproj b/build/visual-studio/render-test-tool/render-test-tool.vcxproj index b9841e122..e74392972 100644 --- a/build/visual-studio/render-test-tool/render-test-tool.vcxproj +++ b/build/visual-studio/render-test-tool/render-test-tool.vcxproj @@ -186,6 +186,7 @@ <ClInclude Include="..\..\..\tools\render-test\shader-input-layout.h" /> <ClInclude Include="..\..\..\tools\render-test\shader-renderer-util.h" /> <ClInclude Include="..\..\..\tools\render-test\slang-support.h" /> + <ClInclude Include="..\..\..\tools\render-test\surface.h" /> <ClInclude Include="..\..\..\tools\render-test\window.h" /> </ItemGroup> <ItemGroup> @@ -197,6 +198,7 @@ <ClCompile Include="..\..\..\tools\render-test\shader-input-layout.cpp" /> <ClCompile Include="..\..\..\tools\render-test\shader-renderer-util.cpp" /> <ClCompile Include="..\..\..\tools\render-test\slang-support.cpp" /> + <ClCompile Include="..\..\..\tools\render-test\surface.cpp" /> <ClCompile Include="..\..\..\tools\render-test\window.cpp" /> <ClCompile Include="..\..\..\tools\render-test\windows\win-window.cpp" /> </ItemGroup> @@ -210,6 +212,9 @@ <ProjectReference Include="..\gfx\gfx.vcxproj"> <Project>{222F7498-B40C-4F3F-A704-DDEB91A4484A}</Project> </ProjectReference> + <ProjectReference Include="..\gfx-util\gfx-util.vcxproj"> + <Project>{F5ADB74E-02A7-44FB-AA3B-FC02F8AC7A4B}</Project> + </ProjectReference> <ProjectReference Include="..\graphics-app-framework\graphics-app-framework.vcxproj"> <Project>{3565FE5E-4FA3-11EB-AE93-0242AC130002}</Project> </ProjectReference> diff --git a/build/visual-studio/render-test-tool/render-test-tool.vcxproj.filters b/build/visual-studio/render-test-tool/render-test-tool.vcxproj.filters index 1c0d82cdd..5223edb08 100644 --- a/build/visual-studio/render-test-tool/render-test-tool.vcxproj.filters +++ b/build/visual-studio/render-test-tool/render-test-tool.vcxproj.filters @@ -30,6 +30,9 @@ <ClInclude Include="..\..\..\tools\render-test\slang-support.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="..\..\..\tools\render-test\surface.h"> + <Filter>Header Files</Filter> + </ClInclude> <ClInclude Include="..\..\..\tools\render-test\window.h"> <Filter>Header Files</Filter> </ClInclude> @@ -59,6 +62,9 @@ <ClCompile Include="..\..\..\tools\render-test\slang-support.cpp"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="..\..\..\tools\render-test\surface.cpp"> + <Filter>Source Files</Filter> + </ClCompile> <ClCompile Include="..\..\..\tools\render-test\window.cpp"> <Filter>Source Files</Filter> </ClCompile> diff --git a/build/visual-studio/shader-toy/shader-toy.vcxproj b/build/visual-studio/shader-toy/shader-toy.vcxproj index 5c540113b..9fd7014a3 100644 --- a/build/visual-studio/shader-toy/shader-toy.vcxproj +++ b/build/visual-studio/shader-toy/shader-toy.vcxproj @@ -178,6 +178,9 @@ <ProjectReference Include="..\gfx\gfx.vcxproj"> <Project>{222F7498-B40C-4F3F-A704-DDEB91A4484A}</Project> </ProjectReference> + <ProjectReference Include="..\gfx-util\gfx-util.vcxproj"> + <Project>{F5ADB74E-02A7-44FB-AA3B-FC02F8AC7A4B}</Project> + </ProjectReference> <ProjectReference Include="..\graphics-app-framework\graphics-app-framework.vcxproj"> <Project>{3565FE5E-4FA3-11EB-AE93-0242AC130002}</Project> </ProjectReference> diff --git a/examples/gpu-printing/main.cpp b/examples/gpu-printing/main.cpp index 03b20b969..57e096043 100644 --- a/examples/gpu-printing/main.cpp +++ b/examples/gpu-printing/main.cpp @@ -6,7 +6,6 @@ using Slang::ComPtr; #include "gfx/render.h" -#include "gfx/d3d11/render-d3d11.h" #include "tools/graphics-app-framework/window.h" #include "source/core/slang-basic.h" using namespace gfx; @@ -119,7 +118,7 @@ Result execute() windowDesc.height = gWindowHeight; gWindow = createWindow(windowDesc); - createD3D11Renderer(gRenderer.writeRef()); + gfxGetCreateFunc(gfx::RendererType::DirectX11)(gRenderer.writeRef()); IRenderer::Desc rendererDesc; rendererDesc.width = gWindowWidth; rendererDesc.height = gWindowHeight; diff --git a/examples/hello-world/main.cpp b/examples/hello-world/main.cpp index 77ca8a978..959aa2881 100644 --- a/examples/hello-world/main.cpp +++ b/examples/hello-world/main.cpp @@ -33,7 +33,6 @@ // design choices in their abstraction layer. // #include "gfx/render.h" -#include "gfx/d3d11/render-d3d11.h" #include "tools/graphics-app-framework/window.h" #include "slang-com-ptr.h" #include "source/core/slang-basic.h" @@ -261,7 +260,7 @@ Slang::Result initialize() // A future version of this example may support multiple // platforms/APIs. // - createD3D11Renderer(gRenderer.writeRef()); + gfxGetCreateFunc(gfx::RendererType::DirectX11)(gRenderer.writeRef()); IRenderer::Desc rendererDesc; rendererDesc.width = gWindowWidth; rendererDesc.height = gWindowHeight; diff --git a/examples/heterogeneous-hello-world/main.cpp b/examples/heterogeneous-hello-world/main.cpp index 0446ea1a7..8cf3894ed 100644 --- a/examples/heterogeneous-hello-world/main.cpp +++ b/examples/heterogeneous-hello-world/main.cpp @@ -34,7 +34,6 @@ // #include "slang-com-ptr.h" #include "gfx/render.h" -#include "gfx/d3d11/render-d3d11.h" #include "tools/graphics-app-framework/window.h" #include "../../prelude/slang-cpp-types.h" #include "source/core/slang-basic.h" @@ -124,7 +123,7 @@ gfx::IRenderer* createRenderer( // A future version of this example may support multiple // platforms/APIs. // - createD3D11Renderer(gRenderer.writeRef()); + gfxGetCreateFunc(gfx::RendererType::DirectX11)(gRenderer.writeRef()); IRenderer::Desc rendererDesc; rendererDesc.width = windowWidth; rendererDesc.height = windowHeight; diff --git a/examples/model-viewer/main.cpp b/examples/model-viewer/main.cpp index 387ec7293..720d421e2 100644 --- a/examples/model-viewer/main.cpp +++ b/examples/model-viewer/main.cpp @@ -18,7 +18,6 @@ // #include "graphics-app-framework/model.h" #include "gfx/render.h" -#include "gfx/d3d11/render-d3d11.h" #include "graphics-app-framework/vector-math.h" #include "graphics-app-framework/window.h" #include "graphics-app-framework/gui.h" @@ -2051,7 +2050,7 @@ Result initialize() windowDesc.userData = this; gWindow = createWindow(windowDesc); - createD3D11Renderer(gRenderer.writeRef()); + gfxGetCreateFunc(gfx::RendererType::DirectX11)(gRenderer.writeRef()); IRenderer::Desc rendererDesc; rendererDesc.width = gWindowWidth; rendererDesc.height = gWindowHeight; diff --git a/examples/shader-toy/main.cpp b/examples/shader-toy/main.cpp index e2efc325c..23193496b 100644 --- a/examples/shader-toy/main.cpp +++ b/examples/shader-toy/main.cpp @@ -20,7 +20,6 @@ using Slang::ComPtr; // compiler, and API. // #include "gfx/render.h" -#include "gfx/d3d11/render-d3d11.h" #include "tools/graphics-app-framework/window.h" #include "source/core/slang-basic.h" @@ -385,7 +384,7 @@ Result initialize() windowDesc.userData = this; gWindow = createWindow(windowDesc); - createD3D11Renderer(gRenderer.writeRef()); + gfxGetCreateFunc(gfx::RendererType::DirectX11)(gRenderer.writeRef()); IRenderer::Desc rendererDesc; rendererDesc.width = gWindowWidth; rendererDesc.height = gWindowHeight; diff --git a/premake5.lua b/premake5.lua index 36a7ead0a..211955ae1 100644 --- a/premake5.lua +++ b/premake5.lua @@ -525,7 +525,7 @@ function example(name) -- and the `gfx` abstraction layer (which in turn -- depends on the `core` library). We specify all of that here, -- rather than in each example. - links { "slang", "core", "gfx", "graphics-app-framework" } + links { "slang", "core", "gfx", "gfx-util", "graphics-app-framework" } end -- @@ -698,7 +698,7 @@ toolSharedLibrary "render-test" uuid "61F7EB00-7281-4BF3-9470-7C2EA92620C3" includedirs { ".", "external", "source", "tools/gfx", "tools/graphics-app-framework" } - links { "core", "slang", "gfx", "graphics-app-framework" } + links { "core", "slang", "gfx", "gfx-util", "graphics-app-framework" } if isTargetWindows then addSourceDir "tools/render-test/windows" @@ -717,7 +717,7 @@ toolSharedLibrary "render-test" defines { "RENDER_TEST_CUDA" } includedirs { cudaPath .. "/include" } includedirs { cudaPath .. "/include", cudaPath .. "/common/inc" } - + links { "cuda", "cudart" } if optixPath then defines { "RENDER_TEST_OPTIX" } includedirs { optixPath .. "include/" } @@ -739,9 +739,12 @@ tool "gfx" uuid "222F7498-B40C-4F3F-A704-DDEB91A4484A" -- Unlike most of the code under `tools/`, this is a library -- rather than a stand-alone executable. - kind "StaticLib" + kind "SharedLib" + links { "core", "slang" } pic "On" - + + defines { "SLANG_GFX_DYNAMIC", "SLANG_GFX_DYNAMIC_EXPORT" } + includedirs { ".", "external", "source" } -- Will compile across targets @@ -809,6 +812,18 @@ tool "gfx" end -- +-- `gfx-util` is a static library containing utilities and helpers for using +-- the `gfx` library. +-- +tool "gfx-util" + uuid "F5ADB74E-02A7-44FB-AA3B-FC02F8AC7A4B" + kind "StaticLib" + pic "On" + + includedirs { ".", "source" } + + addSourceDir "tools/gfx-util" +-- -- `graphics-app-framework` contains all the utils for a simple graphics application. -- tool "graphics-app-framework" @@ -47,6 +47,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{FD47AE19 EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gfx", "build\visual-studio\gfx\gfx.vcxproj", "{222F7498-B40C-4F3F-A704-DDEB91A4484A}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gfx-util", "build\visual-studio\gfx-util\gfx-util.vcxproj", "{F5ADB74E-02A7-44FB-AA3B-FC02F8AC7A4B}" +EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "graphics-app-framework", "build\visual-studio\graphics-app-framework\graphics-app-framework.vcxproj", "{3565FE5E-4FA3-11EB-AE93-0242AC130002}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "slang-cpp-extractor", "build\visual-studio\slang-cpp-extractor\slang-cpp-extractor.vcxproj", "{CA8A30D1-8FA9-4330-B7F7-84709246D8DC}" @@ -185,6 +187,14 @@ Global {222F7498-B40C-4F3F-A704-DDEB91A4484A}.Release|Win32.Build.0 = Release|Win32 {222F7498-B40C-4F3F-A704-DDEB91A4484A}.Release|x64.ActiveCfg = Release|x64 {222F7498-B40C-4F3F-A704-DDEB91A4484A}.Release|x64.Build.0 = Release|x64 + {F5ADB74E-02A7-44FB-AA3B-FC02F8AC7A4B}.Debug|Win32.ActiveCfg = Debug|Win32 + {F5ADB74E-02A7-44FB-AA3B-FC02F8AC7A4B}.Debug|Win32.Build.0 = Debug|Win32 + {F5ADB74E-02A7-44FB-AA3B-FC02F8AC7A4B}.Debug|x64.ActiveCfg = Debug|x64 + {F5ADB74E-02A7-44FB-AA3B-FC02F8AC7A4B}.Debug|x64.Build.0 = Debug|x64 + {F5ADB74E-02A7-44FB-AA3B-FC02F8AC7A4B}.Release|Win32.ActiveCfg = Release|Win32 + {F5ADB74E-02A7-44FB-AA3B-FC02F8AC7A4B}.Release|Win32.Build.0 = Release|Win32 + {F5ADB74E-02A7-44FB-AA3B-FC02F8AC7A4B}.Release|x64.ActiveCfg = Release|x64 + {F5ADB74E-02A7-44FB-AA3B-FC02F8AC7A4B}.Release|x64.Build.0 = Release|x64 {3565FE5E-4FA3-11EB-AE93-0242AC130002}.Debug|Win32.ActiveCfg = Debug|Win32 {3565FE5E-4FA3-11EB-AE93-0242AC130002}.Debug|Win32.Build.0 = Debug|Win32 {3565FE5E-4FA3-11EB-AE93-0242AC130002}.Debug|x64.ActiveCfg = Debug|x64 @@ -240,6 +250,7 @@ Global {61F7EB00-7281-4BF3-9470-7C2EA92620C3} = {57B5AA5E-C340-1823-CC51-9B17385C7423} {C5ACCA6E-C04D-4B36-8516-3752B3C13C2F} = {57B5AA5E-C340-1823-CC51-9B17385C7423} {222F7498-B40C-4F3F-A704-DDEB91A4484A} = {FD47AE19-69FD-260F-F2F1-20E65EA61D13} + {F5ADB74E-02A7-44FB-AA3B-FC02F8AC7A4B} = {FD47AE19-69FD-260F-F2F1-20E65EA61D13} {3565FE5E-4FA3-11EB-AE93-0242AC130002} = {FD47AE19-69FD-260F-F2F1-20E65EA61D13} {CA8A30D1-8FA9-4330-B7F7-84709246D8DC} = {FD47AE19-69FD-260F-F2F1-20E65EA61D13} {7F773DD9-EB8F-2403-B43C-B49C2014B99C} = {FD47AE19-69FD-260F-F2F1-20E65EA61D13} diff --git a/tools/gfx/shader-cursor.cpp b/tools/gfx-util/shader-cursor.cpp index 65cf2f8ac..65cf2f8ac 100644 --- a/tools/gfx/shader-cursor.cpp +++ b/tools/gfx-util/shader-cursor.cpp diff --git a/tools/gfx/shader-cursor.h b/tools/gfx-util/shader-cursor.h index 82794be9a..82794be9a 100644 --- a/tools/gfx/shader-cursor.h +++ b/tools/gfx-util/shader-cursor.h diff --git a/tools/gfx/cuda/render-cuda.cpp b/tools/gfx/cuda/render-cuda.cpp index bf316546e..0e4ee6c13 100644 --- a/tools/gfx/cuda/render-cuda.cpp +++ b/tools/gfx/cuda/render-cuda.cpp @@ -1493,10 +1493,14 @@ public: SLANG_UNUSED(outState); return SLANG_E_NOT_AVAILABLE; } - virtual SLANG_NO_THROW SlangResult SLANG_MCALL - captureScreenSurface(Surface& surfaceOut) override + virtual SLANG_NO_THROW SlangResult SLANG_MCALL captureScreenSurface( + void* buffer, size_t* inOutBufferSize, size_t* outRowPitch, size_t* outPixelSize) override { - SLANG_UNUSED(surfaceOut); + SLANG_UNUSED(buffer); + SLANG_UNUSED(inOutBufferSize); + SLANG_UNUSED(outRowPitch); + SLANG_UNUSED(outPixelSize); + return SLANG_E_NOT_AVAILABLE; } virtual SLANG_NO_THROW void SLANG_MCALL diff --git a/tools/gfx/d3d11/render-d3d11.cpp b/tools/gfx/d3d11/render-d3d11.cpp index 8bf11c39d..4ac90f47f 100644 --- a/tools/gfx/d3d11/render-d3d11.cpp +++ b/tools/gfx/d3d11/render-d3d11.cpp @@ -11,8 +11,6 @@ #include "../d3d/d3d-util.h" #include "../nvapi/nvapi-util.h" -#include "../surface.h" - // In order to use the Slang API, we need to include its header //#include <slang.h> @@ -106,8 +104,8 @@ public: virtual SLANG_NO_THROW Result SLANG_MCALL createComputePipelineState( const ComputePipelineStateDesc& desc, IPipelineState** outState) override; - virtual SLANG_NO_THROW SlangResult SLANG_MCALL - captureScreenSurface(Surface& surfaceOut) override; + virtual SLANG_NO_THROW SlangResult SLANG_MCALL captureScreenSurface( + void* buffer, size_t* inOutBufferSize, size_t* outRowPitch, size_t* outPixelSize) override; virtual SLANG_NO_THROW void* SLANG_MCALL map(IBufferResource* buffer, MapFlavor flavor) override; virtual SLANG_NO_THROW void SLANG_MCALL unmap(IBufferResource* buffer) override; @@ -491,7 +489,14 @@ public: }; /// Capture a texture to a file - static HRESULT captureTextureToSurface(ID3D11Device* device, ID3D11DeviceContext* context, ID3D11Texture2D* texture, Surface& surfaceOut); + static HRESULT captureTextureToSurface( + ID3D11Device* device, + ID3D11DeviceContext* context, + TextureResourceImpl* texture, + void* buffer, + size_t* inOutBufferSize, + size_t* outRowPitch, + size_t* outPixelSize); void _flushGraphicsState(); void _flushComputeState(); @@ -569,27 +574,50 @@ D3D11Renderer::ScopeNVAPI::~ScopeNVAPI() // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!D3D11Renderer !!!!!!!!!!!!!!!!!!!!!!!!!!!!! -/* static */HRESULT D3D11Renderer::captureTextureToSurface(ID3D11Device* device, ID3D11DeviceContext* context, ID3D11Texture2D* texture, Surface& surfaceOut) +/* static */ HRESULT D3D11Renderer::captureTextureToSurface( + ID3D11Device* device, + ID3D11DeviceContext* context, + TextureResourceImpl* texture, + void* buffer, + size_t* inOutBufferSize, + size_t* outRowPitch, + size_t* outPixelSize) { if (!context) return E_INVALIDARG; if (!texture) return E_INVALIDARG; - D3D11_TEXTURE2D_DESC textureDesc; - texture->GetDesc(&textureDesc); - // Don't bother supporting MSAA for right now - if (textureDesc.SampleDesc.Count > 1) + if (texture->getDesc()->sampleDesc.numSamples > 1) { fprintf(stderr, "ERROR: cannot capture multi-sample texture\n"); return E_INVALIDARG; } + size_t bytesPerPixel = sizeof(uint32_t); + size_t rowPitch = int(texture->getDesc()->size.width) * bytesPerPixel; + size_t bufferSize = rowPitch * int(texture->getDesc()->size.height); + if (outRowPitch) + *outRowPitch = rowPitch; + if (outPixelSize) + *outPixelSize = bytesPerPixel; + if (!buffer || *inOutBufferSize == 0) + { + *inOutBufferSize = bufferSize; + return S_OK; + } + if (*inOutBufferSize < bufferSize) + return SLANG_ERROR_INSUFFICIENT_BUFFER; + + D3D11_TEXTURE2D_DESC textureDesc; + auto d3d11Texture = ((ID3D11Texture2D*)texture->m_resource.get()); + d3d11Texture->GetDesc(&textureDesc); + HRESULT hr = S_OK; ComPtr<ID3D11Texture2D> stagingTexture; if (textureDesc.Usage == D3D11_USAGE_STAGING && (textureDesc.CPUAccessFlags & D3D11_CPU_ACCESS_READ)) { - stagingTexture = texture; + stagingTexture = d3d11Texture; } else { @@ -606,7 +634,7 @@ D3D11Renderer::ScopeNVAPI::~ScopeNVAPI() return hr; } - context->CopyResource(stagingTexture, texture); + context->CopyResource(stagingTexture, d3d11Texture); } // Now just read back texels from the staging textures @@ -614,11 +642,16 @@ D3D11Renderer::ScopeNVAPI::~ScopeNVAPI() D3D11_MAPPED_SUBRESOURCE mappedResource; SLANG_RETURN_ON_FAIL(context->Map(stagingTexture, 0, D3D11_MAP_READ, 0, &mappedResource)); - Result res = surfaceOut.set(textureDesc.Width, textureDesc.Height, Format::RGBA_Unorm_UInt8, mappedResource.RowPitch, mappedResource.pData, SurfaceAllocator::getMallocAllocator()); - + for (size_t y = 0; y < textureDesc.Height; y++) + { + memcpy( + (char*)buffer + y * (*outRowPitch), + (char*)mappedResource.pData + y * mappedResource.RowPitch, + *outRowPitch); + } // Make sure to unmap context->Unmap(stagingTexture, 0); - return res; + return SLANG_OK; } } @@ -891,9 +924,17 @@ TextureResource::Desc D3D11Renderer::getSwapChainTextureDesc() return desc; } -SlangResult D3D11Renderer::captureScreenSurface(Surface& surfaceOut) +SlangResult D3D11Renderer::captureScreenSurface( + void* buffer, size_t* inOutBufferSize, size_t* outRowPitch, size_t* outPixelSize) { - return captureTextureToSurface(m_device, m_immediateContext, (ID3D11Texture2D*) m_primaryRenderTargetTexture->m_resource.get(), surfaceOut); + return captureTextureToSurface( + m_device, + m_immediateContext, + m_primaryRenderTargetTexture.Ptr(), + buffer, + inOutBufferSize, + outRowPitch, + outPixelSize); } static D3D11_BIND_FLAG _calcResourceFlag(IResource::BindFlag::Enum bindFlag) diff --git a/tools/gfx/d3d12/render-d3d12.cpp b/tools/gfx/d3d12/render-d3d12.cpp index 6b66c5403..3db93df50 100644 --- a/tools/gfx/d3d12/render-d3d12.cpp +++ b/tools/gfx/d3d12/render-d3d12.cpp @@ -7,7 +7,6 @@ #include "../renderer-shared.h" #include "../render-graphics-common.h" -#include "../surface.h" #include "core/slang-basic.h" // In order to use the Slang API, we need to include its header @@ -112,8 +111,8 @@ public: virtual SLANG_NO_THROW Result SLANG_MCALL createComputePipelineState( const ComputePipelineStateDesc& desc, IPipelineState** outState) override; - virtual SLANG_NO_THROW SlangResult SLANG_MCALL - captureScreenSurface(Surface& surfaceOut) override; + virtual SLANG_NO_THROW SlangResult SLANG_MCALL captureScreenSurface( + void* buffer, size_t* inOutBufferSize, size_t* outRowPitch, size_t* outPixelSize) override; virtual SLANG_NO_THROW void* SLANG_MCALL map(IBufferResource* buffer, MapFlavor flavor) override; @@ -648,7 +647,12 @@ protected: void submitGpuWorkAndWait(); void _resetCommandList(); - Result captureTextureToSurface(D3D12Resource& resource, Surface& surfaceOut); + Result captureTextureToSurface( + D3D12Resource& resource, + void* buffer, + size_t* inOutBufferSize, + size_t* outRowPitch, + size_t* outPixelSize); FrameInfo& getFrame() { return m_frameInfos[m_frameIndex]; } const FrameInfo& getFrame() const { return m_frameInfos[m_frameIndex]; } @@ -1063,7 +1067,12 @@ void D3D12Renderer::submitGpuWorkAndWait() waitForGpu(); } -Result D3D12Renderer::captureTextureToSurface(D3D12Resource& resource, Surface& surfaceOut) +Result D3D12Renderer::captureTextureToSurface( + D3D12Resource& resource, + void* buffer, + size_t* inOutBufferSize, + size_t* outRowPitch, + size_t* outPixelSize) { const D3D12_RESOURCE_STATES initialState = resource.getState(); @@ -1079,7 +1088,17 @@ Result D3D12Renderer::captureTextureToSurface(D3D12Resource& resource, Surface& size_t bytesPerPixel = sizeof(uint32_t); size_t rowPitch = int(desc.Width) * bytesPerPixel; size_t bufferSize = rowPitch * int(desc.Height); - + if (outRowPitch) + *outRowPitch = rowPitch; + if (outPixelSize) + *outPixelSize = bytesPerPixel; + if (!buffer || *inOutBufferSize == 0) + { + *inOutBufferSize = bufferSize; + return SLANG_OK; + } + if (*inOutBufferSize < bufferSize) + return SLANG_ERROR_INSUFFICIENT_BUFFER; D3D12Resource stagingResource; { D3D12_RESOURCE_DESC stagingDesc; @@ -1136,10 +1155,10 @@ Result D3D12Renderer::captureTextureToSurface(D3D12Resource& resource, Surface& SLANG_RETURN_ON_FAIL(dxResource->Map(0, &readRange, reinterpret_cast<void**>(&data))); - Result res = surfaceOut.set(int(desc.Width), int(desc.Height), Format::RGBA_Unorm_UInt8, int(rowPitch), data, SurfaceAllocator::getMallocAllocator()); + memcpy(buffer, data, bufferSize); dxResource->Unmap(0, nullptr); - return res; + return SLANG_OK; } } @@ -1800,9 +1819,10 @@ TextureResource::Desc D3D12Renderer::getSwapChainTextureDesc() return desc; } -SlangResult D3D12Renderer::captureScreenSurface(Surface& surfaceOut) +SlangResult D3D12Renderer::captureScreenSurface( + void* buffer, size_t* inOutBufferSize, size_t* outRowPitch, size_t* outPixelSize) { - return captureTextureToSurface(*m_renderTargets[m_renderTargetIndex], surfaceOut); + return captureTextureToSurface(*m_renderTargets[m_renderTargetIndex], buffer, inOutBufferSize, outRowPitch, outPixelSize); } static D3D12_RESOURCE_STATES _calcResourceState(IResource::Usage usage) diff --git a/tools/gfx/open-gl/render-gl.cpp b/tools/gfx/open-gl/render-gl.cpp index 826192e8d..7ee73366b 100644 --- a/tools/gfx/open-gl/render-gl.cpp +++ b/tools/gfx/open-gl/render-gl.cpp @@ -13,8 +13,6 @@ #include "core/slang-secure-crt.h" #include "external/stb/stb_image_write.h" -#include "../surface.h" - // TODO(tfoley): eventually we should be able to run these // tests on non-Windows targets to confirm that cross-compilation // at least *works* on those platforms... @@ -125,8 +123,8 @@ public: virtual SLANG_NO_THROW Result SLANG_MCALL createComputePipelineState( const ComputePipelineStateDesc& desc, IPipelineState** outState) override; - virtual SLANG_NO_THROW SlangResult SLANG_MCALL - captureScreenSurface(Surface& surfaceOut) override; + virtual SLANG_NO_THROW SlangResult SLANG_MCALL captureScreenSurface( + void* buffer, size_t* inOutBufferSize, size_t* outRowPitch, size_t* outPixelSize) override; virtual SLANG_NO_THROW void* SLANG_MCALL map(IBufferResource* buffer, MapFlavor flavor) override; virtual SLANG_NO_THROW void SLANG_MCALL unmap(IBufferResource* buffer) override; @@ -882,11 +880,36 @@ SLANG_NO_THROW TextureResource::Desc SLANG_MCALL GLRenderer::getSwapChainTexture return desc; } -SLANG_NO_THROW Result SLANG_MCALL GLRenderer::captureScreenSurface(Surface& surfaceOut) +SLANG_NO_THROW Result SLANG_MCALL GLRenderer::captureScreenSurface( + void* buffer, size_t* inOutBufferSize, size_t* outRowPitch, size_t* outPixelSize) { - SLANG_RETURN_ON_FAIL(surfaceOut.allocate(m_desc.width, m_desc.height, Format::RGBA_Unorm_UInt8, 1, SurfaceAllocator::getMallocAllocator())); - glReadPixels(0, 0, m_desc.width, m_desc.height, GL_RGBA, GL_UNSIGNED_BYTE, surfaceOut.m_data); - surfaceOut.flipInplaceVertically(); + size_t requiredSize = m_desc.width * m_desc.height * sizeof(uint32_t); + if (outRowPitch) + *outRowPitch = m_desc.width * sizeof(uint32_t); + if (outPixelSize) + *outPixelSize = sizeof(uint32_t); + + if (!buffer || *inOutBufferSize == 0) + { + *inOutBufferSize = requiredSize; + return SLANG_OK; + } + if (*inOutBufferSize < requiredSize) + return SLANG_ERROR_INSUFFICIENT_BUFFER; + + glReadPixels(0, 0, m_desc.width, m_desc.height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); + + // Flip pixels vertically in-place. + for (int y = 0; y < m_desc.height / 2; y++) + { + for (int x = 0; x < m_desc.width; x++) + { + std::swap( + *((uint32_t*)buffer + y * m_desc.width + x), + *((uint32_t*)buffer + (m_desc.height - y - 1) * m_desc.width + x)); + } + } + return SLANG_OK; } diff --git a/tools/gfx/render.h b/tools/gfx/render.h index 0bc8692eb..8e1a5d665 100644 --- a/tools/gfx/render.h +++ b/tools/gfx/render.h @@ -38,9 +38,6 @@ typedef SlangResult Result; typedef SlangInt Int; typedef SlangUInt UInt; -// pre declare types -class Surface; - // Declare opaque type class IInputLayout: public ISlangUnknown { @@ -1281,7 +1278,7 @@ public: } /// Captures the back buffer and stores the result in surfaceOut. If the surface contains data - it will either be overwritten (if same size and format), or freed and a re-allocated. - virtual SLANG_NO_THROW SlangResult SLANG_MCALL captureScreenSurface(Surface& surfaceOut) = 0; + virtual SLANG_NO_THROW SlangResult SLANG_MCALL captureScreenSurface(void* buffer, size_t *inOutBufferSize, size_t* outRowPitch, size_t* outPixelSize) = 0; virtual SLANG_NO_THROW void* SLANG_MCALL map(IBufferResource* buffer, MapFlavor flavor) = 0; virtual SLANG_NO_THROW void SLANG_MCALL unmap(IBufferResource* buffer) = 0; diff --git a/tools/gfx/slang-gfx-helper.cpp b/tools/gfx/slang-gfx-helper.cpp deleted file mode 100644 index 499e462b0..000000000 --- a/tools/gfx/slang-gfx-helper.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "slang-gfx-helper.h" -#include "renderer-shared.h" - -namespace gfx -{ -} // namespace gfx diff --git a/tools/gfx/slang-gfx-helper.h b/tools/gfx/slang-gfx-helper.h deleted file mode 100644 index 1cd3fe64c..000000000 --- a/tools/gfx/slang-gfx-helper.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -#include "render.h" - -namespace gfx -{ - - -} diff --git a/tools/gfx/vulkan/render-vk.cpp b/tools/gfx/vulkan/render-vk.cpp index c2a1e36bf..382f12f85 100644 --- a/tools/gfx/vulkan/render-vk.cpp +++ b/tools/gfx/vulkan/render-vk.cpp @@ -12,8 +12,6 @@ #include "vk-device-queue.h" #include "vk-swap-chain.h" -#include "../surface.h" - // Vulkan has a different coordinate system to ogl // http://anki3d.org/vulkan-coordinate-system/ @@ -88,7 +86,8 @@ public: const ComputePipelineStateDesc& desc, IPipelineState** outState) override; - virtual SLANG_NO_THROW SlangResult SLANG_MCALL captureScreenSurface(Surface& surface) override; + virtual SLANG_NO_THROW SlangResult SLANG_MCALL captureScreenSurface( + void* buffer, size_t* inOutBufferSize, size_t* outRowPitch, size_t* outPixelSize) override; virtual SLANG_NO_THROW void* SLANG_MCALL map(IBufferResource* buffer, MapFlavor flavor) override; virtual SLANG_NO_THROW void SLANG_MCALL unmap(IBufferResource* buffer) override; @@ -1439,8 +1438,13 @@ TextureResource::Desc VKRenderer::getSwapChainTextureDesc() return desc; } -SlangResult VKRenderer::captureScreenSurface(Surface& surfaceOut) +SlangResult VKRenderer::captureScreenSurface( + void* buffer, size_t* inOutBufferSize, size_t* outRowPitch, size_t* outPixelSize) { + SLANG_UNUSED(buffer); + SLANG_UNUSED(inOutBufferSize); + SLANG_UNUSED(outRowPitch); + SLANG_UNUSED(outPixelSize); return SLANG_FAIL; } @@ -1594,6 +1598,21 @@ void VKRenderer::_transitionImageLayout(VkImage image, VkFormat format, const Te m_api.vkCmdPipelineBarrier(commandBuffer, sourceStage, destinationStage, 0, 0, nullptr, 0, nullptr, 1, &barrier); } +size_t calcRowSize(Format format, int width) +{ + size_t pixelSize = gfxGetFormatSize(format); + if (pixelSize == 0) + { + return 0; + } + return size_t(pixelSize * width); +} + +size_t calcNumRows(Format format, int height) +{ + return (size_t)height; +} + Result VKRenderer::createTextureResource(IResource::Usage initialUsage, const ITextureResource::Desc& descIn, const ITextureResource::Data* initData, ITextureResource** outResource) { TextureResource::Desc desc(descIn); @@ -1704,8 +1723,8 @@ Result VKRenderer::createTextureResource(IResource::Usage initialUsage, const IT { const TextureResource::Size mipSize = desc.size.calcMipSize(j); - const int rowSizeInBytes = Surface::calcRowSize(desc.format, mipSize.width); - const int numRows = Surface::calcNumRows(desc.format, mipSize.height); + const int rowSizeInBytes = calcRowSize(desc.format, mipSize.width); + const int numRows = calcNumRows(desc.format, mipSize.height); mipSizes.add(mipSize); @@ -1735,8 +1754,8 @@ Result VKRenderer::createTextureResource(IResource::Usage initialUsage, const IT const auto& mipSize = mipSizes[j]; const ptrdiff_t srcRowStride = initData->mipRowStrides[j]; - const int dstRowSizeInBytes = Surface::calcRowSize(desc.format, mipSize.width); - const int numRows = Surface::calcNumRows(desc.format, mipSize.height); + const int dstRowSizeInBytes = calcRowSize(desc.format, mipSize.width); + const int numRows = calcNumRows(desc.format, mipSize.height); for (int k = 0; k < mipSize.depth; k++) { @@ -1768,8 +1787,8 @@ Result VKRenderer::createTextureResource(IResource::Usage initialUsage, const IT { const auto& mipSize = mipSizes[j]; - const int rowSizeInBytes = Surface::calcRowSize(desc.format, mipSize.width); - const int numRows = Surface::calcNumRows(desc.format, mipSize.height); + const int rowSizeInBytes = calcRowSize(desc.format, mipSize.width); + const int numRows = calcNumRows(desc.format, mipSize.height); // https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/VkBufferImageCopy.html // bufferRowLength and bufferImageHeight specify the data in buffer memory as a subregion of a larger two- or three-dimensional image, diff --git a/tools/render-test/render-test-main.cpp b/tools/render-test/render-test-main.cpp index 89bb25871..184373f0c 100644 --- a/tools/render-test/render-test-main.cpp +++ b/tools/render-test/render-test-main.cpp @@ -4,7 +4,7 @@ #include "options.h" #include "render.h" -#include "shader-cursor.h" +#include "tools/gfx-util/shader-cursor.h" #include "slang-support.h" #include "surface.h" #include "png-serialize-util.h" @@ -827,8 +827,23 @@ Result ShaderObjectRenderTestApp::writeBindingOutput(BindRoot* bindRoot, const c Result RenderTestApp::writeScreen(const char* filename) { + size_t rowPitch, bufferSize, pixelSize; + List<uint8_t> buffer; + + SLANG_RETURN_ON_FAIL(m_renderer->captureScreenSurface(nullptr, &bufferSize, &rowPitch, &pixelSize)); + buffer.setCount(bufferSize); + SLANG_RETURN_ON_FAIL( + m_renderer->captureScreenSurface(buffer.getBuffer(), &bufferSize, &rowPitch, &pixelSize)); + Surface surface; - SLANG_RETURN_ON_FAIL(m_renderer->captureScreenSurface(surface)); + size_t width = rowPitch / pixelSize; + size_t height = bufferSize / rowPitch; + surface.setUnowned( + width, + height, + gfx::Format::RGBA_Unorm_UInt8, + rowPitch, + buffer.getBuffer()); return PngSerializeUtil::write(filename, surface); } diff --git a/tools/gfx/surface.cpp b/tools/render-test/surface.cpp index 636881fca..636881fca 100644 --- a/tools/gfx/surface.cpp +++ b/tools/render-test/surface.cpp diff --git a/tools/gfx/surface.h b/tools/render-test/surface.h index 3e0f6f0aa..3e0f6f0aa 100644 --- a/tools/gfx/surface.h +++ b/tools/render-test/surface.h |
