diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2016-08-20 06:35:47 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2016-08-20 06:35:47 +0000 |
| commit | 2b64f003622ee7871fd7aec041622427dd2fc88f (patch) | |
| tree | 893dab48c6d0e7121e047d8d3bb6d5bf172ce2d5 /Graphics/GraphicsEngine | |
| parent | Release v1.0.0 (diff) | |
| download | DiligentCore-2b64f003622ee7871fd7aec041622427dd2fc88f.tar.gz DiligentCore-2b64f003622ee7871fd7aec041622427dd2fc88f.zip | |
Updated to Diligent Engine 2.0
Diffstat (limited to 'Graphics/GraphicsEngine')
68 files changed, 2734 insertions, 1785 deletions
diff --git a/Graphics/GraphicsEngine/build/WindowsStore/GraphicsEngine.Windows/GraphicsEngine.Windows.vcxproj b/Graphics/GraphicsEngine/build/UWP/GraphicsEngine.vcxproj index 7a0d8593..883c9e2f 100644 --- a/Graphics/GraphicsEngine/build/WindowsStore/GraphicsEngine.Windows/GraphicsEngine.Windows.vcxproj +++ b/Graphics/GraphicsEngine/build/UWP/GraphicsEngine.vcxproj @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> +<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ItemGroup Label="ProjectConfigurations"> <ProjectConfiguration Include="Debug|ARM"> <Configuration>Debug</Configuration> @@ -27,88 +27,89 @@ </ProjectConfiguration> </ItemGroup> <PropertyGroup Label="Globals"> - <ProjectGuid>{9df5553c-ca9d-4cb6-a06a-ca905119c00b}</ProjectGuid> + <ProjectGuid>{dfe6435d-cc9d-4ca1-bf4e-5640c522d815}</ProjectGuid> + <Keyword>StaticLibrary</Keyword> <RootNamespace>GraphicsEngine</RootNamespace> <DefaultLanguage>en-US</DefaultLanguage> - <MinimumVisualStudioVersion>12.0</MinimumVisualStudioVersion> + <MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion> <AppContainerApplication>true</AppContainerApplication> <ApplicationType>Windows Store</ApplicationType> - <ApplicationTypeRevision>8.1</ApplicationTypeRevision> - <ConvergedProjectType>CodeSharingStaticLibrary</ConvergedProjectType> + <WindowsTargetPlatformVersion>10.0.10586.0</WindowsTargetPlatformVersion> + <WindowsTargetPlatformMinVersion>10.0.10240.0</WindowsTargetPlatformMinVersion> + <ApplicationTypeRevision>10.0</ApplicationTypeRevision> </PropertyGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <ConfigurationType>StaticLibrary</ConfigurationType> <UseDebugLibraries>true</UseDebugLibraries> - <PlatformToolset>v120</PlatformToolset> + <PlatformToolset>v140</PlatformToolset> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'" Label="Configuration"> <ConfigurationType>StaticLibrary</ConfigurationType> <UseDebugLibraries>true</UseDebugLibraries> - <PlatformToolset>v120</PlatformToolset> + <PlatformToolset>v140</PlatformToolset> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> <ConfigurationType>StaticLibrary</ConfigurationType> <UseDebugLibraries>true</UseDebugLibraries> - <PlatformToolset>v120</PlatformToolset> + <PlatformToolset>v140</PlatformToolset> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <ConfigurationType>StaticLibrary</ConfigurationType> <UseDebugLibraries>false</UseDebugLibraries> <WholeProgramOptimization>true</WholeProgramOptimization> - <PlatformToolset>v120</PlatformToolset> + <PlatformToolset>v140</PlatformToolset> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'" Label="Configuration"> <ConfigurationType>StaticLibrary</ConfigurationType> <UseDebugLibraries>false</UseDebugLibraries> <WholeProgramOptimization>true</WholeProgramOptimization> - <PlatformToolset>v120</PlatformToolset> + <PlatformToolset>v140</PlatformToolset> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <ConfigurationType>StaticLibrary</ConfigurationType> <UseDebugLibraries>false</UseDebugLibraries> <WholeProgramOptimization>true</WholeProgramOptimization> - <PlatformToolset>v120</PlatformToolset> + <PlatformToolset>v140</PlatformToolset> </PropertyGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> - <Import Project="..\GraphicsEngine.Shared\GraphicsEngine.Shared.vcxitems" Label="Shared" /> + <ImportGroup Label="ExtensionSettings"> + </ImportGroup> + <ImportGroup Label="Shared"> + <Import Project="..\Windows.Shared\GraphicsEngine.Shared.vcxitems" Label="Shared" /> + </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" /> - <Import Project="..\..\..\..\..\Shared\build\WindowsStore\WinStore32Dbg.props" /> - <Import Project="..\EngineRoot.props" /> - <Import Project="..\..\Windows\GraphicsEngine.props" /> + <Import Project="..\..\..\..\Shared\build\UWP\UWP_Win32Dbg.props" /> + <Import Project="..\Windows.Shared\GraphicsEngine.props" /> </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" /> - <Import Project="..\..\..\..\..\Shared\build\WindowsStore\WinStore32Rel.props" /> - <Import Project="..\EngineRoot.props" /> - <Import Project="..\..\Windows\GraphicsEngine.props" /> + <Import Project="..\..\..\..\Shared\build\UWP\UWP_Win32Rel.props" /> + <Import Project="..\Windows.Shared\GraphicsEngine.props" /> </ImportGroup> <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'"> <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> - <Import Project="..\..\..\..\..\Shared\build\WindowsStore\WinStoreArmDbg.props" /> - <Import Project="..\EngineRoot.props" /> - <Import Project="..\..\Windows\GraphicsEngine.props" /> + <Import Project="..\..\..\..\Shared\build\UWP\UWP_ArmDbg.props" /> + <Import Project="..\Windows.Shared\GraphicsEngine.props" /> </ImportGroup> <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|ARM'"> <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> - <Import Project="..\..\..\..\..\Shared\build\WindowsStore\WinStoreArmRel.props" /> - <Import Project="..\EngineRoot.props" /> - <Import Project="..\..\Windows\GraphicsEngine.props" /> + <Import Project="..\..\..\..\Shared\build\UWP\UWP_ArmRel.props" /> + <Import Project="..\Windows.Shared\GraphicsEngine.props" /> </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" /> - <Import Project="..\..\..\..\..\Shared\build\WindowsStore\WinStore64Dbg.props" /> - <Import Project="..\EngineRoot.props" /> - <Import Project="..\..\Windows\GraphicsEngine.props" /> + <Import Project="..\..\..\..\Shared\build\UWP\UWP_X64Dbg.props" /> + <Import Project="..\Windows.Shared\GraphicsEngine.props" /> </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" /> - <Import Project="..\..\..\..\..\Shared\build\WindowsStore\WinStore64Rel.props" /> - <Import Project="..\EngineRoot.props" /> - <Import Project="..\..\Windows\GraphicsEngine.props" /> + <Import Project="..\..\..\..\Shared\build\UWP\UWP_X64Rel.props" /> + <Import Project="..\Windows.Shared\GraphicsEngine.props" /> </ImportGroup> <PropertyGroup Label="UserMacros" /> + <PropertyGroup /> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <GenerateManifest>false</GenerateManifest> </PropertyGroup> @@ -129,10 +130,8 @@ </PropertyGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ClCompile> - <PrecompiledHeader>Use</PrecompiledHeader> <CompileAsWinRT>false</CompileAsWinRT> <SDLCheck>true</SDLCheck> - <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> </ClCompile> <Link> <SubSystem>Console</SubSystem> @@ -142,10 +141,8 @@ </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ClCompile> - <PrecompiledHeader>Use</PrecompiledHeader> <CompileAsWinRT>false</CompileAsWinRT> <SDLCheck>true</SDLCheck> - <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> </ClCompile> <Link> <SubSystem>Console</SubSystem> @@ -155,10 +152,8 @@ </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|arm'"> <ClCompile> - <PrecompiledHeader>Use</PrecompiledHeader> <CompileAsWinRT>false</CompileAsWinRT> <SDLCheck>true</SDLCheck> - <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> </ClCompile> <Link> <SubSystem>Console</SubSystem> @@ -168,10 +163,8 @@ </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|arm'"> <ClCompile> - <PrecompiledHeader>Use</PrecompiledHeader> <CompileAsWinRT>false</CompileAsWinRT> <SDLCheck>true</SDLCheck> - <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> </ClCompile> <Link> <SubSystem>Console</SubSystem> @@ -181,7 +174,6 @@ </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <ClCompile> - <PrecompiledHeader>Use</PrecompiledHeader> <CompileAsWinRT>false</CompileAsWinRT> <SDLCheck>true</SDLCheck> </ClCompile> @@ -193,7 +185,6 @@ </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <ClCompile> - <PrecompiledHeader>Use</PrecompiledHeader> <CompileAsWinRT>false</CompileAsWinRT> <SDLCheck>true</SDLCheck> </ClCompile> diff --git a/Graphics/GraphicsEngine/build/UWP/GraphicsEngine.vcxproj.filters b/Graphics/GraphicsEngine/build/UWP/GraphicsEngine.vcxproj.filters new file mode 100644 index 00000000..c31757ec --- /dev/null +++ b/Graphics/GraphicsEngine/build/UWP/GraphicsEngine.vcxproj.filters @@ -0,0 +1,2 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />
\ No newline at end of file diff --git a/Graphics/GraphicsEngine/build/Windows/Android/gcc_Debug.h b/Graphics/GraphicsEngine/build/Win32/Android/gcc_Debug.h index da574716..da574716 100644 --- a/Graphics/GraphicsEngine/build/Windows/Android/gcc_Debug.h +++ b/Graphics/GraphicsEngine/build/Win32/Android/gcc_Debug.h diff --git a/Graphics/GraphicsEngine/build/Windows/Android/gcc_Release.h b/Graphics/GraphicsEngine/build/Win32/Android/gcc_Release.h index da574716..da574716 100644 --- a/Graphics/GraphicsEngine/build/Windows/Android/gcc_Release.h +++ b/Graphics/GraphicsEngine/build/Win32/Android/gcc_Release.h diff --git a/Graphics/GraphicsEngine/build/Windows/GraphicsEngine-Debug.vgdbsettings b/Graphics/GraphicsEngine/build/Win32/GraphicsEngine-Debug.vgdbsettings index 3f5b24b1..3f5b24b1 100644 --- a/Graphics/GraphicsEngine/build/Windows/GraphicsEngine-Debug.vgdbsettings +++ b/Graphics/GraphicsEngine/build/Win32/GraphicsEngine-Debug.vgdbsettings diff --git a/Graphics/GraphicsEngine/build/Windows/GraphicsEngine-Release.vgdbsettings b/Graphics/GraphicsEngine/build/Win32/GraphicsEngine-Release.vgdbsettings index 669691f2..669691f2 100644 --- a/Graphics/GraphicsEngine/build/Windows/GraphicsEngine-Release.vgdbsettings +++ b/Graphics/GraphicsEngine/build/Win32/GraphicsEngine-Release.vgdbsettings diff --git a/Graphics/GraphicsEngine/build/Windows/GraphicsEngine.vcxproj b/Graphics/GraphicsEngine/build/Win32/GraphicsEngine.vcxproj index 34dfc85e..f2e38dc4 100644 --- a/Graphics/GraphicsEngine/build/Windows/GraphicsEngine.vcxproj +++ b/Graphics/GraphicsEngine/build/Win32/GraphicsEngine.vcxproj @@ -69,31 +69,27 @@ </PropertyGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <ImportGroup Label="ExtensionSettings"> - <Import Project="..\WindowsStore\GraphicsEngine.Shared\GraphicsEngine.Shared.vcxitems" Label="Shared" Condition="Exists('..\WindowsStore\GraphicsEngine.Shared\GraphicsEngine.Shared.vcxitems')" /> + <Import Project="..\Windows.Shared\GraphicsEngine.Shared.vcxitems" Label="Shared" Condition="Exists('..\Windows.Shared\GraphicsEngine.Shared.vcxitems')" /> </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" /> <Import Project="..\..\..\..\Shared\build\Windows\Win32d.props" /> - <Import Project="EngineRoot.props" /> - <Import Project="GraphicsEngine.props" /> + <Import Project="..\Windows.Shared\GraphicsEngine.props" /> </ImportGroup> <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets"> <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> <Import Project="..\..\..\..\Shared\build\Windows\Win64d.props" /> - <Import Project="EngineRoot.props" /> - <Import Project="GraphicsEngine.props" /> + <Import Project="..\Windows.Shared\GraphicsEngine.props" /> </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" /> <Import Project="..\..\..\..\Shared\build\Windows\Win32r.props" /> - <Import Project="EngineRoot.props" /> - <Import Project="GraphicsEngine.props" /> + <Import Project="..\Windows.Shared\GraphicsEngine.props" /> </ImportGroup> <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets"> <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> <Import Project="..\..\..\..\Shared\build\Windows\Win64r.props" /> - <Import Project="EngineRoot.props" /> - <Import Project="GraphicsEngine.props" /> + <Import Project="..\Windows.Shared\GraphicsEngine.props" /> </ImportGroup> <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'"> <Import Project="..\..\..\..\Shared\build\Windows\Android32d.props" /> @@ -114,7 +110,6 @@ </PropertyGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ClCompile> - <WarningLevel>Level3</WarningLevel> <Optimization>Disabled</Optimization> <PreprocessorDefinitions>_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> </ClCompile> @@ -125,7 +120,6 @@ </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <ClCompile> - <WarningLevel>Level3</WarningLevel> <Optimization>Disabled</Optimization> <PreprocessorDefinitions>_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> </ClCompile> @@ -139,7 +133,6 @@ </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ClCompile> - <WarningLevel>Level3</WarningLevel> <Optimization>MaxSpeed</Optimization> <FunctionLevelLinking>true</FunctionLevelLinking> <IntrinsicFunctions>true</IntrinsicFunctions> @@ -154,7 +147,6 @@ </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <ClCompile> - <WarningLevel>Level3</WarningLevel> <Optimization>MaxSpeed</Optimization> <FunctionLevelLinking>true</FunctionLevelLinking> <IntrinsicFunctions>true</IntrinsicFunctions> @@ -175,6 +167,12 @@ <None Include="jni\Application.mk" /> </ItemGroup> <ItemGroup> + <ClCompile Include="..\..\src\EngineMemory.cpp"> + <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild> + <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild> + <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild> + <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild> + </ClCompile> <ClCompile Include="..\..\src\ResourceMapping.cpp"> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild> diff --git a/Graphics/GraphicsEngine/build/Windows/GraphicsEngine.vcxproj.filters b/Graphics/GraphicsEngine/build/Win32/GraphicsEngine.vcxproj.filters index f9817491..6bcb0a74 100644 --- a/Graphics/GraphicsEngine/build/Windows/GraphicsEngine.vcxproj.filters +++ b/Graphics/GraphicsEngine/build/Win32/GraphicsEngine.vcxproj.filters @@ -23,5 +23,8 @@ <ClCompile Include="..\..\src\Texture.cpp"> <Filter>android_src</Filter> </ClCompile> + <ClCompile Include="..\..\src\EngineMemory.cpp"> + <Filter>android_src</Filter> + </ClCompile> </ItemGroup> </Project>
\ No newline at end of file diff --git a/Graphics/GraphicsEngine/build/Windows/jni/Android.mk b/Graphics/GraphicsEngine/build/Win32/jni/Android.mk index 5d40b9a3..a2975140 100644 --- a/Graphics/GraphicsEngine/build/Windows/jni/Android.mk +++ b/Graphics/GraphicsEngine/build/Win32/jni/Android.mk @@ -19,6 +19,6 @@ LOCAL_C_INCLUDES := $(PROJECT_ROOT)/include $(PROJECT_ROOT)/interface $(SOLUTION # Source files #VisualGDBAndroid: AutoUpdateSourcesInNextLine -LOCAL_SRC_FILES := ../../../src/ResourceMapping.cpp ../../../src/Texture.cpp +LOCAL_SRC_FILES := ../../../src/EngineMemory.cpp ../../../src/ResourceMapping.cpp ../../../src/Texture.cpp include $(BUILD_STATIC_LIBRARY) diff --git a/Graphics/GraphicsEngine/build/Windows/jni/Application.mk b/Graphics/GraphicsEngine/build/Win32/jni/Application.mk index 45f02b20..45f02b20 100644 --- a/Graphics/GraphicsEngine/build/Windows/jni/Application.mk +++ b/Graphics/GraphicsEngine/build/Win32/jni/Application.mk diff --git a/Graphics/GraphicsEngine/build/Windows.Shared/GraphicsEngine.Shared.vcxitems b/Graphics/GraphicsEngine/build/Windows.Shared/GraphicsEngine.Shared.vcxitems new file mode 100644 index 00000000..b388caf2 --- /dev/null +++ b/Graphics/GraphicsEngine/build/Windows.Shared/GraphicsEngine.Shared.vcxitems @@ -0,0 +1,74 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup Label="Globals"> + <MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects> + <HasSharedItems>true</HasSharedItems> + <ItemsProjectGuid>{0cdd843c-089d-4fee-be9f-c08fa2b51acb}</ItemsProjectGuid> + <ItemsRootNamespace>GraphicsEngine</ItemsRootNamespace> + <ItemsProjectName>GraphicsEngine.Shared</ItemsProjectName> + <CodeSharingProject>248F659F-DAC5-46E8-AC09-60EC9FC95053</CodeSharingProject> + </PropertyGroup> + <ItemDefinitionGroup> + <ClCompile> + <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory)</AdditionalIncludeDirectories> + </ClCompile> + </ItemDefinitionGroup> + <ItemGroup> + <ProjectCapability Include="SourceItemsFromImports" /> + </ItemGroup> + <ItemGroup> + <ClCompile Include="$(MSBuildThisFileDirectory)..\..\src\EngineMemory.cpp" /> + <ClCompile Include="$(MSBuildThisFileDirectory)..\..\src\ResourceMapping.cpp" /> + <ClCompile Include="$(MSBuildThisFileDirectory)..\..\src\pch.cpp"> + <PrecompiledHeader>Create</PrecompiledHeader> + </ClCompile> + <ClCompile Include="$(MSBuildThisFileDirectory)..\..\src\Texture.cpp" /> + </ItemGroup> + <ItemGroup> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\BufferBase.h" /> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\BufferViewBase.h" /> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\CommandListBase.h" /> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\Defines.h" /> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\DeviceContextBase.h" /> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\DeviceObjectBase.h" /> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\EngineMemory.h" /> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\PipelineStateBase.h" /> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\RenderDeviceBase.h" /> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\ResourceMappingImpl.h" /> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\SamplerBase.h" /> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\ShaderBase.h" /> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\ShaderResourceBindingBase.h" /> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\StateObjectsRegistry.h" /> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\pch.h" /> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\SwapChainBase.h" /> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\TextureBase.h" /> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\TextureViewBase.h" /> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\BlendState.h" /> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\Buffer.h" /> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\BufferView.h" /> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\CommandList.h" /> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\Constants.h" /> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\DepthStencilState.h" /> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\DeviceCaps.h" /> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\DeviceContext.h" /> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\DeviceObject.h" /> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\MapHelper.h" /> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\PipelineState.h" /> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\RasterizerState.h" /> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\RenderDevice.h" /> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\ResourceMapping.h" /> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\Sampler.h" /> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\Shader.h" /> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\ShaderResourceBinding.h" /> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\SwapChain.h" /> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\Texture.h" /> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\TextureView.h" /> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\GraphicsTypes.h" /> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\InputLayout.h" /> + </ItemGroup> + <ItemGroup> + <Text Include="$(MSBuildThisFileDirectory)..\..\CMakeLists.txt"> + <DeploymentContent>false</DeploymentContent> + </Text> + </ItemGroup> +</Project>
\ No newline at end of file diff --git a/Graphics/GraphicsEngine/build/Windows.Shared/GraphicsEngine.Shared.vcxitems.filters b/Graphics/GraphicsEngine/build/Windows.Shared/GraphicsEngine.Shared.vcxitems.filters new file mode 100644 index 00000000..4a458938 --- /dev/null +++ b/Graphics/GraphicsEngine/build/Windows.Shared/GraphicsEngine.Shared.vcxitems.filters @@ -0,0 +1,153 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup> + <Filter Include="include"> + <UniqueIdentifier>{32eded03-121f-406a-8a23-6721ca9116ee}</UniqueIdentifier> + </Filter> + <Filter Include="src"> + <UniqueIdentifier>{d881c412-cc78-41fb-997c-0d6543c1e477}</UniqueIdentifier> + </Filter> + <Filter Include="interface"> + <UniqueIdentifier>{c38a8d65-5100-44be-b1a5-453d901c892f}</UniqueIdentifier> + </Filter> + </ItemGroup> + <ItemGroup> + <ClCompile Include="$(MSBuildThisFileDirectory)..\..\src\pch.cpp"> + <Filter>src</Filter> + </ClCompile> + <ClCompile Include="$(MSBuildThisFileDirectory)..\..\src\Texture.cpp"> + <Filter>src</Filter> + </ClCompile> + <ClCompile Include="$(MSBuildThisFileDirectory)..\..\src\ResourceMapping.cpp"> + <Filter>src</Filter> + </ClCompile> + <ClCompile Include="$(MSBuildThisFileDirectory)..\..\src\EngineMemory.cpp"> + <Filter>src</Filter> + </ClCompile> + </ItemGroup> + <ItemGroup> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\DeviceObjectBase.h"> + <Filter>include</Filter> + </ClInclude> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\RenderDeviceBase.h"> + <Filter>include</Filter> + </ClInclude> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\ResourceMappingImpl.h"> + <Filter>include</Filter> + </ClInclude> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\SamplerBase.h"> + <Filter>include</Filter> + </ClInclude> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\ShaderBase.h"> + <Filter>include</Filter> + </ClInclude> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\StateObjectsRegistry.h"> + <Filter>include</Filter> + </ClInclude> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\pch.h"> + <Filter>include</Filter> + </ClInclude> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\TextureBase.h"> + <Filter>include</Filter> + </ClInclude> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\TextureViewBase.h"> + <Filter>include</Filter> + </ClInclude> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\BufferBase.h"> + <Filter>include</Filter> + </ClInclude> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\BufferViewBase.h"> + <Filter>include</Filter> + </ClInclude> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\Defines.h"> + <Filter>include</Filter> + </ClInclude> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\DeviceContextBase.h"> + <Filter>include</Filter> + </ClInclude> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\DepthStencilState.h"> + <Filter>interface</Filter> + </ClInclude> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\DeviceCaps.h"> + <Filter>interface</Filter> + </ClInclude> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\DeviceContext.h"> + <Filter>interface</Filter> + </ClInclude> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\DeviceObject.h"> + <Filter>interface</Filter> + </ClInclude> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\MapHelper.h"> + <Filter>interface</Filter> + </ClInclude> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\RasterizerState.h"> + <Filter>interface</Filter> + </ClInclude> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\RenderDevice.h"> + <Filter>interface</Filter> + </ClInclude> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\ResourceMapping.h"> + <Filter>interface</Filter> + </ClInclude> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\Sampler.h"> + <Filter>interface</Filter> + </ClInclude> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\Shader.h"> + <Filter>interface</Filter> + </ClInclude> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\Texture.h"> + <Filter>interface</Filter> + </ClInclude> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\TextureView.h"> + <Filter>interface</Filter> + </ClInclude> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\BlendState.h"> + <Filter>interface</Filter> + </ClInclude> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\Buffer.h"> + <Filter>interface</Filter> + </ClInclude> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\BufferView.h"> + <Filter>interface</Filter> + </ClInclude> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\Constants.h"> + <Filter>interface</Filter> + </ClInclude> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\SwapChain.h"> + <Filter>interface</Filter> + </ClInclude> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\SwapChainBase.h"> + <Filter>include</Filter> + </ClInclude> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\GraphicsTypes.h"> + <Filter>interface</Filter> + </ClInclude> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\PipelineState.h"> + <Filter>interface</Filter> + </ClInclude> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\PipelineStateBase.h"> + <Filter>include</Filter> + </ClInclude> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\InputLayout.h"> + <Filter>interface</Filter> + </ClInclude> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\ShaderResourceBinding.h"> + <Filter>interface</Filter> + </ClInclude> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\ShaderResourceBindingBase.h"> + <Filter>include</Filter> + </ClInclude> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\EngineMemory.h"> + <Filter>include</Filter> + </ClInclude> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\interface\CommandList.h"> + <Filter>interface</Filter> + </ClInclude> + <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\CommandListBase.h"> + <Filter>include</Filter> + </ClInclude> + </ItemGroup> + <ItemGroup> + <Text Include="$(MSBuildThisFileDirectory)..\..\CMakeLists.txt" /> + </ItemGroup> +</Project>
\ No newline at end of file diff --git a/Graphics/GraphicsEngine/build/Windows/EngineRoot.props b/Graphics/GraphicsEngine/build/Windows.Shared/GraphicsEngine.props index 6e4b958b..53a6cd34 100644 --- a/Graphics/GraphicsEngine/build/Windows/EngineRoot.props +++ b/Graphics/GraphicsEngine/build/Windows.Shared/GraphicsEngine.props @@ -5,7 +5,9 @@ <EngineRoot>..\..\..\..</EngineRoot> <GraphicsRoot>..\..\..</GraphicsRoot> </PropertyGroup> - <PropertyGroup /> + <PropertyGroup> + <IncludePath>$(GraphicsRoot)\GraphicsEngine\include;$(GraphicsRoot)\GraphicsEngine\interface;$(GraphicsRoot)\GraphicsTools\include;$(EngineRoot)\Common\include;$(EngineRoot)\Common\interface;$(EngineRoot)\Platforms\interface;$(VC_IncludePath);$(WindowsSDK_IncludePath);$(IncludePath)</IncludePath> + </PropertyGroup> <ItemDefinitionGroup /> <ItemGroup> <BuildMacro Include="EngineRoot"> diff --git a/Graphics/GraphicsEngine/build/Windows/GraphicsEngine.props b/Graphics/GraphicsEngine/build/Windows/GraphicsEngine.props deleted file mode 100644 index f5ff61e5..00000000 --- a/Graphics/GraphicsEngine/build/Windows/GraphicsEngine.props +++ /dev/null @@ -1,10 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <ImportGroup Label="PropertySheets" /> - <PropertyGroup Label="UserMacros" /> - <PropertyGroup> - <IncludePath>$(GraphicsRoot)\GraphicsEngine\include;$(GraphicsRoot)\GraphicsEngine\interface;$(GraphicsRoot)\GraphicsTools\include;$(EngineRoot)\Common\include;$(EngineRoot)\Common\interface;$(EngineRoot)\Platforms\interface;$(VC_IncludePath);$(WindowsSDK_IncludePath);$(IncludePath)</IncludePath> - </PropertyGroup> - <ItemDefinitionGroup /> - <ItemGroup /> -</Project>
\ No newline at end of file diff --git a/Graphics/GraphicsEngine/build/WindowsStore/EngineRoot.props b/Graphics/GraphicsEngine/build/WindowsStore/EngineRoot.props deleted file mode 100644 index fcb891c0..00000000 --- a/Graphics/GraphicsEngine/build/WindowsStore/EngineRoot.props +++ /dev/null @@ -1,18 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <ImportGroup Label="PropertySheets" /> - <PropertyGroup Label="UserMacros"> - <EngineRoot>..\..\..\..\..</EngineRoot> - <GraphicsRoot>..\..\..\..</GraphicsRoot> - </PropertyGroup> - <PropertyGroup /> - <ItemDefinitionGroup /> - <ItemGroup> - <BuildMacro Include="EngineRoot"> - <Value>$(EngineRoot)</Value> - </BuildMacro> - <BuildMacro Include="GraphicsRoot"> - <Value>$(GraphicsRoot)</Value> - </BuildMacro> - </ItemGroup> -</Project>
\ No newline at end of file diff --git a/Graphics/GraphicsEngine/build/WindowsStore/GraphicsEngine.Shared/GraphicsEngine.Shared.vcxitems b/Graphics/GraphicsEngine/build/WindowsStore/GraphicsEngine.Shared/GraphicsEngine.Shared.vcxitems deleted file mode 100644 index e8d4f5a7..00000000 --- a/Graphics/GraphicsEngine/build/WindowsStore/GraphicsEngine.Shared/GraphicsEngine.Shared.vcxitems +++ /dev/null @@ -1,65 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <PropertyGroup Label="Globals"> - <MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects> - <HasSharedItems>true</HasSharedItems> - <ItemsProjectGuid>{0cdd843c-089d-4fee-be9f-c08fa2b51acb}</ItemsProjectGuid> - <ItemsRootNamespace>GraphicsEngine</ItemsRootNamespace> - <ItemsProjectName>GraphicsEngine.Shared</ItemsProjectName> - <CodeSharingProject>248F659F-DAC5-46E8-AC09-60EC9FC95053</CodeSharingProject> - </PropertyGroup> - <ItemDefinitionGroup> - <ClCompile> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory)</AdditionalIncludeDirectories> - </ClCompile> - </ItemDefinitionGroup> - <ItemGroup> - <ProjectCapability Include="SourceItemsFromImports" /> - </ItemGroup> - <ItemGroup> - <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\ResourceMapping.cpp" /> - <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\pch.cpp"> - <PrecompiledHeader>Create</PrecompiledHeader> - </ClCompile> - <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\Texture.cpp" /> - </ItemGroup> - <ItemGroup> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\BlendStateBase.h" /> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\BufferBase.h" /> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\BufferViewBase.h" /> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\Defines.h" /> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\DepthStencilStateBase.h" /> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\DeviceContextBase.h" /> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\DeviceObjectBase.h" /> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\RasterizerStateBase.h" /> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\RenderDeviceBase.h" /> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\ResourceMappingImpl.h" /> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\SamplerBase.h" /> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\ShaderBase.h" /> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\StateObjectsRegistry.h" /> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\pch.h" /> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\SwapChainBase.h" /> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\TextureBase.h" /> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\TextureViewBase.h" /> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\VertexDescriptionBase.h" /> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\BlendState.h" /> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\Buffer.h" /> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\BufferView.h" /> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\Constants.h" /> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\DepthStencilState.h" /> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\DeviceCaps.h" /> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\DeviceContext.h" /> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\DeviceObject.h" /> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\MapHelper.h" /> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\RasterizerState.h" /> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\RenderDevice.h" /> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\ResourceMapping.h" /> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\Sampler.h" /> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\Shader.h" /> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\SwapChain.h" /> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\Texture.h" /> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\TextureView.h" /> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\GraphicsTypes.h" /> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\VertexDescription.h" /> - </ItemGroup> -</Project>
\ No newline at end of file diff --git a/Graphics/GraphicsEngine/build/WindowsStore/GraphicsEngine.Shared/GraphicsEngine.Shared.vcxitems.filters b/Graphics/GraphicsEngine/build/WindowsStore/GraphicsEngine.Shared/GraphicsEngine.Shared.vcxitems.filters deleted file mode 100644 index 8014c299..00000000 --- a/Graphics/GraphicsEngine/build/WindowsStore/GraphicsEngine.Shared/GraphicsEngine.Shared.vcxitems.filters +++ /dev/null @@ -1,138 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <ItemGroup> - <Filter Include="include"> - <UniqueIdentifier>{32eded03-121f-406a-8a23-6721ca9116ee}</UniqueIdentifier> - </Filter> - <Filter Include="src"> - <UniqueIdentifier>{d881c412-cc78-41fb-997c-0d6543c1e477}</UniqueIdentifier> - </Filter> - <Filter Include="interface"> - <UniqueIdentifier>{c38a8d65-5100-44be-b1a5-453d901c892f}</UniqueIdentifier> - </Filter> - </ItemGroup> - <ItemGroup> - <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\pch.cpp"> - <Filter>src</Filter> - </ClCompile> - <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\Texture.cpp"> - <Filter>src</Filter> - </ClCompile> - <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\ResourceMapping.cpp"> - <Filter>src</Filter> - </ClCompile> - </ItemGroup> - <ItemGroup> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\DeviceObjectBase.h"> - <Filter>include</Filter> - </ClInclude> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\RasterizerStateBase.h"> - <Filter>include</Filter> - </ClInclude> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\RenderDeviceBase.h"> - <Filter>include</Filter> - </ClInclude> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\ResourceMappingImpl.h"> - <Filter>include</Filter> - </ClInclude> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\SamplerBase.h"> - <Filter>include</Filter> - </ClInclude> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\ShaderBase.h"> - <Filter>include</Filter> - </ClInclude> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\StateObjectsRegistry.h"> - <Filter>include</Filter> - </ClInclude> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\pch.h"> - <Filter>include</Filter> - </ClInclude> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\TextureBase.h"> - <Filter>include</Filter> - </ClInclude> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\TextureViewBase.h"> - <Filter>include</Filter> - </ClInclude> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\VertexDescriptionBase.h"> - <Filter>include</Filter> - </ClInclude> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\BlendStateBase.h"> - <Filter>include</Filter> - </ClInclude> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\BufferBase.h"> - <Filter>include</Filter> - </ClInclude> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\BufferViewBase.h"> - <Filter>include</Filter> - </ClInclude> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\Defines.h"> - <Filter>include</Filter> - </ClInclude> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\DepthStencilStateBase.h"> - <Filter>include</Filter> - </ClInclude> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\DeviceContextBase.h"> - <Filter>include</Filter> - </ClInclude> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\DepthStencilState.h"> - <Filter>interface</Filter> - </ClInclude> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\DeviceCaps.h"> - <Filter>interface</Filter> - </ClInclude> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\DeviceContext.h"> - <Filter>interface</Filter> - </ClInclude> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\DeviceObject.h"> - <Filter>interface</Filter> - </ClInclude> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\MapHelper.h"> - <Filter>interface</Filter> - </ClInclude> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\RasterizerState.h"> - <Filter>interface</Filter> - </ClInclude> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\RenderDevice.h"> - <Filter>interface</Filter> - </ClInclude> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\ResourceMapping.h"> - <Filter>interface</Filter> - </ClInclude> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\Sampler.h"> - <Filter>interface</Filter> - </ClInclude> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\Shader.h"> - <Filter>interface</Filter> - </ClInclude> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\Texture.h"> - <Filter>interface</Filter> - </ClInclude> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\TextureView.h"> - <Filter>interface</Filter> - </ClInclude> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\VertexDescription.h"> - <Filter>interface</Filter> - </ClInclude> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\BlendState.h"> - <Filter>interface</Filter> - </ClInclude> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\Buffer.h"> - <Filter>interface</Filter> - </ClInclude> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\BufferView.h"> - <Filter>interface</Filter> - </ClInclude> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\Constants.h"> - <Filter>interface</Filter> - </ClInclude> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\SwapChain.h"> - <Filter>interface</Filter> - </ClInclude> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\SwapChainBase.h"> - <Filter>include</Filter> - </ClInclude> - <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\GraphicsTypes.h"> - <Filter>interface</Filter> - </ClInclude> - </ItemGroup> -</Project>
\ No newline at end of file diff --git a/Graphics/GraphicsEngine/build/WindowsStore/GraphicsEngine.Windows/GraphicsEngine.Windows.vcxproj.filters b/Graphics/GraphicsEngine/build/WindowsStore/GraphicsEngine.Windows/GraphicsEngine.Windows.vcxproj.filters deleted file mode 100644 index a7761ab0..00000000 --- a/Graphics/GraphicsEngine/build/WindowsStore/GraphicsEngine.Windows/GraphicsEngine.Windows.vcxproj.filters +++ /dev/null @@ -1,5 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <ItemGroup> - </ItemGroup> -</Project> diff --git a/Graphics/GraphicsEngine/build/WindowsStore/GraphicsEngine.WindowsPhone/GraphicsEngine.WindowsPhone.vcxproj b/Graphics/GraphicsEngine/build/WindowsStore/GraphicsEngine.WindowsPhone/GraphicsEngine.WindowsPhone.vcxproj deleted file mode 100644 index b3f74084..00000000 --- a/Graphics/GraphicsEngine/build/WindowsStore/GraphicsEngine.WindowsPhone/GraphicsEngine.WindowsPhone.vcxproj +++ /dev/null @@ -1,144 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <ItemGroup Label="ProjectConfigurations"> - <ProjectConfiguration Include="Debug|ARM"> - <Configuration>Debug</Configuration> - <Platform>ARM</Platform> - </ProjectConfiguration> - <ProjectConfiguration Include="Debug|Win32"> - <Configuration>Debug</Configuration> - <Platform>Win32</Platform> - </ProjectConfiguration> - <ProjectConfiguration Include="Release|ARM"> - <Configuration>Release</Configuration> - <Platform>ARM</Platform> - </ProjectConfiguration> - <ProjectConfiguration Include="Release|Win32"> - <Configuration>Release</Configuration> - <Platform>Win32</Platform> - </ProjectConfiguration> - </ItemGroup> - <PropertyGroup Label="Globals"> - <ProjectGuid>{aefba9a8-e16d-4b06-b16d-bc74ac799b4f}</ProjectGuid> - <RootNamespace>GraphicsEngine</RootNamespace> - <DefaultLanguage>en-US</DefaultLanguage> - <MinimumVisualStudioVersion>12.0</MinimumVisualStudioVersion> - <AppContainerApplication>true</AppContainerApplication> - <ApplicationType>Windows Phone</ApplicationType> - <ApplicationTypeRevision>8.1</ApplicationTypeRevision> - <ConvergedProjectType>CodeSharingStaticLibrary</ConvergedProjectType> - </PropertyGroup> - <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> - <ConfigurationType>StaticLibrary</ConfigurationType> - <UseDebugLibraries>true</UseDebugLibraries> - <PlatformToolset>v120_wp81</PlatformToolset> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'" Label="Configuration"> - <ConfigurationType>StaticLibrary</ConfigurationType> - <UseDebugLibraries>true</UseDebugLibraries> - <PlatformToolset>v120_wp81</PlatformToolset> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> - <ConfigurationType>StaticLibrary</ConfigurationType> - <UseDebugLibraries>false</UseDebugLibraries> - <WholeProgramOptimization>true</WholeProgramOptimization> - <PlatformToolset>v120_wp81</PlatformToolset> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'" Label="Configuration"> - <ConfigurationType>StaticLibrary</ConfigurationType> - <UseDebugLibraries>false</UseDebugLibraries> - <WholeProgramOptimization>true</WholeProgramOptimization> - <PlatformToolset>v120_wp81</PlatformToolset> - </PropertyGroup> - <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> - <Import Project="..\GraphicsEngine.Shared\GraphicsEngine.Shared.vcxitems" Label="Shared" /> - <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" /> - <Import Project="..\..\..\..\..\Shared\build\WindowsStore\WinStore32Dbg.props" /> - <Import Project="..\EngineRoot.props" /> - <Import Project="..\..\Windows\GraphicsEngine.props" /> - </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" /> - <Import Project="..\..\..\..\..\Shared\build\WindowsStore\WinStore32Rel.props" /> - <Import Project="..\EngineRoot.props" /> - <Import Project="..\..\Windows\GraphicsEngine.props" /> - </ImportGroup> - <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> - <Import Project="..\..\..\..\..\Shared\build\WindowsStore\WinStoreArmDbg.props" /> - <Import Project="..\EngineRoot.props" /> - <Import Project="..\..\Windows\GraphicsEngine.props" /> - </ImportGroup> - <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|ARM'"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> - <Import Project="..\..\..\..\..\Shared\build\WindowsStore\WinStoreArmRel.props" /> - <Import Project="..\EngineRoot.props" /> - <Import Project="..\..\Windows\GraphicsEngine.props" /> - </ImportGroup> - <PropertyGroup Label="UserMacros" /> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> - <GenerateManifest>false</GenerateManifest> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <GenerateManifest>false</GenerateManifest> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'"> - <GenerateManifest>false</GenerateManifest> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'"> - <GenerateManifest>false</GenerateManifest> - </PropertyGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> - <ClCompile> - <PrecompiledHeader>Use</PrecompiledHeader> - <CompileAsWinRT>false</CompileAsWinRT> - <SDLCheck>true</SDLCheck> - </ClCompile> - <Link> - <SubSystem>Console</SubSystem> - <IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries> - <GenerateWindowsMetadata>false</GenerateWindowsMetadata> - </Link> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <ClCompile> - <PrecompiledHeader>Use</PrecompiledHeader> - <CompileAsWinRT>false</CompileAsWinRT> - <SDLCheck>true</SDLCheck> - </ClCompile> - <Link> - <SubSystem>Console</SubSystem> - <IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries> - <GenerateWindowsMetadata>false</GenerateWindowsMetadata> - </Link> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|arm'"> - <ClCompile> - <PrecompiledHeader>Use</PrecompiledHeader> - <CompileAsWinRT>false</CompileAsWinRT> - <SDLCheck>true</SDLCheck> - </ClCompile> - <Link> - <SubSystem>Console</SubSystem> - <IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries> - <GenerateWindowsMetadata>false</GenerateWindowsMetadata> - </Link> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|arm'"> - <ClCompile> - <PrecompiledHeader>Use</PrecompiledHeader> - <CompileAsWinRT>false</CompileAsWinRT> - <SDLCheck>true</SDLCheck> - </ClCompile> - <Link> - <SubSystem>Console</SubSystem> - <IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries> - <GenerateWindowsMetadata>false</GenerateWindowsMetadata> - </Link> - </ItemDefinitionGroup> - <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> - <ImportGroup Label="ExtensionTargets"> - </ImportGroup> -</Project>
\ No newline at end of file diff --git a/Graphics/GraphicsEngine/build/WindowsStore/GraphicsEngine.WindowsPhone/GraphicsEngine.WindowsPhone.vcxproj.filters b/Graphics/GraphicsEngine/build/WindowsStore/GraphicsEngine.WindowsPhone/GraphicsEngine.WindowsPhone.vcxproj.filters deleted file mode 100644 index a7761ab0..00000000 --- a/Graphics/GraphicsEngine/build/WindowsStore/GraphicsEngine.WindowsPhone/GraphicsEngine.WindowsPhone.vcxproj.filters +++ /dev/null @@ -1,5 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <ItemGroup> - </ItemGroup> -</Project> diff --git a/Graphics/GraphicsEngine/include/BlendStateBase.h b/Graphics/GraphicsEngine/include/BlendStateBase.h deleted file mode 100644 index 78494b46..00000000 --- a/Graphics/GraphicsEngine/include/BlendStateBase.h +++ /dev/null @@ -1,76 +0,0 @@ -/* Copyright 2015 Egor Yusov - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. - * - * In no event and under no legal theory, whether in tort (including negligence), - * contract, or otherwise, unless required by applicable law (such as deliberate - * and grossly negligent acts) or agreed to in writing, shall any Contributor be - * liable for any damages, including any direct, indirect, special, incidental, - * or consequential damages of any character arising as a result of this License or - * out of the use or inability to use the software (including but not limited to damages - * for loss of goodwill, work stoppage, computer failure or malfunction, or any and - * all other commercial damages or losses), even if such Contributor has been advised - * of the possibility of such damages. - */ - -#pragma once - -/// \file -/// Implementation of the Diligent::BlendStateBase template class - -#include "BlendState.h" -#include "DeviceObjectBase.h" - -namespace Diligent -{ - -/// Template class implementing base functionality for a blend state object. - -/// \tparam BaseInterface - base interface that this class will inheret -/// (Diligent::IBlendStateD3D11 or Diligent::IBlendStateGL). -/// \tparam RenderDeviceBaseInterface - base interface for the render device -/// (Diligent::IRenderDeviceD3D11, Diligent::IRenderDeviceGL, -/// or Diligent::IRenderDeviceGLES). -template<class BaseInterface = IBlendState, class RenderDeviceBaseInterface = IRenderDevice> -class BlendStateBase : public DeviceObjectBase<BaseInterface, BlendStateDesc> -{ -public: - typedef DeviceObjectBase<BaseInterface, BlendStateDesc> TDeviceObjectBase; - typedef RenderDeviceBase < RenderDeviceBaseInterface > TRenderDeviceBase; - - /// \param pDevice - pointer to the device. - /// \param BSDesc - blend state description. - /// \param bIsDeviceInternal - flag indicating if the blend state is an internal device object and - /// must not keep a strong reference to the device. - BlendStateBase( IRenderDevice *pDevice, const BlendStateDesc& BSDesc, bool bIsDeviceInternal = false ) : - TDeviceObjectBase( pDevice, BSDesc, nullptr, bIsDeviceInternal ) - { - } - - ~BlendStateBase() - { - /// \note Destructor cannot directly remove the object from the registry as this may cause a - /// deadlock at the point where StateObjectsRegistry::Find() locks the weak pointer: if we - /// are in dtor, the object is locked by Diligent::RefCountedObject::Release() and - /// StateObjectsRegistry::Find() will wait for that lock to be released. - /// A the same time this thread will be waiting for the other thread to unlock the registry.\n - /// Thus destructor only notifies the registry that there is a deleted object. - /// The reference to the object will be removed later. - auto &BlendStateRegistry = static_cast<TRenderDeviceBase*>(this->GetDevice())->GetBSRegistry(); - // StateObjectsRegistry::ReportDeletedObject() does not lock the registry, but only - // atomically increments the outstanding deleted objects counter. - BlendStateRegistry.ReportDeletedObject(); - } - - IMPLEMENT_QUERY_INTERFACE_IN_PLACE( IID_BlendState, TDeviceObjectBase ) -}; - -} diff --git a/Graphics/GraphicsEngine/include/BufferBase.h b/Graphics/GraphicsEngine/include/BufferBase.h index 43b07662..ded3bbc3 100644 --- a/Graphics/GraphicsEngine/include/BufferBase.h +++ b/Graphics/GraphicsEngine/include/BufferBase.h @@ -1,4 +1,4 @@ -/* Copyright 2015 Egor Yusov +/* Copyright 2015-2016 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ #include "Buffer.h" #include "DeviceObjectBase.h" #include "GraphicsUtilities.h" +#include "STDAllocator.h" #include <memory> namespace Diligent @@ -37,22 +38,39 @@ namespace Diligent /// Template class implementing base functionality for a buffer object /// \tparam BaseInterface - base interface that this class will inheret -/// (Diligent::IBufferD3D11 or Diligent::IBufferGL). +/// (Diligent::IBufferD3D11, Diligent::IBufferD3D12 or Diligent::IBufferGL). /// \tparam BufferViewImplType - type of the buffer view implementation -/// (Diligent::BufferViewD3D11Impl or Diligent::BufferVeiwGLImpl) -template<class BaseInterface, class BufferViewImplType> -class BufferBase : public DeviceObjectBase < BaseInterface, BufferDesc > +/// (Diligent::BufferViewD3D11Impl, Diligent::BufferViewD3D12Impl or Diligent::BufferViewGLImpl) +/// \tparam TBuffObjAllocator - type of the allocator that is used to allocate memory for the buffer object instances +/// \tparam TBuffViewObjAllocator - type of the allocator that is used to allocate memory for the buffer view object instances +template<class BaseInterface, class BufferViewImplType, class TBuffObjAllocator, class TBuffViewObjAllocator> +class BufferBase : public DeviceObjectBase < BaseInterface, BufferDesc, TBuffObjAllocator > { public: - typedef DeviceObjectBase<BaseInterface, BufferDesc> TDeviceObjectBase; + typedef DeviceObjectBase<BaseInterface, BufferDesc, TBuffObjAllocator> TDeviceObjectBase; + /// \param BuffObjAllocator - allocator that was used to allocate memory for this instance of the buffer object. + /// \param BuffViewObjAllocator - allocator that is used to allocate memory for the buffer view instances. + /// This parameter is only used for debug purposes. /// \param pDevice - pointer to the device. /// \param BuffDesc - buffer description. /// \param bIsDeviceInternal - flag indicating if the buffer is an internal device object and /// must not keep a strong reference to the device. - BufferBase( IRenderDevice *pDevice, const BufferDesc& BuffDesc, bool bIsDeviceInternal = false ) : - TDeviceObjectBase( pDevice, BuffDesc, nullptr, bIsDeviceInternal ) + BufferBase( TBuffObjAllocator &BuffObjAllocator, + TBuffViewObjAllocator &BuffViewObjAllocator, + IRenderDevice *pDevice, + const BufferDesc& BuffDesc, + bool bIsDeviceInternal = false ) : + TDeviceObjectBase( BuffObjAllocator, pDevice, BuffDesc, nullptr, bIsDeviceInternal ), +#ifdef _DEBUG + m_dbgBuffViewAllocator(BuffViewObjAllocator), +#endif + m_pDefaultUAV(nullptr, STDDeleter<BufferViewImplType, TBuffViewObjAllocator>(BuffViewObjAllocator) ), + m_pDefaultSRV(nullptr, STDDeleter<BufferViewImplType, TBuffViewObjAllocator>(BuffViewObjAllocator) ) { +#define VERIFY_BUFFER(Expr, ...) VERIFY(Expr, "Buffer \"", this->m_Desc.Name ? this->m_Desc.Name : "", "\": ", ##__VA_ARGS__) + +#ifdef _DEBUG Uint32 AllowedBindFlags = BIND_VERTEX_BUFFER | BIND_INDEX_BUFFER | BIND_UNIFORM_BUFFER | BIND_SHADER_RESOURCE | BIND_STREAM_OUTPUT | BIND_UNORDERED_ACCESS | @@ -62,142 +80,162 @@ public: "BIND_SHADER_RESOURCE (8), BIND_STREAM_OUTPUT (16), BIND_UNORDERED_ACCESS (128), " "BIND_INDIRECT_DRAW_ARGS (256)"; -#define VERIFY_BUFFER(Expr, ...) VERIFY(Expr, "Buffer \"", m_Desc.Name ? m_Desc.Name : "", "\": ", ##__VA_ARGS__) - VERIFY_BUFFER( (BuffDesc.BindFlags & ~AllowedBindFlags) == 0, "Incorrect bind flags specified (", BuffDesc.BindFlags & ~AllowedBindFlags, "). Only the following flags are allowed:\n", strAllowedBindFlags ); - - m_Desc = BuffDesc; - if( (m_Desc.BindFlags & BIND_UNORDERED_ACCESS) || - (m_Desc.BindFlags & BIND_SHADER_RESOURCE) ) +#endif + + if( (this->m_Desc.BindFlags & BIND_UNORDERED_ACCESS) || + (this->m_Desc.BindFlags & BIND_SHADER_RESOURCE) ) { - VERIFY_BUFFER( m_Desc.Mode > BUFFER_MODE_UNDEFINED && m_Desc.Mode < BUFFER_MODE_NUM_MODES, "Buffer mode (", m_Desc.Mode, ") is not correct" ); - if( m_Desc.Mode == BUFFER_MODE_STRUCTURED ) + VERIFY_BUFFER( this->m_Desc.Mode > BUFFER_MODE_UNDEFINED && this->m_Desc.Mode < BUFFER_MODE_NUM_MODES, "Buffer mode (", this->m_Desc.Mode, ") is not correct" ); + if( this->m_Desc.Mode == BUFFER_MODE_STRUCTURED ) { - VERIFY_BUFFER( m_Desc.ElementByteStride != 0, "Element stride cannot be zero for structured buffer" ); + VERIFY_BUFFER( this->m_Desc.ElementByteStride != 0, "Element stride cannot be zero for structured buffer" ); } - if( m_Desc.Mode == BUFFER_MODE_FORMATED ) + if( this->m_Desc.Mode == BUFFER_MODE_FORMATED ) { - VERIFY_BUFFER( m_Desc.Format.ValueType != VT_UNDEFINED, "Value type is not specified for a formated buffer" ); - VERIFY_BUFFER( m_Desc.Format.NumComponents != 0, "Num components cannot be zero in a formated buffer" ); - if( m_Desc.ElementByteStride == 0 ) - m_Desc.ElementByteStride = static_cast<Uint32>(GetValueSize( m_Desc.Format.ValueType )) * m_Desc.Format.NumComponents; + VERIFY_BUFFER( this->m_Desc.Format.ValueType != VT_UNDEFINED, "Value type is not specified for a formated buffer" ); + VERIFY_BUFFER( this->m_Desc.Format.NumComponents != 0, "Num components cannot be zero in a formated buffer" ); + if( this->m_Desc.ElementByteStride == 0 ) + this->m_Desc.ElementByteStride = static_cast<Uint32>(GetValueSize( this->m_Desc.Format.ValueType )) * this->m_Desc.Format.NumComponents; } } } IMPLEMENT_QUERY_INTERFACE_IN_PLACE( IID_Buffer, TDeviceObjectBase ) + /// Base implementation of IBuffer::UpdateData(); validates input parameters. virtual void UpdateData( IDeviceContext *pContext, Uint32 Offset, Uint32 Size, const PVoid pData )override = 0; + /// Base implementation of IBuffer::CopyData(); validates input parameters. virtual void CopyData( IDeviceContext *pContext, IBuffer *pSrcBuffer, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size )override = 0; + /// Base implementation of IBuffer::Map(); validates input parameters. virtual void Map( IDeviceContext *pContext, MAP_TYPE MapType, Uint32 MapFlags, PVoid &pMappedData )override; - virtual void Unmap( IDeviceContext *pContext )override = 0; + /// Base implementation of IBuffer::Unmap() + virtual void Unmap( IDeviceContext *pContext, MAP_TYPE MapType )override = 0; + /// Implementation of IBuffer::CreateView(); calls CreateViewInternal() virtual function + /// that creates buffer view for the specific engine implementation. virtual void CreateView( const struct BufferViewDesc &ViewDesc, IBufferView **ppView )override; + /// Implementation of IBuffer::GetDefaultView(). virtual IBufferView* GetDefaultView( BUFFER_VIEW_TYPE ViewType )override; + /// Creates default buffer views. + + /// + /// - Creates default shader resource view addressing the entire buffer if Diligent::BIND_SHADER_RESOURCE flag is set + /// - Creates default unordered access view addressing the entire buffer if Diligent::BIND_UNORDERED_ACCESS flag is set + /// + /// The function calls CreateViewInternal(). void CreateDefaultViews(); protected: + + /// Pure virtual function that creates buffer view for the specific engine implementation. virtual void CreateViewInternal( const struct BufferViewDesc &ViewDesc, IBufferView **ppView, bool bIsDefaultView ) = 0; + /// Corrects buffer view description and validates view parameters. void CorrectBufferViewDesc( struct BufferViewDesc &ViewDesc ); - BufferDesc m_Desc; +#ifdef _DEBUG + TBuffViewObjAllocator &m_dbgBuffViewAllocator; +#endif + + /// Default UAV addressing the entire buffer + std::unique_ptr<BufferViewImplType, STDDeleter<BufferViewImplType, TBuffViewObjAllocator> > m_pDefaultUAV; - std::unique_ptr<BufferViewImplType> m_pDefaultUAV; - std::unique_ptr<BufferViewImplType> m_pDefaultSRV; + /// Default SRV addressing the entire buffer + std::unique_ptr<BufferViewImplType, STDDeleter<BufferViewImplType, TBuffViewObjAllocator> > m_pDefaultSRV; }; -template<class BaseInterface, class BufferViewImplType> -void BufferBase<BaseInterface, BufferViewImplType> :: UpdateData( IDeviceContext *pContext, Uint32 Offset, Uint32 Size, const PVoid pData ) +template<class BaseInterface, class BufferViewImplType, class TBuffObjAllocator, class TBuffViewObjAllocator> +void BufferBase<BaseInterface, BufferViewImplType, TBuffObjAllocator, TBuffViewObjAllocator> :: UpdateData( IDeviceContext *pContext, Uint32 Offset, Uint32 Size, const PVoid pData ) { - VERIFY_BUFFER( m_Desc.Usage == USAGE_DEFAULT, "Only default usage buffers can be updated with UpdateData()" ); - VERIFY_BUFFER( Offset < m_Desc.uiSizeInBytes, "Offset (", Offset, ") exceeds the buffer size (", m_Desc.uiSizeInBytes, ")" ); - VERIFY_BUFFER( Size + Offset <= m_Desc.uiSizeInBytes, "Update region [", Offset, ",", Size + Offset, ") is out of buffer bounds [0,",m_Desc.uiSizeInBytes,")" ); + VERIFY_BUFFER( this->m_Desc.Usage == USAGE_DEFAULT, "Only default usage buffers can be updated with UpdateData()" ); + VERIFY_BUFFER( Offset < this->m_Desc.uiSizeInBytes, "Offset (", Offset, ") exceeds the buffer size (", this->m_Desc.uiSizeInBytes, ")" ); + VERIFY_BUFFER( Size + Offset <= this->m_Desc.uiSizeInBytes, "Update region [", Offset, ",", Size + Offset, ") is out of buffer bounds [0,",this->m_Desc.uiSizeInBytes,")" ); } -template<class BaseInterface, class BufferViewImplType> -void BufferBase<BaseInterface, BufferViewImplType> :: CopyData( IDeviceContext *pContext, IBuffer *pSrcBuffer, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size ) +template<class BaseInterface, class BufferViewImplType, class TBuffObjAllocator, class TBuffViewObjAllocator> +void BufferBase<BaseInterface, BufferViewImplType, TBuffObjAllocator, TBuffViewObjAllocator> :: CopyData( IDeviceContext *pContext, IBuffer *pSrcBuffer, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size ) { - VERIFY_BUFFER( DstOffset + Size <= m_Desc.uiSizeInBytes, "Destination range [", DstOffset, ",", DstOffset + Size, ") is out of buffer bounds [0,",m_Desc.uiSizeInBytes,")" ); - VERIFY_BUFFER( SrcOffset + Size <= pSrcBuffer->GetDesc().uiSizeInBytes, "Source range [", SrcOffset, ",", SrcOffset + Size, ") is out of buffer bounds [0,",m_Desc.uiSizeInBytes,")" ); + VERIFY_BUFFER( DstOffset + Size <= this->m_Desc.uiSizeInBytes, "Destination range [", DstOffset, ",", DstOffset + Size, ") is out of buffer bounds [0,",this->m_Desc.uiSizeInBytes,")" ); + VERIFY_BUFFER( SrcOffset + Size <= pSrcBuffer->GetDesc().uiSizeInBytes, "Source range [", SrcOffset, ",", SrcOffset + Size, ") is out of buffer bounds [0,",this->m_Desc.uiSizeInBytes,")" ); } -template<class BaseInterface, class BufferViewImplType> -void BufferBase<BaseInterface, BufferViewImplType> :: Map( IDeviceContext *pContext, MAP_TYPE MapType, Uint32 MapFlags, PVoid &pMappedData ) +template<class BaseInterface, class BufferViewImplType, class TBuffObjAllocator, class TBuffViewObjAllocator> +void BufferBase<BaseInterface, BufferViewImplType, TBuffObjAllocator, TBuffViewObjAllocator> :: Map( IDeviceContext *pContext, MAP_TYPE MapType, Uint32 MapFlags, PVoid &pMappedData ) { switch( MapType ) { case MAP_READ: - VERIFY_BUFFER( m_Desc.Usage == USAGE_CPU_ACCESSIBLE, "Only buffers with usage USAGE_CPU_ACCESSIBLE can be read from" ); - VERIFY_BUFFER( (m_Desc.CPUAccessFlags & CPU_ACCESS_READ), "Buffer being mapped for reading was not created with CPU_ACCESS_READ flag" ); + VERIFY_BUFFER( this->m_Desc.Usage == USAGE_CPU_ACCESSIBLE, "Only buffers with usage USAGE_CPU_ACCESSIBLE can be read from" ); + VERIFY_BUFFER( (this->m_Desc.CPUAccessFlags & CPU_ACCESS_READ), "Buffer being mapped for reading was not created with CPU_ACCESS_READ flag" ); break; case MAP_WRITE: - VERIFY_BUFFER( m_Desc.Usage == USAGE_CPU_ACCESSIBLE, "Only buffers with usage USAGE_CPU_ACCESSIBLE can be written to" ); - VERIFY_BUFFER( (m_Desc.CPUAccessFlags & CPU_ACCESS_WRITE), "Buffer being mapped for writing was not created with CPU_ACCESS_WRITE flag" ); + VERIFY_BUFFER( this->m_Desc.Usage == USAGE_CPU_ACCESSIBLE, "Only buffers with usage USAGE_CPU_ACCESSIBLE can be written to" ); + VERIFY_BUFFER( (this->m_Desc.CPUAccessFlags & CPU_ACCESS_WRITE), "Buffer being mapped for writing was not created with CPU_ACCESS_WRITE flag" ); break; case MAP_READ_WRITE: - VERIFY_BUFFER( m_Desc.Usage == USAGE_CPU_ACCESSIBLE, "Only buffers with usage USAGE_CPU_ACCESSIBLE can be read and written" ); - VERIFY_BUFFER( (m_Desc.CPUAccessFlags & CPU_ACCESS_WRITE), "Buffer being mapped for reading & writing was not created with CPU_ACCESS_WRITE flag" ); - VERIFY_BUFFER( (m_Desc.CPUAccessFlags & CPU_ACCESS_READ), "Buffer being mapped for reading & writing was not created with CPU_ACCESS_READ flag" ); + VERIFY_BUFFER( this->m_Desc.Usage == USAGE_CPU_ACCESSIBLE, "Only buffers with usage USAGE_CPU_ACCESSIBLE can be read and written" ); + VERIFY_BUFFER( (this->m_Desc.CPUAccessFlags & CPU_ACCESS_WRITE), "Buffer being mapped for reading & writing was not created with CPU_ACCESS_WRITE flag" ); + VERIFY_BUFFER( (this->m_Desc.CPUAccessFlags & CPU_ACCESS_READ), "Buffer being mapped for reading & writing was not created with CPU_ACCESS_READ flag" ); break; case MAP_WRITE_DISCARD: - VERIFY_BUFFER( m_Desc.Usage == USAGE_DYNAMIC, "Only dynamic buffers can be mapped with write discard flag" ); - VERIFY_BUFFER( (m_Desc.CPUAccessFlags & CPU_ACCESS_WRITE), "Dynamic buffer must be created with CPU_ACCESS_WRITE flag" ); + VERIFY_BUFFER( this->m_Desc.Usage == USAGE_DYNAMIC, "Only dynamic buffers can be mapped with write discard flag" ); + VERIFY_BUFFER( (this->m_Desc.CPUAccessFlags & CPU_ACCESS_WRITE), "Dynamic buffer must be created with CPU_ACCESS_WRITE flag" ); break; case MAP_WRITE_NO_OVERWRITE: - VERIFY_BUFFER( m_Desc.Usage == USAGE_DYNAMIC, "Only dynamic buffers can be mapped with write no overwrite flag" ); - VERIFY_BUFFER( (m_Desc.CPUAccessFlags & CPU_ACCESS_WRITE), "Dynamic buffer must be created with CPU_ACCESS_WRITE flag" ); + VERIFY_BUFFER( this->m_Desc.Usage == USAGE_DYNAMIC, "Only dynamic buffers can be mapped with write no overwrite flag" ); + VERIFY_BUFFER( (this->m_Desc.CPUAccessFlags & CPU_ACCESS_WRITE), "Dynamic buffer must be created with CPU_ACCESS_WRITE flag" ); break; default: UNEXPECTED( "Unknown map type" ); } } -template<class BaseInterface, class BufferViewImplType> -void BufferBase<BaseInterface, BufferViewImplType> :: Unmap( IDeviceContext *pContext ) +template<class BaseInterface, class BufferViewImplType, class TBuffObjAllocator, class TBuffViewObjAllocator> +void BufferBase<BaseInterface, BufferViewImplType, TBuffObjAllocator, TBuffViewObjAllocator> :: Unmap( IDeviceContext *pContext, MAP_TYPE MapType ) { } -template<class BaseInterface, class BufferViewImplType> -void BufferBase<BaseInterface, BufferViewImplType> :: CreateView( const struct BufferViewDesc &ViewDesc, IBufferView **ppView ) +template<class BaseInterface, class BufferViewImplType, class TBuffObjAllocator, class TBuffViewObjAllocator> +void BufferBase<BaseInterface, BufferViewImplType, TBuffObjAllocator, TBuffViewObjAllocator> :: CreateView( const struct BufferViewDesc &ViewDesc, IBufferView **ppView ) { CreateViewInternal( ViewDesc, ppView, false ); } -template<class BaseInterface, class BufferViewImplType> -void BufferBase<BaseInterface, BufferViewImplType> :: CorrectBufferViewDesc( struct BufferViewDesc &ViewDesc ) +template<class BaseInterface, class BufferViewImplType, class TBuffObjAllocator, class TBuffViewObjAllocator> +void BufferBase<BaseInterface, BufferViewImplType, TBuffObjAllocator, TBuffViewObjAllocator> :: CorrectBufferViewDesc( struct BufferViewDesc &ViewDesc ) { if( ViewDesc.ByteWidth == 0 ) - ViewDesc.ByteWidth = m_Desc.uiSizeInBytes; - if( ViewDesc.ByteOffset + ViewDesc.ByteWidth > m_Desc.uiSizeInBytes ) - LOG_ERROR_AND_THROW( "Buffer view range [", ViewDesc.ByteOffset, ", ", ViewDesc.ByteOffset + ViewDesc.ByteWidth, ") is out of the buffer boundaries [0, ", m_Desc.uiSizeInBytes, ")." ); - if( (m_Desc.BindFlags & BIND_UNORDERED_ACCESS) || - (m_Desc.BindFlags & BIND_SHADER_RESOURCE) ) + ViewDesc.ByteWidth = this->m_Desc.uiSizeInBytes; + if( ViewDesc.ByteOffset + ViewDesc.ByteWidth > this->m_Desc.uiSizeInBytes ) + LOG_ERROR_AND_THROW( "Buffer view range [", ViewDesc.ByteOffset, ", ", ViewDesc.ByteOffset + ViewDesc.ByteWidth, ") is out of the buffer boundaries [0, ", this->m_Desc.uiSizeInBytes, ")." ); + if( (this->m_Desc.BindFlags & BIND_UNORDERED_ACCESS) || + (this->m_Desc.BindFlags & BIND_SHADER_RESOURCE) ) { - VERIFY( m_Desc.ElementByteStride != 0, "Element byte stride is zero" ); - if( (ViewDesc.ByteOffset % m_Desc.ElementByteStride) != 0 ) - LOG_ERROR_AND_THROW( "Buffer view byte offset (", ViewDesc.ByteOffset, ") is not multiple of element byte stride (", m_Desc.ElementByteStride, ")." ); - if( (ViewDesc.ByteWidth % m_Desc.ElementByteStride) != 0 ) - LOG_ERROR_AND_THROW( "Buffer view byte width (", ViewDesc.ByteWidth, ") is not multiple of element byte stride (", m_Desc.ElementByteStride, ")." ); + VERIFY( this->m_Desc.ElementByteStride != 0, "Element byte stride is zero" ); + if( (ViewDesc.ByteOffset % this->m_Desc.ElementByteStride) != 0 ) + LOG_ERROR_AND_THROW( "Buffer view byte offset (", ViewDesc.ByteOffset, ") is not multiple of element byte stride (", this->m_Desc.ElementByteStride, ")." ); + if( (ViewDesc.ByteWidth % this->m_Desc.ElementByteStride) != 0 ) + LOG_ERROR_AND_THROW( "Buffer view byte width (", ViewDesc.ByteWidth, ") is not multiple of element byte stride (", this->m_Desc.ElementByteStride, ")." ); } } -template<class BaseInterface, class BufferViewImplType> -IBufferView* BufferBase<BaseInterface, BufferViewImplType> ::GetDefaultView( BUFFER_VIEW_TYPE ViewType ) +template<class BaseInterface, class BufferViewImplType, class TBuffObjAllocator, class TBuffViewObjAllocator> +IBufferView* BufferBase<BaseInterface, BufferViewImplType, TBuffObjAllocator, TBuffViewObjAllocator> ::GetDefaultView( BUFFER_VIEW_TYPE ViewType ) { switch( ViewType ) { @@ -207,10 +245,10 @@ IBufferView* BufferBase<BaseInterface, BufferViewImplType> ::GetDefaultView( BUF } } -template<class BaseInterface, class BufferViewImplType> -void BufferBase<BaseInterface, BufferViewImplType> :: CreateDefaultViews() +template<class BaseInterface, class BufferViewImplType, class TBuffObjAllocator, class TBuffViewObjAllocator> +void BufferBase<BaseInterface, BufferViewImplType, TBuffObjAllocator, TBuffViewObjAllocator> :: CreateDefaultViews() { - if( m_Desc.BindFlags & BIND_UNORDERED_ACCESS ) + if( this->m_Desc.BindFlags & BIND_UNORDERED_ACCESS ) { BufferViewDesc ViewDesc; ViewDesc.ViewType = BUFFER_VIEW_UNORDERED_ACCESS; @@ -220,7 +258,7 @@ void BufferBase<BaseInterface, BufferViewImplType> :: CreateDefaultViews() VERIFY( m_pDefaultUAV->GetDesc().ViewType == BUFFER_VIEW_UNORDERED_ACCESS, "Unexpected view type" ); } - if( m_Desc.BindFlags & BIND_SHADER_RESOURCE ) + if( this->m_Desc.BindFlags & BIND_SHADER_RESOURCE ) { BufferViewDesc ViewDesc; ViewDesc.ViewType = BUFFER_VIEW_SHADER_RESOURCE; diff --git a/Graphics/GraphicsEngine/include/BufferViewBase.h b/Graphics/GraphicsEngine/include/BufferViewBase.h index 59ce395a..00eb5008 100644 --- a/Graphics/GraphicsEngine/include/BufferViewBase.h +++ b/Graphics/GraphicsEngine/include/BufferViewBase.h @@ -1,4 +1,4 @@ -/* Copyright 2015 Egor Yusov +/* Copyright 2015-2016 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,27 +37,30 @@ namespace Diligent /// Template class implementing base functionality for a buffer view object /// \tparam BaseInterface - base interface that this class will inheret -/// (Diligent::IBufferViewD3D11 or Diligent::IBufferViewGL). -template<class BaseInterface = IBufferView> -class BufferViewBase : public DeviceObjectBase<BaseInterface, BufferViewDesc> +/// (Diligent::IBufferViewD3D11, Diligent::IBufferViewD3D12 or Diligent::IBufferViewGL). +/// \tparam BuffViewObjAllocator - type of the allocator that is used to allocate memory for the buffer view object instances +template<class BaseInterface, class BuffViewObjAllocator> +class BufferViewBase : public DeviceObjectBase<BaseInterface, BufferViewDesc, BuffViewObjAllocator> { public: - typedef DeviceObjectBase<BaseInterface, BufferViewDesc> TDeviceObjectBase; + typedef DeviceObjectBase<BaseInterface, BufferViewDesc, BuffViewObjAllocator> TDeviceObjectBase; + /// \param ObjAllocator - allocator that was used to allocate memory for this instance of the buffer view object /// \param pDevice - pointer to the render device. /// \param ViewDesc - buffer view description. /// \param pBuffer - pointer to the buffer that the view is to be created for. /// \param bIsDefaultView - flag indicating if the view is default view, and is thus /// part of the buffer object. In this case the view will attach /// to the buffer's reference counters. - BufferViewBase( class IRenderDevice *pDevice, + BufferViewBase( BuffViewObjAllocator &ObjAllocator, + class IRenderDevice *pDevice, const BufferViewDesc& ViewDesc, class IBuffer *pBuffer, bool bIsDefaultView ) : // Default views are created as part of the buffer, so we cannot not keep strong // reference to the buffer to avoid cyclic links. Instead, we will attach to the // reference counters of the buffer. - TDeviceObjectBase( pDevice, ViewDesc, bIsDefaultView ? pBuffer : nullptr ), + TDeviceObjectBase( ObjAllocator, pDevice, ViewDesc, bIsDefaultView ? pBuffer : nullptr ), m_pBuffer( pBuffer ), // For non-default view, we will keep strong reference to buffer m_spBuffer(bIsDefaultView ? nullptr : pBuffer) @@ -65,15 +68,16 @@ public: IMPLEMENT_QUERY_INTERFACE_IN_PLACE( IID_BufferView, TDeviceObjectBase ) - virtual IBuffer* GetBuffer() + /// Implementation of IBufferView::GetBuffer() + virtual IBuffer* GetBuffer()override final { return m_pBuffer; } protected: - /// Reference to the buffer - IBuffer* m_pBuffer; + /// Pointer to the buffer + IBuffer* const m_pBuffer; /// Strong reference to the buffer. Used for non-default views /// to keep the buffer alive diff --git a/Graphics/GraphicsEngine/include/CommandListBase.h b/Graphics/GraphicsEngine/include/CommandListBase.h new file mode 100644 index 00000000..fd917490 --- /dev/null +++ b/Graphics/GraphicsEngine/include/CommandListBase.h @@ -0,0 +1,66 @@ +/* Copyright 2015-2016 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +/// \file +/// Implementation of the Diligent::CommandListBase template class + +#include "CommandList.h" +#include "DeviceObjectBase.h" +#include "RenderDeviceBase.h" + +namespace Diligent +{ + +struct CommandListDesc : public DeviceObjectAttribs +{ +}; + +/// Template class implementing base functionality for a command list object. + +/// \tparam BaseInterface - base interface that this class will inheret +/// (Diligent::ICommandListD3D11 or Diligent::ICommandListD3D12). +/// \tparam CommandListObjAllocator - allocator that is used to allocate memory for command list object instances +template<class BaseInterface, class CommandListObjAllocator> +class CommandListBase : public DeviceObjectBase<BaseInterface, CommandListDesc, CommandListObjAllocator> +{ +public: + typedef DeviceObjectBase<BaseInterface, CommandListDesc, CommandListObjAllocator> TDeviceObjectBase; + + /// \param ObjAllocator - Allocator that was used to allocate memory for this instance of the command list object + /// \param pDevice - pointer to the device. + /// \param bIsDeviceInternal - flag indicating if the CommandList is an internal device object and + /// must not keep a strong reference to the device. + CommandListBase( CommandListObjAllocator &ObjAllocator, IRenderDevice *pDevice, bool bIsDeviceInternal = false ) : + TDeviceObjectBase( ObjAllocator, pDevice, CommandListDesc(), nullptr, bIsDeviceInternal ) + {} + + ~CommandListBase() + { + } + + IMPLEMENT_QUERY_INTERFACE_IN_PLACE( IID_CommandList, TDeviceObjectBase ) +}; + +} diff --git a/Graphics/GraphicsEngine/include/Defines.h b/Graphics/GraphicsEngine/include/Defines.h index 7f6a56e3..23585de3 100644 --- a/Graphics/GraphicsEngine/include/Defines.h +++ b/Graphics/GraphicsEngine/include/Defines.h @@ -1,4 +1,4 @@ -/* Copyright 2015 Egor Yusov +/* Copyright 2015-2016 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngine/include/DepthStencilStateBase.h b/Graphics/GraphicsEngine/include/DepthStencilStateBase.h deleted file mode 100644 index dbfe43d3..00000000 --- a/Graphics/GraphicsEngine/include/DepthStencilStateBase.h +++ /dev/null @@ -1,69 +0,0 @@ -/* Copyright 2015 Egor Yusov - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. - * - * In no event and under no legal theory, whether in tort (including negligence), - * contract, or otherwise, unless required by applicable law (such as deliberate - * and grossly negligent acts) or agreed to in writing, shall any Contributor be - * liable for any damages, including any direct, indirect, special, incidental, - * or consequential damages of any character arising as a result of this License or - * out of the use or inability to use the software (including but not limited to damages - * for loss of goodwill, work stoppage, computer failure or malfunction, or any and - * all other commercial damages or losses), even if such Contributor has been advised - * of the possibility of such damages. - */ - -#pragma once - -/// \file -/// Implementation of the Diligent::DepthStencilStateBase template class - -#include "DepthStencilState.h" -#include "DeviceObjectBase.h" - -namespace Diligent -{ - -/// Template class implementing base functionality for a depth stencil state object. - -/// \tparam BaseInterface - base interface that this class will inheret -/// (Diligent::IDepthStencilStateD3D11 or Diligent::IDepthStencilStateGL). -/// \tparam RenderDeviceBaseInterface - base interface for the render device -/// (Diligent::IRenderDeviceD3D11, Diligent::IRenderDeviceGL, -/// or Diligent::IRenderDeviceGLES). -template<class BaseInterface = IDepthStencilState, class RenderDeviceBaseInterface = IRenderDevice> -class DepthStencilStateBase : public DeviceObjectBase<BaseInterface, DepthStencilStateDesc> -{ -public: - typedef DeviceObjectBase<BaseInterface, DepthStencilStateDesc> TDeviceObjectBase; - typedef RenderDeviceBase<RenderDeviceBaseInterface> TRenderDeviceBase; - - /// \param pDevice - pointer to the device. - /// \param DSSDesc - depth-stencil state description. - /// \param bIsDeviceInternal - flag indicating if the state is an internal device object and - /// must not keep a strong reference to the device. - DepthStencilStateBase( IRenderDevice *pDevice, const DepthStencilStateDesc& DSSDesc, bool bIsDeviceInternal = false ) : - TDeviceObjectBase( pDevice, DSSDesc, nullptr, bIsDeviceInternal ) - { - } - - ~DepthStencilStateBase() - { - /// \note Destructor cannot directly remove the object from the registry as this may cause a - /// deadlock. See BlendStateBase::~BlendStateBase() for details. - auto &DSStateRegistry = static_cast<TRenderDeviceBase*>(this->GetDevice())->GetDSStateRegistry(); - DSStateRegistry.ReportDeletedObject(); - } - - IMPLEMENT_QUERY_INTERFACE_IN_PLACE( IID_DepthStencilState, TDeviceObjectBase ) -}; - -} diff --git a/Graphics/GraphicsEngine/include/DeviceContextBase.h b/Graphics/GraphicsEngine/include/DeviceContextBase.h index 26885aa4..f18a8f85 100644 --- a/Graphics/GraphicsEngine/include/DeviceContextBase.h +++ b/Graphics/GraphicsEngine/include/DeviceContextBase.h @@ -1,4 +1,4 @@ -/* Copyright 2015 Egor Yusov +/* Copyright 2015-2016 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,8 +49,8 @@ struct VertexStreamInfo { /// Strong reference to the buffer object RefCntAutoPtr<IBuffer> pBuffer; - Uint32 Stride; ///< Stride - Uint32 Offset; ///< Offset + Uint32 Stride; ///< Stride in bytes + Uint32 Offset; ///< Offset in bytes VertexStreamInfo() : Stride( 0 ), Offset( 0 ) @@ -64,25 +64,30 @@ struct VertexStreamInfo /// the pipeline: buffers, states, samplers, shaders, etc. /// The context also keeps strong references to the device and /// the swap chain. -template<typename BaseInterface = IDeviceContext> -class DeviceContextBase : public ObjectBase<BaseInterface> +template<typename BaseInterface> +class DeviceContextBase : public ObjectBase<BaseInterface, IMemoryAllocator> { public: - DeviceContextBase(IRenderDevice *pRenderDevice) : + + typedef ObjectBase<BaseInterface, IMemoryAllocator> TObjectBase; + + /// \param RawMemAllocator - allocator that was used to allocate memory for this instance of the device context object. + /// \param pRenderDevice - render device. + /// \param bIsDeferred - flag indicating if this instance is a deferred context + DeviceContextBase(IMemoryAllocator& RawMemAllocator, IRenderDevice *pRenderDevice, bool bIsDeferred) : + TObjectBase(nullptr, &RawMemAllocator), m_pDevice(pRenderDevice), m_IndexDataStartOffset( 0 ), m_StencilRef( 0 ), - m_SamplesBlendMask( 0 ) + m_NumVertexStreams(0), + m_bIsDeferred(bIsDeferred) { for( int i = 0; i < 4; ++i ) m_BlendFactors[i] = -1; - m_VertexStreams.reserve( MaxBufferSlots ); - m_Viewports.reserve( 16 ); - m_ScissorRects.reserve( 16 ); // Set dummy render target array size to make sure that // render targets are actually bound the first time // SetRenderTargets() is called - m_pBoundRenderTargets.resize( 8 ); + m_NumBoundRenderTargets = _countof(m_pBoundRenderTargets); } ~DeviceContextBase() @@ -91,89 +96,62 @@ public: IMPLEMENT_QUERY_INTERFACE_IN_PLACE( IID_DeviceContext, ObjectBase<BaseInterface> ) - virtual void SetVertexBuffers( Uint32 StartSlot, Uint32 NumBuffersSet, IBuffer **ppBuffers, Uint32 *pStrides, Uint32 *pOffsets, Uint32 Flags ) = 0; - - virtual void ClearState() = 0; - - virtual void SetShaders( IShader **ppShaders, Uint32 NumShadersToSet ) - { - m_pBoundShaders.resize( NumShadersToSet ); - for( Uint32 i = 0; i < NumShadersToSet; ++i ) - m_pBoundShaders[i] = ppShaders[i]; -#ifdef DEBUG_CHECKS - { - Uint32 BoundShaders = 0; - for( auto sh = m_pBoundShaders.begin(); sh != m_pBoundShaders.end(); ++sh ) - { - auto ShaderType = (*sh)->GetDesc().ShaderType; - if( BoundShaders & ShaderType ) - { - LOG_ERROR_MESSAGE( "More than one shader of type ", GetShaderTypeLiteralName( ShaderType ), " is being set to the pipeline" ); - BoundShaders |= ShaderType; - } - } - } -#endif - } - - virtual void BindShaderResources( IResourceMapping *pResourceMapping, Uint32 Flags ) - { - } - - // Body of the pure virtual function cannot be inlined - /// Caches the strong reference to the vertex description - virtual void SetVertexDescription( IVertexDescription *pVertexDesc ) = 0; - - /// Caches the strong reference to the index buffer - virtual void SetIndexBuffer( IBuffer *pIndexBuffer, Uint32 ByteOffset ) = 0; + /// Base implementation of IDeviceContext::SetVertexBuffers(); validates parameters and + /// caches references to the buffers. + inline virtual void SetVertexBuffers( Uint32 StartSlot, Uint32 NumBuffersSet, IBuffer **ppBuffers, Uint32 *pStrides, Uint32 *pOffsets, Uint32 Flags ) = 0; - /// If the new depth stencil parameters differ from the cached values, - /// updates the values and returns true. Otherwise returns false. - bool SetDepthStencilState( IDepthStencilState *pDSState, Uint32 StencilRef, Uint32 Dummy = 0); + inline virtual void ClearState() = 0; + /// Base implementation of IDeviceContext::SetPipelineState(); caches references to the pipeline state object. + inline virtual void SetPipelineState(IPipelineState *pPipelineState) = 0; - /// If the new rasterizer state differs from the cached state, - /// updates the cached state and returns true. Otherwise returns false. - bool SetRasterizerState( IRasterizerState *pRS, Uint32 Dummy = 0 ); + /// Base implementation of IDeviceContext::CommitShaderResources(); validates parameters. + inline bool CommitShaderResources(IShaderResourceBinding *pShaderResourceBinding, Uint32 Flags, int); + /// Base implementation of IDeviceContext::SetIndexBuffer(); caches the strong reference to the index buffer + inline virtual void SetIndexBuffer( IBuffer *pIndexBuffer, Uint32 ByteOffset ) = 0; - /// If the new blend parameters differ from the cached values, - /// updates the cached values and returns true. Otherwise returns false. - bool SetBlendState( IBlendState *pBS, const float* pBlendFactors, Uint32 SampleMask, Uint32 Dummy = 0 ); - /// Caches the viewports - void SetViewports( Uint32 NumViewports, const Viewport *pViewports, Uint32 &RTWidth, Uint32 &RTHeight ); + inline void SetViewports( Uint32 NumViewports, const Viewport *pViewports, Uint32 &RTWidth, Uint32 &RTHeight ); /// Caches the scissor rects - void SetScissorRects( Uint32 NumRects, const Rect *pRects, Uint32 &RTWidth, Uint32 &RTHeight ); + inline void SetScissorRects( Uint32 NumRects, const Rect *pRects, Uint32 &RTWidth, Uint32 &RTHeight ); /// Caches the render target and depth stencil views. Returns true if any view is different /// from the cached value and false otherwise. - bool SetRenderTargets( Uint32 NumRenderTargets, ITextureView *ppRenderTargets[], ITextureView *pDepthStencil, Uint32 Dummy = 0 ); + inline bool SetRenderTargets( Uint32 NumRenderTargets, ITextureView *ppRenderTargets[], ITextureView *pDepthStencil, Uint32 Dummy = 0 ); /// Sets the strong pointer to the swap chain - void SetSwapChain( ISwapChain *pSwapChain ) { m_pSwapChain = pSwapChain; } + inline void SetSwapChain( ISwapChain *pSwapChain ) { m_pSwapChain = pSwapChain; } - bool IsDefaultFBBound(){ return m_pBoundRenderTargets.size() == 0 && m_pBoundDepthStencil == nullptr; } + /// Returns the swap chain + ISwapChain *GetSwapChain() { return m_pSwapChain; } - void GetDepthStencilState(IDepthStencilState **ppDSS, Uint32 &StencilRef); + /// Returns true if currently bound frame buffer is the default frame buffer + inline bool IsDefaultFBBound(){ return m_NumBoundRenderTargets == 0 && m_pBoundDepthStencil == nullptr; } - void GetRasterizerState( IRasterizerState **ppRS ); + /// Returns currently bound pipeline state and blend factors + inline void GetPipelineState(IPipelineState **ppPSO, float* BlendFactors, Uint32 &StencilRef); - void GetBlendState( IBlendState **ppBS, float* BlendFactors, Uint32& SamplesBlendMask ); + /// Returns currently bound render targets + inline void GetRenderTargets(Uint32 &NumRenderTargets, ITextureView **ppRTVs, ITextureView **ppDSV); - void GetRenderTargets(Uint32 &NumRenderTargets, ITextureView **ppRTVs, ITextureView **ppDSV); + /// Returns currently set viewports + inline void GetViewports( Uint32 &NumViewports, Viewport *pViewports ); - /// Creates and binds default depth stencil, rasterizer & blend states - void CreateDefaultStates(); + /// Returns the render device + IRenderDevice *GetDevice(){return m_pDevice;} - void GetShaders( IShader **ppShaders, Uint32 &NumShaders ); +protected: + inline bool SetBlendFactors(const float *BlendFactors, int Dummy); - void GetViewports( Uint32 &NumViewports, Viewport *pViewports ); + inline bool SetStencilRef(Uint32 StencilRef, int Dummy); -protected: /// Returns the size of the currently bound render target - void GetRenderTargetSize( Uint32 &RTWidth, Uint32 &RTHeight ); + inline void GetRenderTargetSize( Uint32 &RTWidth, Uint32 &RTHeight ); + + /// Clears all cached resources + inline void ClearStateCache(); /// Strong reference to the device. RefCntAutoPtr<IRenderDevice> m_pDevice; @@ -182,59 +160,51 @@ protected: /// weak reference to the immediate context. RefCntAutoPtr<ISwapChain> m_pSwapChain; - /// Vector of strong references to bound shaders - std::vector< RefCntAutoPtr<IShader> > m_pBoundShaders; - /// Vertex streams. Every stream holds strong reference to the buffer - std::vector<VertexStreamInfo> m_VertexStreams; + VertexStreamInfo m_VertexStreams[MaxBufferSlots]; + + /// Number of bound vertex streams + Uint32 m_NumVertexStreams = 0; - /// Strong reference to the bound vertex description object - RefCntAutoPtr<IVertexDescription> m_pVertexDesc; + /// Strong reference to the bound pipeline state object + RefCntAutoPtr<IPipelineState> m_pPipelineState; /// Strong reference to the bound index buffer RefCntAutoPtr<IBuffer> m_pIndexBuffer; + /// Offset from the beginning of the index buffer to the start of the index data, in bytes. Uint32 m_IndexDataStartOffset; - /// Strong references to the bound depth-stencil state - RefCntAutoPtr< IDepthStencilState > m_pDSState; - - /// Strong references to the bound rasterizer state - RefCntAutoPtr< IRasterizerState> m_pRasterizerState; - - /// Strong references to the bound blend state - RefCntAutoPtr< IBlendState> m_pBlendState; - /// Current stencil reference value Uint32 m_StencilRef; /// Curent blend factors Float32 m_BlendFactors[4]; - /// Current samples blend mask - Uint32 m_SamplesBlendMask; - /// Current viewports - std::vector<Viewport> m_Viewports; + Viewport m_Viewports[MaxRenderTargets]; + /// Number of current viewports + Uint32 m_NumViewports = 0; /// Current scissor rects - std::vector<Rect> m_ScissorRects; + Rect m_ScissorRects[MaxRenderTargets]; + /// Number of current scissor rects + Uint32 m_NumScissorRects = 0; - /// Vector of strong references to bound render targets - std::vector< RefCntAutoPtr<ITextureView> > m_pBoundRenderTargets; + /// Vector of strong references to the bound render targets + RefCntAutoPtr<ITextureView> m_pBoundRenderTargets[MaxRenderTargets]; + /// Number of bound render targets + Uint32 m_NumBoundRenderTargets = 0; /// Strong references to the bound depth stencil view RefCntAutoPtr<ITextureView> m_pBoundDepthStencil; -private: - RefCntAutoPtr<IDepthStencilState> m_pDefaultDSS; - RefCntAutoPtr<IRasterizerState> m_pDefaultRS; - RefCntAutoPtr<IBlendState> m_pDefaultBS; + bool m_bIsDeferred = false; }; template<typename BaseInterface> -void DeviceContextBase<BaseInterface> :: SetVertexBuffers( Uint32 StartSlot, Uint32 NumBuffersSet, IBuffer **ppBuffers, Uint32 *pStrides, Uint32 *pOffsets, Uint32 Flags ) +inline void DeviceContextBase<BaseInterface> :: SetVertexBuffers( Uint32 StartSlot, Uint32 NumBuffersSet, IBuffer **ppBuffers, Uint32 *pStrides, Uint32 *pOffsets, Uint32 Flags ) { if( StartSlot >= MaxBufferSlots ) { @@ -250,9 +220,12 @@ void DeviceContextBase<BaseInterface> :: SetVertexBuffers( Uint32 StartSlot, Uin if( Flags & SET_VERTEX_BUFFERS_FLAG_RESET ) { - m_VertexStreams.clear(); + for(Uint32 s=0; s < m_NumVertexStreams; ++s) + m_VertexStreams[s] = VertexStreamInfo(); + m_NumVertexStreams = 0; } - m_VertexStreams.resize( std::max(m_VertexStreams.size(), static_cast<size_t>(StartSlot + NumBuffersSet) ) ); + m_NumVertexStreams = std::max(m_NumVertexStreams, StartSlot + NumBuffersSet ); + for( Uint32 Buff = 0; Buff < NumBuffersSet; ++Buff ) { auto &CurrStream = m_VertexStreams[StartSlot + Buff]; @@ -271,27 +244,50 @@ void DeviceContextBase<BaseInterface> :: SetVertexBuffers( Uint32 StartSlot, Uin #endif } // Remove null buffers from the end of the array - while(m_VertexStreams.size() > 0 && !m_VertexStreams.back().pBuffer) - m_VertexStreams.pop_back(); + while(m_NumVertexStreams > 0 && !m_VertexStreams[m_NumVertexStreams-1].pBuffer) + m_VertexStreams[m_NumVertexStreams--] = VertexStreamInfo(); } template<typename BaseInterface> -void DeviceContextBase<BaseInterface> :: ClearState() +inline void DeviceContextBase<BaseInterface> :: SetPipelineState(IPipelineState *pPipelineState) { - UNSUPPORTED("This function is not implemented") - //m_VertexStreams.clear(); - //m_pIndexBuffer.Release(); - //m_IndexDataStartOffset = 0; + m_pPipelineState = pPipelineState; } template<typename BaseInterface> -void DeviceContextBase<BaseInterface> :: SetVertexDescription( IVertexDescription *pVertexDesc ) +inline bool DeviceContextBase<BaseInterface> :: CommitShaderResources(IShaderResourceBinding *pShaderResourceBinding, Uint32 Flags, int) { - m_pVertexDesc = pVertexDesc; +#ifdef _DEBUG + if (!m_pPipelineState) + { + LOG_ERROR_MESSAGE("No pipeline state is bound to the pipeline"); + return false; + } + + if (pShaderResourceBinding) + { + auto *pPSO = pShaderResourceBinding->GetPipelineState(); + if (pPSO != m_pPipelineState) + { + LOG_ERROR_MESSAGE("Shader resource binding object does not match currently bound pipeline state"); + return false; + } + } +#endif + return true; } template<typename BaseInterface> -void DeviceContextBase<BaseInterface> :: SetIndexBuffer( IBuffer *pIndexBuffer, Uint32 ByteOffset ) +inline void DeviceContextBase<BaseInterface> :: ClearState() +{ + UNSUPPORTED("This function is deprecated") + //m_VertexStreams.clear(); + //m_pIndexBuffer.Release(); + //m_IndexDataStartOffset = 0; +} + +template<typename BaseInterface> +inline void DeviceContextBase<BaseInterface> :: SetIndexBuffer( IBuffer *pIndexBuffer, Uint32 ByteOffset ) { m_pIndexBuffer = pIndexBuffer; m_IndexDataStartOffset = ByteOffset; @@ -305,151 +301,56 @@ void DeviceContextBase<BaseInterface> :: SetIndexBuffer( IBuffer *pIndexBuffer, } -/// \param [in] pDSState - pointer to the new depth-stencil state interface. -/// \param [in] StencilRef - new stencil reference value. -/// \param [in] Dummy - dummy argument required to make function signature distinct -/// from IDeviceContext::SetDepthStencilState(). This is required -/// because otherwise this overloaded function will only differ in -/// the return type which is not allowed. -/// \return -/// - True if either new depth stencil state or stencil reference value differs from -/// currently cached values. -/// - False otherwise. -/// -/// \remarks The method caches *strong reference* to the provided interface in m_pDSState. template<typename BaseInterface> -bool DeviceContextBase<BaseInterface> :: SetDepthStencilState( IDepthStencilState *pDSState, Uint32 StencilRef, Uint32 Dummy ) -{ - // If null depth-stencil state is provided, bind default state - if( !pDSState ) - pDSState = m_pDefaultDSS; - - // Here m_pDSState is certainly a live object because we keep the - // strong reference. pDSState is also clearly live object, so we can - // safely compare pointers. - if( m_pDSState != pDSState || m_StencilRef != StencilRef ) +inline void DeviceContextBase<BaseInterface> :: GetPipelineState(IPipelineState **ppPSO, float* BlendFactors, Uint32 &StencilRef) +{ + VERIFY( ppPSO != nullptr, "Null pointer provided null" ); + VERIFY( *ppPSO == nullptr, "Memory address contains a pointer to a non-null blend state" ); + if(m_pPipelineState) { - m_pDSState = pDSState; - m_StencilRef = StencilRef; - return true; + m_pPipelineState->QueryInterface( IID_PipelineState, reinterpret_cast<IObject**>( ppPSO ) ); + } + else + { + *ppPSO = nullptr; } - return false; -} + for( Uint32 f = 0; f < 4; ++f ) + BlendFactors[f] = m_BlendFactors[f]; + StencilRef = m_StencilRef; +}; -/// \param [in] pRS - pointer to the new rasterizer state interface. -/// \param [in] Dummy - dummy argument required to make function signature distinct -/// from IDeviceContext::SetRasterizerState(). This is required -/// because otherwise this overloaded function will only differ in -/// the return type which is not allowed. -/// \return -/// - True if the new rasterizer state differ from the cached state. -/// - False otherwise. -/// -/// \remarks The method caches *strong reference* to the provided interface in m_pRasterizerState. template<typename BaseInterface> -bool DeviceContextBase<BaseInterface> :: SetRasterizerState( IRasterizerState *pRS, Uint32 Dummy ) +inline bool DeviceContextBase<BaseInterface> ::SetBlendFactors(const float *BlendFactors, int) { - // If null rasterizer state provided, bind default state - if( !pRS ) - pRS = m_pDefaultRS; - - // Here m_pRasterizerState is certainly a live object because we keep the - // strong reference. pRS is also clearly live object, so we can - // safely compare pointers. - if( m_pRasterizerState != pRS ) + bool FactorsDiffer = false; + for( Uint32 f = 0; f < 4; ++f ) { - m_pRasterizerState = pRS; - return true; + if( m_BlendFactors[f] != BlendFactors[f] ) + FactorsDiffer = true; + m_BlendFactors[f] = BlendFactors[f]; } - - return false; + return FactorsDiffer; } - -/// \param [in] pBS - pointer to the new blend state interface. -/// \param [in] pBlendFactors - new blend factors. -/// \param [in] SampleMask - new sample mask. -/// \param [in] Dummy - dummy argument required to make function signature distinct -/// from IDeviceContext::SetBlendState(). This is required -/// because otherwise this overloaded function will only differ in -/// the return type which is not allowed. -/// \return -/// - True if either the new blend state, blend factors or sample mask value differs from -/// the currently cached values. -/// - False otherwise. -/// -/// \remarks The method caches *strong reference* to the provided interface in m_pBlendState. template<typename BaseInterface> -bool DeviceContextBase<BaseInterface> :: SetBlendState( IBlendState *pBS, const float* pBlendFactors, Uint32 SampleMask, Uint32 Dummy ) +inline bool DeviceContextBase<BaseInterface> :: SetStencilRef(Uint32 StencilRef, int) { - // If null blend state provided, bind default state - if( !pBS ) - pBS = m_pDefaultBS; - - static const float DefaultBlendFactors[4] = { 1, 1, 1, 1 }; - if( pBlendFactors == nullptr ) - pBlendFactors = DefaultBlendFactors; - - // Here m_pBlendState is certainly a live object because we keep the - // strong reference. pBS is also clearly live object, so we can - // safely compare pointers. - if( m_pBlendState != pBS || - m_BlendFactors[0] != pBlendFactors[0] || - m_BlendFactors[1] != pBlendFactors[1] || - m_BlendFactors[2] != pBlendFactors[2] || - m_BlendFactors[3] != pBlendFactors[3] || - m_SamplesBlendMask != SampleMask ) + if (m_StencilRef != StencilRef) { - m_pBlendState = pBS; - m_SamplesBlendMask = SampleMask; - for( int i = 0; i < 4; ++i ) - m_BlendFactors[i] = pBlendFactors[i]; - + m_StencilRef = StencilRef; return true; } - return false; } template<typename BaseInterface> -void DeviceContextBase<BaseInterface> :: GetDepthStencilState(IDepthStencilState **ppDSS, Uint32 &StencilRef) -{ - VERIFY( ppDSS != nullptr, "Null pointer provided null" ); - VERIFY( *ppDSS == nullptr, "Memory address contains a pointer to a non-null depth-stencil state" ); - VERIFY( m_pDSState, "No depth-stencil state is bound. At least default state must always be bound. Did you forget to call CreateDefaultStates()?" ); - m_pDSState->QueryInterface( IID_DepthStencilState, reinterpret_cast<IObject**>( ppDSS ) ); - StencilRef = m_StencilRef; -}; - -template<typename BaseInterface> -void DeviceContextBase<BaseInterface> :: GetRasterizerState(IRasterizerState **ppRS ) -{ - VERIFY( ppRS != nullptr, "Null pointer provided null" ); - VERIFY( *ppRS == nullptr, "Memory address contains a pointer to a non-null rasterizer state" ); - VERIFY( m_pRasterizerState, "No rasterizer state is bound. At least default state must always be bound. Did you forget to call CreateDefaultStates()?" ); - m_pRasterizerState->QueryInterface( IID_RasterizerState, reinterpret_cast<IObject**>( ppRS ) ); -} - -template<typename BaseInterface> -void DeviceContextBase<BaseInterface> :: GetBlendState( IBlendState **ppBS, float* BlendFactors, Uint32& SamplesBlendMask ) -{ - VERIFY( ppBS != nullptr, "Null pointer provided null" ); - VERIFY( *ppBS == nullptr, "Memory address contains a pointer to a non-null blend state" ); - VERIFY( m_pBlendState, "No blend state is bound. At least default state must always be bound. Did you forget to call CreateDefaultStates()?" ); - m_pBlendState->QueryInterface( IID_BlendState, reinterpret_cast<IObject**>( ppBS ) ); - for( Uint32 f = 0; f < 4; ++f ) - BlendFactors[f] = m_BlendFactors[f]; - SamplesBlendMask = m_SamplesBlendMask; -} - -template<typename BaseInterface> -void DeviceContextBase<BaseInterface> :: GetRenderTargetSize( Uint32 &RTWidth, Uint32 &RTHeight ) +inline void DeviceContextBase<BaseInterface> :: GetRenderTargetSize( Uint32 &RTWidth, Uint32 &RTHeight ) { RTWidth = 0; RTHeight = 0; // First, try to find non-null render target - for( Uint32 rt = 0; rt < m_pBoundRenderTargets.size(); ++rt ) + for( Uint32 rt = 0; rt < m_NumBoundRenderTargets; ++rt ) if( auto *pRTView = m_pBoundRenderTargets[rt].RawPtr() ) { // Use render target size as viewport size @@ -487,22 +388,24 @@ void DeviceContextBase<BaseInterface> :: GetRenderTargetSize( Uint32 &RTWidth, U } template<typename BaseInterface> -void DeviceContextBase<BaseInterface> :: SetViewports( Uint32 NumViewports, const Viewport *pViewports, Uint32 &RTWidth, Uint32 &RTHeight ) +inline void DeviceContextBase<BaseInterface> :: SetViewports( Uint32 NumViewports, const Viewport *pViewports, Uint32 &RTWidth, Uint32 &RTHeight ) { if( RTWidth == 0 || RTHeight == 0 ) { GetRenderTargetSize( RTWidth, RTHeight ); } - m_Viewports.resize(NumViewports); + VERIFY(NumViewports < MaxRenderTargets, "Num viewports (", NumViewports,") exceeds the limit (", MaxRenderTargets, ")") + m_NumViewports = std::min(MaxRenderTargets, NumViewports); + Viewport DefaultVP( 0, 0, static_cast<float>(RTWidth), static_cast<float>(RTHeight) ); // If no viewports are specified, use default viewport - if( NumViewports == 1 && pViewports == nullptr ) + if( m_NumViewports == 1 && pViewports == nullptr ) { pViewports = &DefaultVP; } - for( Uint32 vp = 0; vp < NumViewports; ++vp ) + for( Uint32 vp = 0; vp < m_NumViewports; ++vp ) { m_Viewports[vp] = pViewports[vp]; VERIFY( m_Viewports[vp].Width >= 0, "Incorrect viewport width (", m_Viewports[vp].Width, ")" ); @@ -512,26 +415,28 @@ void DeviceContextBase<BaseInterface> :: SetViewports( Uint32 NumViewports, cons } template<typename BaseInterface> -void DeviceContextBase<BaseInterface> :: GetViewports( Uint32 &NumViewports, Viewport *pViewports ) +inline void DeviceContextBase<BaseInterface> :: GetViewports( Uint32 &NumViewports, Viewport *pViewports ) { - NumViewports = static_cast<Uint32>( m_Viewports.size() ); + NumViewports = m_NumViewports; if( pViewports ) { - for( Uint32 vp = 0; vp < m_Viewports.size(); ++vp ) + for( Uint32 vp = 0; vp < m_NumViewports; ++vp ) pViewports[vp] = m_Viewports[vp]; } } template<typename BaseInterface> -void DeviceContextBase<BaseInterface> :: SetScissorRects( Uint32 NumRects, const Rect *pRects, Uint32 &RTWidth, Uint32 &RTHeight ) +inline void DeviceContextBase<BaseInterface> :: SetScissorRects( Uint32 NumRects, const Rect *pRects, Uint32 &RTWidth, Uint32 &RTHeight ) { if( RTWidth == 0 || RTHeight == 0 ) { GetRenderTargetSize( RTWidth, RTHeight ); } - m_ScissorRects.resize( NumRects ); - for( Uint32 sr = 0; sr < NumRects; ++sr ) + VERIFY(NumRects < MaxRenderTargets, "Num scissor rects (", NumRects,") exceeds the limit (", MaxRenderTargets, ")") + m_NumScissorRects = std::min(MaxRenderTargets, NumRects); + + for( Uint32 sr = 0; sr < m_NumScissorRects; ++sr ) { m_ScissorRects[sr] = pRects[sr]; VERIFY( m_ScissorRects[sr].left <= m_ScissorRects[sr].right, "Incorrect horizontal bounds for a scissor rect [", m_ScissorRects[sr].left, ", ", m_ScissorRects[sr].right, ")" ); @@ -540,13 +445,16 @@ void DeviceContextBase<BaseInterface> :: SetScissorRects( Uint32 NumRects, const } template<typename BaseInterface> -bool DeviceContextBase<BaseInterface> :: SetRenderTargets( Uint32 NumRenderTargets, ITextureView *ppRenderTargets[], ITextureView *pDepthStencil, Uint32 Dummy ) +inline bool DeviceContextBase<BaseInterface> :: SetRenderTargets( Uint32 NumRenderTargets, ITextureView *ppRenderTargets[], ITextureView *pDepthStencil, Uint32 Dummy ) { bool bBindRenderTargets = false; - if( NumRenderTargets != m_pBoundRenderTargets.size() ) + if( NumRenderTargets != m_NumBoundRenderTargets ) { bBindRenderTargets = true; - m_pBoundRenderTargets.resize(NumRenderTargets); + for(Uint32 rt=NumRenderTargets; rt<m_NumBoundRenderTargets; ++rt ) + m_pBoundRenderTargets[rt].Release(); + + m_NumBoundRenderTargets = NumRenderTargets; } for( Uint32 rt = 0; rt < NumRenderTargets; ++rt ) @@ -587,9 +495,9 @@ bool DeviceContextBase<BaseInterface> :: SetRenderTargets( Uint32 NumRenderTarge } template<typename BaseInterface> -void DeviceContextBase<BaseInterface> :: GetRenderTargets( Uint32 &NumRenderTargets, ITextureView **ppRTVs, ITextureView **ppDSV ) +inline void DeviceContextBase<BaseInterface> :: GetRenderTargets( Uint32 &NumRenderTargets, ITextureView **ppRTVs, ITextureView **ppDSV ) { - NumRenderTargets = static_cast<Uint32>( m_pBoundRenderTargets.size() ); + NumRenderTargets = m_NumBoundRenderTargets; if( ppRTVs ) { @@ -620,40 +528,51 @@ void DeviceContextBase<BaseInterface> :: GetRenderTargets( Uint32 &NumRenderTarg } template<typename BaseInterface> -void DeviceContextBase<BaseInterface> :: CreateDefaultStates() +inline void DeviceContextBase<BaseInterface> :: ClearStateCache() { - DepthStencilStateDesc DefaultDSSDesc; - DefaultDSSDesc.Name = "Default depth stencil state"; - m_pDevice->CreateDepthStencilState( DefaultDSSDesc, &m_pDefaultDSS ); - - RasterizerStateDesc DefaultRSDesc; - DefaultRSDesc.Name = "Default rasterizer state"; - m_pDevice->CreateRasterizerState( DefaultRSDesc, &m_pDefaultRS ); - - BlendStateDesc DefaultBlendState; - DefaultBlendState.Name = "Default blend state"; - m_pDevice->CreateBlendState( DefaultBlendState, &m_pDefaultBS ); - - SetDepthStencilState( m_pDefaultDSS, 0 ); - SetRasterizerState( m_pDefaultRS ); - float BlendFactors[4] = { 1, 1, 1, 1 }; - SetBlendState( m_pDefaultBS, BlendFactors, 0xFFFFFFFF ); -} + for(Uint32 stream=0; stream < m_NumVertexStreams; ++stream) + m_VertexStreams[stream] = VertexStreamInfo(); +#ifdef _DEBUG + for(Uint32 stream=m_NumVertexStreams; stream < _countof(m_VertexStreams); ++stream) + { + VERIFY(m_VertexStreams[stream].pBuffer == nullptr, "Unexpected non-null buffer"); + VERIFY(m_VertexStreams[stream].Offset == 0, "Unexpected non-zero offset"); + VERIFY(m_VertexStreams[stream].Stride == 0, "Unexpected non-zero stride"); + } +#endif + m_NumVertexStreams = 0; -template<typename BaseInterface> -void DeviceContextBase<BaseInterface> :: GetShaders( IShader **ppShaders, Uint32 &NumShaders ) -{ - NumShaders = static_cast<Uint32>( m_pBoundShaders.size() ); - if( ppShaders == nullptr ) - return; - for( Uint32 s = 0; s < NumShaders; ++s ) - { - VERIFY( ppShaders[s] == nullptr, "Non-null pointer found in shader array element #", s ); - if( auto pBoundShader = m_pBoundShaders[s] ) - pBoundShader->QueryInterface( IID_Shader, reinterpret_cast<IObject**>( ppShaders + s ) ); - else - ppShaders[s] = nullptr; + m_pPipelineState.Release(); + + m_pIndexBuffer.Release(); + m_IndexDataStartOffset = 0; + + m_StencilRef = 0; + + for( int i = 0; i < 4; ++i ) + m_BlendFactors[i] = -1; + + for(Uint32 vp=0; vp < m_NumViewports; ++vp) + m_Viewports[vp] = Viewport(); + m_NumViewports = 0; + + for(Uint32 sr=0; sr < m_NumScissorRects; ++sr) + m_ScissorRects[sr] = Rect(); + m_NumScissorRects = 0; + + /// Vector of strong references to bound render targets + for(Uint32 rt=0; rt < m_NumBoundRenderTargets; ++rt ) + m_pBoundRenderTargets[rt].Release(); +#ifdef _DEBUG + for (Uint32 rt = m_NumBoundRenderTargets; rt < _countof(m_pBoundRenderTargets); ++rt) + { + VERIFY(m_pBoundRenderTargets[rt] == nullptr, "Non-null render target found") } +#endif + // Set this to max RT count to force render targets to be bound next time + m_NumBoundRenderTargets = _countof(m_pBoundRenderTargets); + + m_pBoundDepthStencil.Release(); } } diff --git a/Graphics/GraphicsEngine/include/DeviceObjectBase.h b/Graphics/GraphicsEngine/include/DeviceObjectBase.h index f96b6d7c..f4ca83f9 100644 --- a/Graphics/GraphicsEngine/include/DeviceObjectBase.h +++ b/Graphics/GraphicsEngine/include/DeviceObjectBase.h @@ -1,4 +1,4 @@ -/* Copyright 2015 Egor Yusov +/* Copyright 2015-2016 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,21 +36,24 @@ template<typename BaseInterface> class RenderDeviceBase; /// Template class implementing base functionality for a device object -template<class BaseInterface, typename ObjectDescType> -class DeviceObjectBase : public ObjectBase<BaseInterface> +template<class BaseInterface, typename ObjectDescType, typename TObjectAllocator> +class DeviceObjectBase : public ObjectBase<BaseInterface, TObjectAllocator> { public: + typedef ObjectBase<BaseInterface, TObjectAllocator> TBase; + /// \param ObjAllocator - allocator that was used to allocate memory for this instance /// \param pDevice - pointer to the render device. /// \param ObjDesc - object description. /// \param pOwner - owner object. /// \param bIsDeviceInternal - flag indicating if the object is an internal device object /// and must not keep a strong reference to the device. - DeviceObjectBase( class IRenderDevice *pDevice, + DeviceObjectBase( TObjectAllocator &ObjAllocator, + class IRenderDevice *pDevice, const ObjectDescType &ObjDesc, IObject *pOwner = nullptr, bool bIsDeviceInternal = false) : - ObjectBase<BaseInterface>(pOwner), + TBase(pOwner, &ObjAllocator), m_pDevice( pDevice ), // Do not keep strong reference to the device if the object is an internal device object m_spDevice( bIsDeviceInternal ? nullptr : pDevice ), @@ -70,9 +73,9 @@ public: { } - IMPLEMENT_QUERY_INTERFACE_IN_PLACE( IID_DeviceObject, ObjectBase<BaseInterface> ) + IMPLEMENT_QUERY_INTERFACE_IN_PLACE( IID_DeviceObject, TBase ) - virtual const ObjectDescType& GetDesc()const override + virtual const ObjectDescType& GetDesc()const override final { return m_Desc; } @@ -88,11 +91,15 @@ public: return m_UniqueID.GetID(); } + IRenderDevice *GetDevice()const{return m_pDevice;} + protected: - IRenderDevice *GetDevice(){return m_pDevice;} + /// Copy of a device object name. - /// Copy of a device object name + /// When new object is created, its description structure is copied + /// to m_Desc, the name is copied to m_ObjectNameCopy, and + /// m_Desc.Name pointer is set to m_ObjectNameCopy.c_str(). const String m_ObjectNameCopy; /// Object description diff --git a/Graphics/GraphicsEngine/include/EngineMemory.h b/Graphics/GraphicsEngine/include/EngineMemory.h new file mode 100644 index 00000000..bf5f157c --- /dev/null +++ b/Graphics/GraphicsEngine/include/EngineMemory.h @@ -0,0 +1,73 @@ +/* Copyright 2015-2016 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +/// \file +/// Implementation of the Diligent::BufferBase template class + +#include "MemoryAllocator.h" + +namespace Diligent +{ + /// Sets raw memory allocator. This function must be called before any memory allocation/deallocation function + /// is called. + void SetRawAllocator(IMemoryAllocator *pRawAllocator); + + /// Returns raw memory allocator + IMemoryAllocator& GetRawAllocator(); +} + +#define NEW(Allocator, Desc, Type, ...) new(Allocator, Desc, __FILE__, __LINE__) Type(Allocator, ##__VA_ARGS__) +#define ALLOCATE(Allocator, Desc, Size) (Allocator).Allocate(Size, Desc, __FILE__, __LINE__) +#define FREE(Allocator, Ptr) Allocator.Free(Ptr) + +#if 0 +inline void* operator new(size_t Size, const char* dbgDescription, const char* dbgFileName, const int dbgLineNumber) +{ + return Diligent::GetRawAllocator().Allocate(Size, dbgDescription, dbgFileName, dbgLineNumber); +} + +inline void* operator new[](size_t Size, const char* dbgDescription, const char* dbgFileName, const int dbgLineNumber) +{ + return Diligent::GetRawAllocator().Allocate(Size, dbgDescription, dbgFileName, dbgLineNumber); +} + +// Arguments of the delete operator must exactly match the arguments of new +inline void operator delete(void* Ptr, const char* dbgDescription, const char* dbgFileName, const int dbgLineNumber) +{ + Diligent::GetRawAllocator().Free(Ptr); +} + +inline void operator delete[](void* Ptr, const char* dbgDescription, const char* dbgFileName, const int dbgLineNumber) +{ + Diligent::GetRawAllocator().Free(Ptr); +} + +#define MemAlloc(Size, Desc) GetRawAllocator().Allocate(Size, Desc, __FILE__, __LINE__) +#define MemFree(Ptr) GetRawAllocator().Free(Ptr) +#define New(Desc) new(Desc, __FILE__, __LINE__) +#define Delete delete + + +#endif
\ No newline at end of file diff --git a/Graphics/GraphicsEngine/include/PipelineStateBase.h b/Graphics/GraphicsEngine/include/PipelineStateBase.h new file mode 100644 index 00000000..1cb7d453 --- /dev/null +++ b/Graphics/GraphicsEngine/include/PipelineStateBase.h @@ -0,0 +1,194 @@ +/* Copyright 2015-2016 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +/// \file +/// Implementation of the Diligent::PipelineStateBase template class + +#include "PipelineState.h" +#include "DeviceObjectBase.h" +#include "STDAllocator.h" +#include "EngineMemory.h" +#include "GraphicsUtilities.h" + +namespace Diligent +{ + +/// Template class implementing base functionality for a pipeline state object. + +/// \tparam BaseInterface - base interface that this class will inheret +/// (Diligent::IPipelineStateD3D11, Diligent::IPipelineStateD3D12 or Diligent::IPipelineStateGL). +/// \tparam RenderDeviceBaseInterface - base interface for the render device +/// (Diligent::IRenderDeviceD3D11, Diligent::IRenderDeviceD3D12, Diligent::IRenderDeviceGL, +/// or Diligent::IRenderDeviceGLES). +template<class BaseInterface, class RenderDeviceBaseInterface, class PSOAllocator> +class PipelineStateBase : public DeviceObjectBase<BaseInterface, PipelineStateDesc, PSOAllocator> +{ +public: + typedef DeviceObjectBase<BaseInterface, PipelineStateDesc, PSOAllocator> TDeviceObjectBase; + typedef RenderDeviceBase < RenderDeviceBaseInterface > TRenderDeviceBase; + + /// \param ObjAllocator - allocator that was used to allocate memory for this instance of the pipeline state object + /// \param pDevice - pointer to the device. + /// \param PSODesc - pipeline state description. + /// \param bIsDeviceInternal - flag indicating if the blend state is an internal device object and + /// must not keep a strong reference to the device. + PipelineStateBase( PSOAllocator &ObjAllocator, IRenderDevice *pDevice, const PipelineStateDesc& PSODesc, bool bIsDeviceInternal = false ) : + TDeviceObjectBase( ObjAllocator, pDevice, PSODesc, nullptr, bIsDeviceInternal ), + m_LayoutElements( PSODesc.GraphicsPipeline.InputLayout.NumElements, LayoutElement(), STD_ALLOCATOR_RAW_MEM(LayoutElement, GetRawAllocator(), "Allocator for vector<LayoutElement>" ) ), + m_NumShaders(0) + { + memset(m_ppShaders, 0, sizeof(m_ppShaders)); + + if (this->m_Desc.IsComputePipeline) + { + const auto &ComputePipeline = PSODesc.ComputePipeline; + if (ComputePipeline.pCS == nullptr) + { + LOG_ERROR_AND_THROW( "Compute shader is not provided" ); + } + +#define VALIDATE_SHADER_TYPE(Shader, ExpectedType, ShaderName)\ + if (Shader && Shader->GetDesc().ShaderType != ExpectedType) \ + { \ + LOG_ERROR_AND_THROW( GetShaderTypeLiteralName(Shader->GetDesc().ShaderType), " is not valid type for ", ShaderName, " shader" );\ + } + VALIDATE_SHADER_TYPE(ComputePipeline.pCS, SHADER_TYPE_COMPUTE, "compute") + + m_pCS = ComputePipeline.pCS; + m_ppShaders[0] = ComputePipeline.pCS; + m_NumShaders = 1; + } + else + { + const auto &GraphicsPipeline = PSODesc.GraphicsPipeline; + + VALIDATE_SHADER_TYPE(GraphicsPipeline.pVS, SHADER_TYPE_VERTEX, "vertex") + VALIDATE_SHADER_TYPE(GraphicsPipeline.pPS, SHADER_TYPE_PIXEL, "pixel") + VALIDATE_SHADER_TYPE(GraphicsPipeline.pGS, SHADER_TYPE_GEOMETRY, "geometry") + VALIDATE_SHADER_TYPE(GraphicsPipeline.pHS, SHADER_TYPE_HULL, "hull") + VALIDATE_SHADER_TYPE(GraphicsPipeline.pDS, SHADER_TYPE_DOMAIN, "domain") +#undef VALIDATE_SHADER_TYPE + + m_pVS = GraphicsPipeline.pVS; + m_pPS = GraphicsPipeline.pPS; + m_pGS = GraphicsPipeline.pGS; + m_pDS = GraphicsPipeline.pDS; + m_pHS = GraphicsPipeline.pHS; + + if( GraphicsPipeline.pVS )m_ppShaders[m_NumShaders++] = GraphicsPipeline.pVS; + if( GraphicsPipeline.pPS )m_ppShaders[m_NumShaders++] = GraphicsPipeline.pPS; + if( GraphicsPipeline.pGS )m_ppShaders[m_NumShaders++] = GraphicsPipeline.pGS; + if( GraphicsPipeline.pHS )m_ppShaders[m_NumShaders++] = GraphicsPipeline.pHS; + if( GraphicsPipeline.pDS )m_ppShaders[m_NumShaders++] = GraphicsPipeline.pDS; + } + + const auto &InputLayout = PSODesc.GraphicsPipeline.InputLayout; + for( size_t Elem = 0; Elem < InputLayout.NumElements; ++Elem ) + m_LayoutElements[Elem] = InputLayout.LayoutElements[Elem]; + this->m_Desc.GraphicsPipeline.InputLayout.LayoutElements = m_LayoutElements.data(); + + // Correct description and compute offsets and tight strides + for( auto It = m_LayoutElements.begin(); It != m_LayoutElements.end(); ++It ) + { + if( It->ValueType == VT_FLOAT32 || It->ValueType == VT_FLOAT16 ) + It->IsNormalized = false; // Floating point values cannot be normalized + + auto BuffSlot = It->BufferSlot; + if( BuffSlot >= _countof(m_TightStrides) ) + { + UNEXPECTED("Buffer slot (", BuffSlot, ") exceeds the limit (", _countof(m_TightStrides), ")"); + continue; + } + + auto &CurrStride = m_TightStrides[BuffSlot]; + if( It->RelativeOffset < CurrStride ) + { + if( It->RelativeOffset == 0 ) + It->RelativeOffset = CurrStride; + else + UNEXPECTED( "Overlapping layout elements" ); + } + + CurrStride += It->NumComponents * GetValueSize( It->ValueType ); + } + } + + ~PipelineStateBase() + { + /* + /// \note Destructor cannot directly remove the object from the registry as this may cause a + /// deadlock at the point where StateObjectsRegistry::Find() locks the weak pointer: if we + /// are in dtor, the object is locked by Diligent::RefCountedObject::Release() and + /// StateObjectsRegistry::Find() will wait for that lock to be released. + /// A the same time this thread will be waiting for the other thread to unlock the registry.\n + /// Thus destructor only notifies the registry that there is a deleted object. + /// The reference to the object will be removed later. + auto &PipelineStateRegistry = static_cast<TRenderDeviceBase*>(this->GetDevice())->GetBSRegistry(); + auto &RasterizerStateRegistry = static_cast<TRenderDeviceBase*>(this->GetDevice())->GetRSRegistry(); + auto &DSSRegistry = static_cast<TRenderDeviceBase*>(this->GetDevice())->GetDSSRegistry(); + // StateObjectsRegistry::ReportDeletedObject() does not lock the registry, but only + // atomically increments the outstanding deleted objects counter. + PipelineStateRegistry.ReportDeletedObject(); + RasterizerStateRegistry.ReportDeletedObject(); + DSSRegistry.ReportDeletedObject(); + */ + } + + IMPLEMENT_QUERY_INTERFACE_IN_PLACE( IID_PipelineState, TDeviceObjectBase ) + + virtual const Uint32* GetTightStrides()const + { + return m_TightStrides; + } + + IShader* GetVS(){return m_pVS;} + IShader* GetPS(){return m_pPS;} + IShader* GetGS(){return m_pGS;} + IShader* GetDS(){return m_pDS;} + IShader* GetHS(){return m_pHS;} + IShader* GetCS(){return m_pCS;} + + IShader* const* GetShaders()const{return m_ppShaders;} + Uint32 GetNumShaders()const{return m_NumShaders;} + +protected: + std::vector<LayoutElement, STDAllocatorRawMem<LayoutElement> > m_LayoutElements; + + // The size of this array must be equal to the + // maximum number of buffer slots, because a layout + // element can refer to any input slot + Uint32 m_TightStrides[MaxBufferSlots] = {}; + + RefCntAutoPtr<IShader> m_pVS; ///< Strong reference to the vertex shader + RefCntAutoPtr<IShader> m_pPS; ///< Strong reference to the pixel shader + RefCntAutoPtr<IShader> m_pGS; ///< Strong reference to the geometry shader + RefCntAutoPtr<IShader> m_pDS; ///< Strong reference to the domain shader + RefCntAutoPtr<IShader> m_pHS; ///< Strong reference to the hull shader + RefCntAutoPtr<IShader> m_pCS; ///< Strong reference to the compute shader + IShader *m_ppShaders[5]; ///< Array of pointers to shaders that this PSO uses + Uint32 m_NumShaders; ///< Number of shaders that this PSO uses +}; + +} diff --git a/Graphics/GraphicsEngine/include/RasterizerStateBase.h b/Graphics/GraphicsEngine/include/RasterizerStateBase.h deleted file mode 100644 index a3c90275..00000000 --- a/Graphics/GraphicsEngine/include/RasterizerStateBase.h +++ /dev/null @@ -1,69 +0,0 @@ -/* Copyright 2015 Egor Yusov - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. - * - * In no event and under no legal theory, whether in tort (including negligence), - * contract, or otherwise, unless required by applicable law (such as deliberate - * and grossly negligent acts) or agreed to in writing, shall any Contributor be - * liable for any damages, including any direct, indirect, special, incidental, - * or consequential damages of any character arising as a result of this License or - * out of the use or inability to use the software (including but not limited to damages - * for loss of goodwill, work stoppage, computer failure or malfunction, or any and - * all other commercial damages or losses), even if such Contributor has been advised - * of the possibility of such damages. - */ - -#pragma once - -/// \file -/// Implementation of the Diligent::RasterizerStateBase template class - -#include "RasterizerState.h" -#include "DeviceObjectBase.h" - -namespace Diligent -{ - -/// Template class implementing base functionality for a rasterizer object. - -/// \tparam BaseInterface - base interface that this class will inheret -/// (Diligent::IRasterizerStateD3D11 or Diligent::IRasterizerStateGL). -/// \tparam RenderDeviceBaseInterface - base interface for the render device -/// (Diligent::IRenderDeviceD3D11, Diligent::IRenderDeviceGL, -/// or Diligent::IRenderDeviceGLES). -template<class BaseInterface = IRasterizerState, class RenderDeviceBaseInterface = IRenderDevice> -class RasterizerStateBase : public DeviceObjectBase<BaseInterface, RasterizerStateDesc> -{ -public: - typedef DeviceObjectBase<BaseInterface, RasterizerStateDesc> TDeviceObjectBase; - typedef RenderDeviceBase < RenderDeviceBaseInterface > TRenderDeviceBase; - - /// \param pDevice - pointer to the device. - /// \param RSDesc - rasterizer state description. - /// \param bIsDeviceInternal - flag indicating if the state is an internal device object and - /// must not keep a strong reference to the device. - RasterizerStateBase( IRenderDevice *pDevice, const RasterizerStateDesc& RSDesc, bool bIsDeviceInternal = false ) : - TDeviceObjectBase( pDevice, RSDesc, nullptr, bIsDeviceInternal ) - { - } - - ~RasterizerStateBase() - { - /// \note Destructor cannot directly remove the object from the registry as this may cause a - /// deadlock. See BlendStateBase::~BlendStateBase() for details. - auto &RasterizerStateRegistry = static_cast<TRenderDeviceBase*>(this->GetDevice())->GetRSRegistry(); - RasterizerStateRegistry.ReportDeletedObject(); - } - - IMPLEMENT_QUERY_INTERFACE_IN_PLACE( IID_RasterizerState, TDeviceObjectBase ) -}; - -} diff --git a/Graphics/GraphicsEngine/include/RenderDeviceBase.h b/Graphics/GraphicsEngine/include/RenderDeviceBase.h index 97103f23..bccb4b10 100644 --- a/Graphics/GraphicsEngine/include/RenderDeviceBase.h +++ b/Graphics/GraphicsEngine/include/RenderDeviceBase.h @@ -1,4 +1,4 @@ -/* Copyright 2015 Egor Yusov +/* Copyright 2015-2016 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,9 +36,9 @@ #include "DeviceContext.h" #include "SwapChain.h" #include "GraphicsUtilities.h" - -using Diligent::RefCntAutoPtr; -using Diligent::RefCntWeakPtr; +#include "FixedBlockMemoryAllocator.h" +#include "EngineMemory.h" +#include "STDAllocator.h" namespace std { @@ -48,8 +48,8 @@ namespace std { size_t operator()( const Diligent::SamplerDesc &SamDesc ) const { - // Sampler name is ignored in comparison operator - // and should not be hashed + // Sampler name is ignored in comparison operator + // and should not be hashed return Diligent::ComputeHash( // SamDesc.Name, static_cast<int>(SamDesc.MinFilter), static_cast<int>(SamDesc.MagFilter), @@ -75,9 +75,9 @@ namespace std size_t operator()( const Diligent::StencilOpDesc &StOpDesc ) const { return Diligent::ComputeHash( static_cast<int>( StOpDesc.StencilFailOp ), - static_cast<int>( StOpDesc.StencilDepthFailOp ), - static_cast<int>( StOpDesc.StencilPassOp ), - static_cast<int>( StOpDesc.StencilFunc ) ); + static_cast<int>( StOpDesc.StencilDepthFailOp ), + static_cast<int>( StOpDesc.StencilPassOp ), + static_cast<int>( StOpDesc.StencilFunc ) ); } }; @@ -85,19 +85,16 @@ namespace std template<> struct hash<Diligent::DepthStencilStateDesc> { - size_t operator()( const Diligent::DepthStencilStateDesc &DSSDesc ) const + size_t operator()( const Diligent::DepthStencilStateDesc &DepthStencilDesc ) const { - // Depth-stencil state name is ignored in comparison operator - // and should not be hashed - return Diligent::ComputeHash( // DSSDesc.Name, - DSSDesc.DepthEnable, - DSSDesc.DepthWriteEnable, - static_cast<int>(DSSDesc.DepthFunc), - DSSDesc.StencilEnable, - DSSDesc.StencilReadMask, - DSSDesc.StencilWriteMask, - DSSDesc.FrontFace, - DSSDesc.BackFace ); + return Diligent::ComputeHash( DepthStencilDesc.DepthEnable, + DepthStencilDesc.DepthWriteEnable, + static_cast<int>(DepthStencilDesc.DepthFunc), + DepthStencilDesc.StencilEnable, + DepthStencilDesc.StencilReadMask, + DepthStencilDesc.StencilWriteMask, + DepthStencilDesc.FrontFace, + DepthStencilDesc.BackFace ); } }; @@ -105,20 +102,17 @@ namespace std template<> struct hash<Diligent::RasterizerStateDesc> { - size_t operator()( const Diligent::RasterizerStateDesc &RSDesc ) const + size_t operator()( const Diligent::RasterizerStateDesc &RasterizerDesc ) const { - // Rasterizer state name is ignored in comparison operator - // and should not be hashed - return Diligent::ComputeHash( // RSDesc.Name, - static_cast<int>( RSDesc.FillMode ), - static_cast<int>( RSDesc.CullMode ), - RSDesc.FrontCounterClockwise, - RSDesc.DepthBias, - RSDesc.DepthBiasClamp, - RSDesc.SlopeScaledDepthBias, - RSDesc.DepthClipEnable, - RSDesc.ScissorEnable, - RSDesc.AntialiasedLineEnable ); + return Diligent::ComputeHash( static_cast<int>( RasterizerDesc.FillMode ), + static_cast<int>( RasterizerDesc.CullMode ), + RasterizerDesc.FrontCounterClockwise, + RasterizerDesc.DepthBias, + RasterizerDesc.DepthBiasClamp, + RasterizerDesc.SlopeScaledDepthBias, + RasterizerDesc.DepthClipEnable, + RasterizerDesc.ScissorEnable, + RasterizerDesc.AntialiasedLineEnable ); } }; @@ -143,17 +137,14 @@ namespace std rt.RenderTargetWriteMask ); } Diligent::HashCombine( Seed, - // Blend state name is ignored in comparison operator - // and should not be hashed - // BSDesc.Name, - BSDesc.AlphaToCoverageEnable, - BSDesc.IndependentBlendEnable ); + BSDesc.AlphaToCoverageEnable, + BSDesc.IndependentBlendEnable ); return Seed; } }; - /// Hash function specialization for Diligent::BlendStateDesc structure. + /// Hash function specialization for Diligent::TextureViewDesc structure. template<> struct hash<Diligent::TextureViewDesc> { @@ -162,7 +153,7 @@ namespace std std::size_t Seed = 0; Diligent::HashCombine( Seed, static_cast<Diligent::Int32>(TexViewDesc.ViewType), - static_cast<Diligent::Int32>(TexViewDesc.TextureType), + static_cast<Diligent::Int32>(TexViewDesc.TextureDim), static_cast<Diligent::Int32>(TexViewDesc.Format), TexViewDesc.MostDetailedMip, TexViewDesc.NumMipLevels, @@ -179,30 +170,63 @@ namespace Diligent /// Base implementation of a render device +/// \tparam BaseInterface - base interface that this class will inheret. /// \warning /// Render device must *NOT* hold strong references to any /// object it creates to avoid circular dependencies. /// Device context, swap chain and all object the device creates /// keep strong reference to the device. -/// Device only holds weak reference to immediate context. -template<typename BaseInterface = IRenderDevice> -class RenderDeviceBase : public ObjectBase<BaseInterface> +/// Device only holds weak reference to the immediate context. +template<typename BaseInterface> +class RenderDeviceBase : public ObjectBase<BaseInterface, IMemoryAllocator> { public: - RenderDeviceBase() : - m_TextureFormatsInfo( TEX_FORMAT_NUM_FORMATS ), - m_TexFmtInfoInitFlags( TEX_FORMAT_NUM_FORMATS ), - m_SamplersRegistry("sampler"), - m_DSSRegistry("ds state"), - m_RSRegistry("rasterizer state"), - m_BSRegistry("blend state") + + typedef ObjectBase<BaseInterface, IMemoryAllocator> TObjectBase; + + /// \param RawMemAllocator - allocator that will be used to allocate memory for all device objects (including render device itself) + /// \param NumDeferredContexts - number of deferred device contexts + /// \param TextureObjSize - size of the texture object, in bytes + /// \param TexViewObjSize - size of the texture view object, in bytes + /// \param BufferObjSize - size of the buffer object, in bytes + /// \param BuffViewObjSize - size of the buffer view object, in bytes + /// \param ShaderObjSize - size of the shader object, in bytes + /// \param SamplerObjSize - size of the sampler object, in bytes + /// \param PSOSize - size of the pipeline state object, in bytes + /// \param SRBSize - size of the shader resource binding object, in bytes + /// \remarks Render device uses fixed block allocators (see FixedBlockMemoryAllocator) to allocate memory for + /// device objects. The object sizes provided to constructor are used to initialize the allocators. + RenderDeviceBase(IMemoryAllocator &RawMemAllocator, + Uint32 NumDeferredContexts, + size_t TextureObjSize, + size_t TexViewObjSize, + size_t BufferObjSize, + size_t BuffViewObjSize, + size_t ShaderObjSize, + size_t SamplerObjSize, + size_t PSOSize, + size_t SRBSize) : + TObjectBase(nullptr, &RawMemAllocator), + m_TextureFormatsInfo( TEX_FORMAT_NUM_FORMATS, TextureFormatInfoExt(), STD_ALLOCATOR_RAW_MEM(TextureFormatInfoExt, RawMemAllocator, "Allocator for vector<TextureFormatInfoExt>") ), + m_TexFmtInfoInitFlags( TEX_FORMAT_NUM_FORMATS, false, STD_ALLOCATOR_RAW_MEM(bool, RawMemAllocator, "Allocator for vector<bool>") ), + m_wpDeferredContexts(NumDeferredContexts, RefCntWeakPtr<IDeviceContext>(), STD_ALLOCATOR_RAW_MEM(RefCntWeakPtr<IDeviceContext>, RawMemAllocator, "Allocator for vector< RefCntWeakPtr<IDeviceContext> >")), + m_SamplersRegistry(RawMemAllocator, "sampler"), + m_TexObjAllocator(RawMemAllocator, TextureObjSize, 64), + m_TexViewObjAllocator(RawMemAllocator, TexViewObjSize, 64), + m_BufObjAllocator(RawMemAllocator, BufferObjSize, 128), + m_BuffViewObjAllocator(RawMemAllocator, BuffViewObjSize, 128), + m_ShaderObjAllocator(RawMemAllocator, ShaderObjSize, 32), + m_SamplerObjAllocator(RawMemAllocator, SamplerObjSize, 32), + m_PSOAllocator(RawMemAllocator, PSOSize, 128), + m_SRBAllocator(RawMemAllocator, SRBSize, 1024), + m_ResMappingAllocator(RawMemAllocator, sizeof(ResourceMappingImpl), 16) { // Initialize texture format info for( Uint32 Fmt = TEX_FORMAT_UNKNOWN; Fmt < TEX_FORMAT_NUM_FORMATS; ++Fmt ) static_cast<TextureFormatAttribs&>(m_TextureFormatsInfo[Fmt]) = GetTextureFormatAttribs( static_cast<TEXTURE_FORMAT>(Fmt) ); // https://msdn.microsoft.com/en-us/library/windows/desktop/ff471325(v=vs.85).aspx - std::vector<TEXTURE_FORMAT> FilterableFormats = + TEXTURE_FORMAT FilterableFormats[] = { TEX_FORMAT_RGBA32_FLOAT, // OpenGL ES3.1 does not require this format to be filterable TEX_FORMAT_RGBA16_FLOAT, @@ -243,8 +267,8 @@ public: TEX_FORMAT_BC5_SNORM, TEX_FORMAT_B5G6R5_UNORM }; - for( auto fmt = FilterableFormats.begin(); fmt != FilterableFormats.end(); ++fmt ) - m_TextureFormatsInfo[ *fmt ].Filterable = true; + for( Uint32 fmt = 0; fmt < _countof(FilterableFormats); ++fmt ) + m_TextureFormatsInfo[ FilterableFormats[fmt] ].Filterable = true; } ~RenderDeviceBase() @@ -253,14 +277,17 @@ public: IMPLEMENT_QUERY_INTERFACE_IN_PLACE( IID_RenderDevice, ObjectBase<BaseInterface> ) - virtual void CreateResourceMapping( const ResourceMappingDesc &MappingDesc, IResourceMapping **ppMapping ); + /// Implementation of IRenderDevice::CreateResourceMapping(). + virtual void CreateResourceMapping( const ResourceMappingDesc &MappingDesc, IResourceMapping **ppMapping )override final; - virtual const DeviceCaps& GetDeviceCaps()const + /// Implementation of IRenderDevice::GetDeviceCaps(). + virtual const DeviceCaps& GetDeviceCaps()const override final { return m_DeviceCaps; } - virtual const TextureFormatInfo &GetTextureFormatInfo(TEXTURE_FORMAT TexFormat) + /// Implementation of IRenderDevice::GetTextureFormatInfo(). + virtual const TextureFormatInfo &GetTextureFormatInfo(TEXTURE_FORMAT TexFormat)override final { VERIFY( TexFormat >= TEX_FORMAT_UNKNOWN && TexFormat < TEX_FORMAT_NUM_FORMATS, "Texture format out of range" ); const auto& TexFmtInfo = m_TextureFormatsInfo[TexFormat]; @@ -268,7 +295,8 @@ public: return TexFmtInfo; } - virtual const TextureFormatInfoExt &GetTextureFormatInfoExt( TEXTURE_FORMAT TexFormat ) + /// Implementation of IRenderDevice::GetTextureFormatInfoExt(). + virtual const TextureFormatInfoExt &GetTextureFormatInfoExt( TEXTURE_FORMAT TexFormat )override final { VERIFY( TexFormat >= TEX_FORMAT_UNKNOWN && TexFormat < TEX_FORMAT_NUM_FORMATS, "Texture format out of range" ); const auto& TexFmtInfo = m_TextureFormatsInfo[TexFormat]; @@ -287,9 +315,6 @@ public: } StateObjectsRegistry<SamplerDesc> &GetSamplerRegistry(){ return m_SamplersRegistry; } - StateObjectsRegistry<DepthStencilStateDesc> &GetDSStateRegistry(){ return m_DSSRegistry; } - StateObjectsRegistry<RasterizerStateDesc> &GetRSRegistry() { return m_RSRegistry; } - StateObjectsRegistry<BlendStateDesc> &GetBSRegistry() { return m_BSRegistry; } /// Set weak reference to the immediate context void SetImmediateContext(IDeviceContext *pImmediateContext) @@ -298,7 +323,25 @@ public: m_wpImmediateContext = pImmediateContext; } + /// Set weak reference to the deferred context + void SetDeferredContext(size_t Ctx, IDeviceContext *pDeferredCtx) + { + VERIFY( m_wpDeferredContexts[Ctx].Lock() == nullptr, "Deferred context has already been set" ); + m_wpDeferredContexts[Ctx] = pDeferredCtx; + } + + /// Returns number of deferred contexts + size_t GetNumDeferredContexts()const + { + return m_wpDeferredContexts.size(); + } + RefCntAutoPtr<IDeviceContext> GetImmediateContext(){ return m_wpImmediateContext.Lock(); } + RefCntAutoPtr<IDeviceContext> GetDeferredContext(size_t Ctx){ return m_wpDeferredContexts[Ctx].Lock(); } + + FixedBlockMemoryAllocator& GetTexViewObjAllocator(){return m_TexViewObjAllocator;} + FixedBlockMemoryAllocator& GetBuffViewObjAllocator(){return m_BuffViewObjAllocator;} + FixedBlockMemoryAllocator& GetSRBAllocator(){return m_SRBAllocator;} protected: @@ -314,15 +357,25 @@ protected: // This is safe because every object unregisters itself // when it is deleted. StateObjectsRegistry<SamplerDesc> m_SamplersRegistry; ///< Sampler state registry - StateObjectsRegistry<DepthStencilStateDesc> m_DSSRegistry;///< Depth-stencil state registry - StateObjectsRegistry<RasterizerStateDesc> m_RSRegistry; ///< Rasterizer state registry - StateObjectsRegistry<BlendStateDesc> m_BSRegistry; ///< Blend state registry - std::vector<TextureFormatInfoExt> m_TextureFormatsInfo; - std::vector<bool> m_TexFmtInfoInitFlags; + std::vector<TextureFormatInfoExt, STDAllocatorRawMem<TextureFormatInfoExt> > m_TextureFormatsInfo; + std::vector<bool, STDAllocatorRawMem<bool> > m_TexFmtInfoInitFlags; /// Weak reference to the immediate context. Immediate context holds strong reference /// to the device, so we must use weak reference to avoid circular dependencies. - Diligent::RefCntWeakPtr<IDeviceContext> m_wpImmediateContext; + RefCntWeakPtr<IDeviceContext> m_wpImmediateContext; + + /// Weak references to deferred contexts. + std::vector< RefCntWeakPtr<IDeviceContext>, STDAllocatorRawMem<RefCntWeakPtr<IDeviceContext> > > m_wpDeferredContexts; + + FixedBlockMemoryAllocator m_TexObjAllocator; ///< Allocator for texture objects + FixedBlockMemoryAllocator m_TexViewObjAllocator; ///< Allocator for texture view objects + FixedBlockMemoryAllocator m_BufObjAllocator; ///< Allocator for buffer objects + FixedBlockMemoryAllocator m_BuffViewObjAllocator; ///< Allocator for buffer view objects + FixedBlockMemoryAllocator m_ShaderObjAllocator; ///< Allocator for shader objects + FixedBlockMemoryAllocator m_SamplerObjAllocator; ///< Allocator for sampler objects + FixedBlockMemoryAllocator m_PSOAllocator; ///< Allocator for pipeline state objects + FixedBlockMemoryAllocator m_SRBAllocator; ///< Allocator for shader resource binding objects + FixedBlockMemoryAllocator m_ResMappingAllocator; ///< Allocator for resource mapping objects }; @@ -334,20 +387,20 @@ void RenderDeviceBase<BaseInterface>::CreateResourceMapping( const ResourceMappi return; VERIFY( *ppMapping == nullptr, "Overwriting reference to existing object may cause memory leaks" ); - auto *pResourceMapping( new ResourceMappingImpl() ); + auto *pResourceMapping( NEW(m_ResMappingAllocator, "ResourceMappingImpl instance", ResourceMappingImpl, GetRawAllocator()) ); pResourceMapping->QueryInterface( IID_ResourceMapping, reinterpret_cast<IObject**>(ppMapping) ); if( MappingDesc.pEntries ) { for( auto *pEntry = MappingDesc.pEntries; pEntry->Name && pEntry->pObject; ++pEntry ) { - (*ppMapping)->AddResource( pEntry->Name, pEntry->pObject, true ); + (*ppMapping)->AddResourceArray( pEntry->Name, pEntry->ArrayIndex, &pEntry->pObject, 1, true ); } } } -/// \tparam TObjectType - type of the object being created (IBuffer, ITexture, IBlendState, etc.) -/// \tparam TObjectDescType - type of the object description structure (BufferDesc, TextureDesc, BlendStateDesc, etc.) +/// \tparam TObjectType - type of the object being created (IBuffer, ITexture, etc.) +/// \tparam TObjectDescType - type of the object description structure (BufferDesc, TextureDesc, etc.) /// \tparam TObjectConstructor - type of the function that constructs the object /// \param ObjectTypeName - string name of the object type ("buffer", "texture", etc.) /// \param Desc - object description diff --git a/Graphics/GraphicsEngine/include/ResourceMappingImpl.h b/Graphics/GraphicsEngine/include/ResourceMappingImpl.h index 6d412485..509632d7 100644 --- a/Graphics/GraphicsEngine/include/ResourceMappingImpl.h +++ b/Graphics/GraphicsEngine/include/ResourceMappingImpl.h @@ -1,4 +1,4 @@ -/* Copyright 2015 Egor Yusov +/* Copyright 2015-2016 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,29 +30,103 @@ #include "ObjectBase.h" #include <unordered_map> #include "HashUtils.h" +#include "STDAllocator.h" namespace Diligent { + struct ResMappingHashKey + { + ResMappingHashKey(const Char* Str, bool bMakeCopy, Uint32 ArrInd): + StrKey(Str, bMakeCopy), + ArrayIndex(ArrInd) + { + } + + ResMappingHashKey(ResMappingHashKey &&rhs) : + StrKey(std::move(rhs.StrKey)), + ArrayIndex(rhs.ArrayIndex) + {} + + bool operator == (const ResMappingHashKey& RHS)const + { + return StrKey == RHS.StrKey && ArrayIndex == RHS.ArrayIndex; + } + + size_t GetHash()const + { + if( Hash == 0 ) + { + Hash = ComputeHash( StrKey, ArrayIndex ); + } + + return Hash; + } + + + ResMappingHashKey( const ResMappingHashKey& ) = delete; + ResMappingHashKey& operator = ( const ResMappingHashKey& ) = delete; + ResMappingHashKey& operator = ( ResMappingHashKey&& ) = delete; + + HashMapStringKey StrKey; + Uint32 ArrayIndex; + mutable size_t Hash = 0; + }; +} + +namespace std +{ + template<> + struct hash<Diligent::ResMappingHashKey> + { + size_t operator()( const Diligent::ResMappingHashKey &Key ) const + { + return Key.GetHash(); + } + }; +} + +namespace Diligent +{ + class FixedBlockMemoryAllocator; + /// Implementation of the resource mapping - class ResourceMappingImpl : public ObjectBase<IResourceMapping> + class ResourceMappingImpl : public ObjectBase<IResourceMapping, FixedBlockMemoryAllocator> { public: + typedef ObjectBase<IResourceMapping, FixedBlockMemoryAllocator> TObjectBase; + + /// \param ObjAllocator allocator that was used to allocate memory for this instance of the resource mapping object. + /// \param RawMemAllocator raw memory allocator that is used by the m_HashTable member + ResourceMappingImpl(FixedBlockMemoryAllocator &ObjAllocator, IMemoryAllocator &RawMemAllocator) : + TObjectBase(nullptr, &ObjAllocator), + m_HashTable(STD_ALLOCATOR_RAW_MEM(HashTableElem, RawMemAllocator, "Allocator for unordered_map< ResMappingHashKey, RefCntAutoPtr<IDeviceObject> >") ) + {} + ~ResourceMappingImpl(); - virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface ); + virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )override final; + + /// Implementation of IResourceMapping::AddResource() + virtual void AddResource( const Char *Name, IDeviceObject *pObject, bool bIsUnique )override final; - virtual void AddResource( const Char *Name, IDeviceObject *pObject, bool bIsUnique ); - virtual void RemoveResource( IDeviceObject *pObject ); - virtual void RemoveResourceByName( const Char *Name ); + /// Implementation of IResourceMapping::AddResourceArray() + virtual void AddResourceArray( const Char *Name, Uint32 StartIndex, IDeviceObject * const* ppObjects, Uint32 NumElements, bool bIsUnique )override final; + + /// Implementation of IResourceMapping::RemoveResourceByName() + virtual void RemoveResourceByName( const Char *Name, Uint32 ArrayIndex )override final; - /// Finds resource in the mapping. If no resource is found, nullptr is returned - virtual void GetResource( const Char *Name, IDeviceObject **ppResource ); + /// Implementation of IResourceMapping::GetResource() + virtual void GetResource( const Char *Name, IDeviceObject **ppResource, Uint32 ArrayIndex )override final; + + /// Returns number of resources in the resource mapping. virtual size_t GetSize(); private: + ThreadingTools::LockHelper Lock(); ThreadingTools::LockFlag m_LockFlag; - std::unordered_map< Diligent::HashMapStringKey, Diligent::RefCntAutoPtr<IDeviceObject> > m_HashTable; + typedef std::pair<ResMappingHashKey, RefCntAutoPtr<IDeviceObject> > HashTableElem; + std::unordered_map< ResMappingHashKey, RefCntAutoPtr<IDeviceObject>, std::hash<ResMappingHashKey>, std::equal_to<ResMappingHashKey>, STDAllocatorRawMem<HashTableElem> > m_HashTable; }; } diff --git a/Graphics/GraphicsEngine/include/SamplerBase.h b/Graphics/GraphicsEngine/include/SamplerBase.h index de8ff566..cc6b8a94 100644 --- a/Graphics/GraphicsEngine/include/SamplerBase.h +++ b/Graphics/GraphicsEngine/include/SamplerBase.h @@ -1,4 +1,4 @@ -/* Copyright 2015 Egor Yusov +/* Copyright 2015-2016 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,29 +36,30 @@ namespace Diligent /// Template class implementing base functionality for a sampler object. /// \tparam BaseInterface - base interface that this class will inheret -/// (Diligent::ISamplerD3D11 or Diligent::ISamplerGL). +/// (Diligent::ISamplerD3D11, Diligent::ISamplerD3D12 or Diligent::ISamplerGL). /// \tparam RenderDeviceBaseInterface - base interface for the render device -/// (Diligent::IRenderDeviceD3D11, Diligent::IRenderDeviceGL, -/// or Diligent::IRenderDeviceGLES). -template<class BaseInterface = ISampler, class RenderDeviceBaseInterface = IRenderDevice> -class SamplerBase : public DeviceObjectBase<BaseInterface, SamplerDesc> +/// (Diligent::IRenderDeviceD3D11, Diligent::IRenderDeviceD3D12, Diligent::IRenderDeviceGL, or Diligent::IRenderDeviceGLES). +/// \tparam SamplerObjAllocator - type of the allocator that is used to allocate memory for the sampler object instances +template<class BaseInterface, class RenderDeviceBaseInterface, class SamplerObjAllocator> +class SamplerBase : public DeviceObjectBase<BaseInterface, SamplerDesc, SamplerObjAllocator> { public: - typedef DeviceObjectBase<BaseInterface, SamplerDesc> TDeviceObjectBase; + typedef DeviceObjectBase<BaseInterface, SamplerDesc, SamplerObjAllocator> TDeviceObjectBase; typedef RenderDeviceBase<RenderDeviceBaseInterface> TRenderDeviceBase; + /// \param ObjAllocator - allocator that was used to allocate memory for this instance of the sampler object /// \param pDevice - pointer to the device. /// \param SamDesc - sampler description. /// \param bIsDeviceInternal - flag indicating if the sampler is an internal device object and /// must not keep a strong reference to the device. - SamplerBase( IRenderDevice *pDevice, const SamplerDesc& SamDesc, bool bIsDeviceInternal = false ) : - TDeviceObjectBase( pDevice, SamDesc, nullptr, bIsDeviceInternal ) + SamplerBase( SamplerObjAllocator &ObjAllocator, IRenderDevice *pDevice, const SamplerDesc& SamDesc, bool bIsDeviceInternal = false ) : + TDeviceObjectBase( ObjAllocator, pDevice, SamDesc, nullptr, bIsDeviceInternal ) {} ~SamplerBase() { /// \note Destructor cannot directly remove the object from the registry as this may cause a - /// deadlock. See BlendStateBase::~BlendStateBase() for details. + /// deadlock. auto &SamplerRegistry = static_cast<TRenderDeviceBase *>(this->GetDevice())->GetSamplerRegistry(); SamplerRegistry.ReportDeletedObject(); } diff --git a/Graphics/GraphicsEngine/include/ShaderBase.h b/Graphics/GraphicsEngine/include/ShaderBase.h index b2f89341..1e03b352 100644 --- a/Graphics/GraphicsEngine/include/ShaderBase.h +++ b/Graphics/GraphicsEngine/include/ShaderBase.h @@ -1,4 +1,4 @@ -/* Copyright 2015 Egor Yusov +/* Copyright 2015-2016 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,39 +28,134 @@ #include "Shader.h" #include "DeviceObjectBase.h" +#include "STDAllocator.h" +#include "PlatformMisc.h" +#include "EngineMemory.h" namespace Diligent { +inline SHADER_TYPE GetShaderTypeFromIndex( Int32 Index ) +{ + return static_cast<SHADER_TYPE>(1 << Index); +} + +inline Int32 GetShaderTypeIndex( SHADER_TYPE Type ) +{ + Int32 ShaderIndex = PlatformMisc::GetLSB(Type); + +#ifdef _DEBUG + switch( Type ) + { + case SHADER_TYPE_UNKNOWN: VERIFY_EXPR(ShaderIndex == -1); break; + case SHADER_TYPE_VERTEX: VERIFY_EXPR(ShaderIndex == 0); break; + case SHADER_TYPE_PIXEL: VERIFY_EXPR(ShaderIndex == 1); break; + case SHADER_TYPE_GEOMETRY:VERIFY_EXPR(ShaderIndex == 2); break; + case SHADER_TYPE_HULL: VERIFY_EXPR(ShaderIndex == 3); break; + case SHADER_TYPE_DOMAIN: VERIFY_EXPR(ShaderIndex == 4); break; + case SHADER_TYPE_COMPUTE: VERIFY_EXPR(ShaderIndex == 5); break; + default: UNEXPECTED( "Unexpected shader type (", Type, ")" ); break; + } + VERIFY( Type == GetShaderTypeFromIndex(ShaderIndex), "Incorrect shader type index" ); +#endif + return ShaderIndex; +} + +static const int VSInd = GetShaderTypeIndex(SHADER_TYPE_VERTEX); +static const int PSInd = GetShaderTypeIndex(SHADER_TYPE_PIXEL); +static const int GSInd = GetShaderTypeIndex(SHADER_TYPE_GEOMETRY); +static const int HSInd = GetShaderTypeIndex(SHADER_TYPE_HULL); +static const int DSInd = GetShaderTypeIndex(SHADER_TYPE_DOMAIN); +static const int CSInd = GetShaderTypeIndex(SHADER_TYPE_COMPUTE); + +template<typename TNameCompare> +SHADER_VARIABLE_TYPE GetShaderVariableType(SHADER_VARIABLE_TYPE DefaultVariableType, const ShaderVariableDesc *VariableDesc, Uint32 NumVars, TNameCompare NameCompare) +{ + for (Uint32 v = 0; v < NumVars; ++v) + { + const auto &CurrVarDesc = VariableDesc[v]; + if ( NameCompare(CurrVarDesc.Name) ) + { + return CurrVarDesc.Type; + } + } + return DefaultVariableType; +} + +inline SHADER_VARIABLE_TYPE GetShaderVariableType(const Char* Name, SHADER_VARIABLE_TYPE DefaultVariableType, const ShaderVariableDesc *VariableDesc, Uint32 NumVars) +{ + return GetShaderVariableType(DefaultVariableType, VariableDesc, NumVars, + [&](const char *VarName) + { + return strcmp(VarName, Name) == 0; + } + ); +} + + /// Base implementation of a shader variable -struct ShaderVariableBase : public ObjectBase<IShaderVariable> + +struct ShaderVariableBase : public IShaderVariable { - ShaderVariableBase(IShader *pShader) : - // Shader variables are always created as part of the shader, - // so we must provide owner pointer to the base class constructor - ObjectBase<IShaderVariable>(pShader), - m_pShader(pShader) - {} + ShaderVariableBase(IObject &Owner) : + // Shader variables are always created as part of the shader, or + // shader resource binding, so we must provide owner pointer to + // the base class constructor + m_Owner(Owner) + { + } - virtual IShader* GetShader()override + IObject& GetOwner() { - return m_pShader; + return m_Owner; } - IMPLEMENT_QUERY_INTERFACE_IN_PLACE( IID_ShaderVariable, ObjectBase<IShaderVariable> ) + virtual IReferenceCounters* GetReferenceCounters()const override final + { + return m_Owner.GetReferenceCounters(); + } + + virtual Atomics::Long AddRef()override final + { + return m_Owner.AddRef(); + } + + virtual Atomics::Long Release()override final + { + return m_Owner.Release(); + } + + virtual void QueryInterface( const INTERFACE_ID &IID, IObject **ppInterface )override final + { + if( ppInterface == nullptr ) + return; + + *ppInterface = nullptr; + if( IID == IID_ShaderVariable || IID == IID_Unknown ) + { + *ppInterface = this; + (*ppInterface)->AddRef(); + } + } protected: - IShader *m_pShader; + IObject &m_Owner; }; /// Implementation of a dummy shader variable that silently ignores all operations struct DummyShaderVariable : ShaderVariableBase { - DummyShaderVariable(IShader *pShader) : - ShaderVariableBase(pShader) + DummyShaderVariable(IObject &Owner) : + ShaderVariableBase(Owner) {} - virtual void Set( IDeviceObject *pObject )override + virtual void Set( IDeviceObject *pObject )override final + { + // Ignore operation + // Probably output warning + } + + virtual void SetArray(IDeviceObject* const* ppObjects, Uint32 FirstElement, Uint32 NumElements)override final { // Ignore operation // Probably output warning @@ -68,25 +163,77 @@ struct DummyShaderVariable : ShaderVariableBase }; /// Template class implementing base functionality for a shader object -template<class BaseInterface = IShader, class RenderDeviceBaseInterface = IRenderDevice> -class ShaderBase : public DeviceObjectBase<BaseInterface, ShaderDesc> + +/// \tparam BaseInterface - base interface that this class will inheret +/// (Diligent::IShaderD3D11, Diligent::IShaderD3D12 or Diligent::IShaderGL). +/// \tparam RenderDeviceBaseInterface - base interface for the render device +/// (Diligent::IRenderDeviceD3D11, Diligent::IRenderDeviceD3D12, Diligent::IRenderDeviceGL, or Diligent::IRenderDeviceGLES). +/// \tparam ShaderObjAllocator - type of the allocator that is used to allocate memory for the shader object instances +template<class BaseInterface, class RenderDeviceBaseInterface, class ShaderObjAllocator> +class ShaderBase : public DeviceObjectBase<BaseInterface, ShaderDesc, ShaderObjAllocator> { public: - typedef DeviceObjectBase<BaseInterface, ShaderDesc> TDeviceObjectBase; + typedef DeviceObjectBase<BaseInterface, ShaderDesc, ShaderObjAllocator> TDeviceObjectBase; + /// \param ObjAllocator - allocator that was used to allocate memory for this instance of the shader object /// \param pDevice - pointer to the device. /// \param ShdrDesc - shader description. /// \param bIsDeviceInternal - flag indicating if the shader is an internal device object and /// must not keep a strong reference to the device. - ShaderBase( IRenderDevice *pDevice, const ShaderDesc& ShdrDesc, bool bIsDeviceInternal = false ) : - TDeviceObjectBase( pDevice, ShdrDesc, nullptr, bIsDeviceInternal ), - m_DummyShaderVar(this) - {} + ShaderBase( ShaderObjAllocator &ObjAllocator, IRenderDevice *pDevice, const ShaderDesc& ShdrDesc, bool bIsDeviceInternal = false ) : + TDeviceObjectBase( ObjAllocator, pDevice, ShdrDesc, nullptr, bIsDeviceInternal ), + m_DummyShaderVar(*this), + m_VariablesDesc(ShdrDesc.NumVariables, ShaderVariableDesc(), STD_ALLOCATOR_RAW_MEM(ShaderVariableDesc, GetRawAllocator(), "Allocator for vector<ShaderVariableDesc>") ), + m_StringPool(ShdrDesc.NumVariables + ShdrDesc.NumStaticSamplers, String(), STD_ALLOCATOR_RAW_MEM(String, GetRawAllocator(), "Allocator for vector<String>")), + m_StaticSamplers(ShdrDesc.NumStaticSamplers, StaticSamplerDesc(), STD_ALLOCATOR_RAW_MEM(StaticSamplerDesc, GetRawAllocator(), "Allocator for vector<StaticSamplerDesc>") ) + { + auto Str = m_StringPool.begin(); + if(this->m_Desc.VariableDesc) + { + for (Uint32 v = 0; v < this->m_Desc.NumVariables; ++v, ++Str) + { + m_VariablesDesc[v] = this->m_Desc.VariableDesc[v]; + VERIFY( m_VariablesDesc[v].Name != nullptr, "Variable name not provided" ) + *Str = m_VariablesDesc[v].Name; + m_VariablesDesc[v].Name = Str->c_str(); + } + this->m_Desc.VariableDesc = m_VariablesDesc.data(); + } + if(this->m_Desc.StaticSamplers) + { + for (Uint32 s = 0; s < this->m_Desc.NumStaticSamplers; ++s, ++Str) + { + m_StaticSamplers[s] = this->m_Desc.StaticSamplers[s]; + VERIFY( m_StaticSamplers[s].TextureName != nullptr, "Static sampler texture name not provided" ) + *Str = m_StaticSamplers[s].TextureName; + m_StaticSamplers[s].TextureName = Str->c_str(); +#ifdef _DEBUG + const auto &BorderColor = m_StaticSamplers[s].Desc.BorderColor; + if( !(BorderColor[0] == 0 && BorderColor[1] == 0 && BorderColor[2] == 0 && BorderColor[3] == 0 || + BorderColor[0] == 0 && BorderColor[1] == 0 && BorderColor[2] == 0 && BorderColor[3] == 1 || + BorderColor[0] == 1 && BorderColor[1] == 1 && BorderColor[2] == 1 && BorderColor[3] == 0) ) + { + LOG_WARNING_MESSAGE("Static sampler for variable \"", *Str , "\" specifies border color (", BorderColor[0], ", ", BorderColor[1], ", ", BorderColor[2], ", ", BorderColor[3], "). D3D12 static samplers only allow transparent black (0,0,0,1), opaque black (0,0,0,0) or opaque white (1,1,1,0) as border colors") + } +#endif + } + this->m_Desc.StaticSamplers = m_StaticSamplers.data(); + } + + VERIFY_EXPR(Str == m_StringPool.end()) + } IMPLEMENT_QUERY_INTERFACE_IN_PLACE( IID_Shader, TDeviceObjectBase ) protected: DummyShaderVariable m_DummyShaderVar; ///< Dummy shader variable + + /// Shader variable descriptions + std::vector<ShaderVariableDesc, STDAllocatorRawMem<ShaderVariableDesc> > m_VariablesDesc; + /// String pool that is used to hold copies of variable names and static sampler names + std::vector<String, STDAllocatorRawMem<String> > m_StringPool; + /// Static sampler descriptions + std::vector<StaticSamplerDesc, STDAllocatorRawMem<StaticSamplerDesc> > m_StaticSamplers; }; } diff --git a/Graphics/GraphicsEngine/include/ShaderResourceBindingBase.h b/Graphics/GraphicsEngine/include/ShaderResourceBindingBase.h new file mode 100644 index 00000000..ce5435f7 --- /dev/null +++ b/Graphics/GraphicsEngine/include/ShaderResourceBindingBase.h @@ -0,0 +1,75 @@ +/* Copyright 2015-2016 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +/// \file +/// Implementation of the Diligent::ShaderResourceBindingBase template class + +#include "ShaderResourceBinding.h" +#include "ObjectBase.h" +#include "GraphicsTypes.h" +#include "RefCntAutoPtr.h" + +namespace Diligent +{ + +/// Template class implementing base functionality for a shader resource binding + +/// \tparam BaseInterface - base interface that this class will inheret +/// (Diligent::IShaderResourceBindingGL, Diligent::IShaderResourceBindingD3D11, or Diligent::IShaderResourceBindingD3D12). +/// \tparam SRBAllocator - type of the allocator that is used to allocate memory for the shader resource binding object instances +template<class BaseInterface, class SRBAllocator> +class ShaderResourceBindingBase : public ObjectBase<BaseInterface, SRBAllocator> +{ +public: + typedef ObjectBase<BaseInterface, SRBAllocator> TObjectBase; + + /// \param ObjAllocator - allocator that was used to allocate memory for this instance of the shader resource binding object + /// \param pPSO - pipeline state that this SRB belongs to. + /// \param IsInternal - flag indicating if the shader resource binding is an internal PSO object and + /// must not keep a strong reference to the PSO. + ShaderResourceBindingBase( SRBAllocator &ObjAllocator, IPipelineState *pPSO, bool IsInternal = false ) : + TObjectBase( IsInternal ? pPSO : nullptr, &ObjAllocator ), + m_pPSO( pPSO ), + m_spPSO( IsInternal ? nullptr : pPSO ) + {} + + IMPLEMENT_QUERY_INTERFACE_IN_PLACE( IID_ShaderResourceBinding, TObjectBase ) + + /// Implementation of IShaderResourceBinding::GetPipelineState(). + virtual IPipelineState* GetPipelineState()override final + { + return m_pPSO; + } + +protected: + + /// Strong reference to PSO. We must use strong reference, because + /// shader resource binding uses PSO's memory allocator to allocate + /// memory for shader resource cache. + Diligent::RefCntAutoPtr<IPipelineState> m_spPSO; + IPipelineState *m_pPSO; +}; + +} diff --git a/Graphics/GraphicsEngine/include/StateObjectsRegistry.h b/Graphics/GraphicsEngine/include/StateObjectsRegistry.h index e26d1183..35840476 100644 --- a/Graphics/GraphicsEngine/include/StateObjectsRegistry.h +++ b/Graphics/GraphicsEngine/include/StateObjectsRegistry.h @@ -1,4 +1,4 @@ -/* Copyright 2015 Egor Yusov +/* Copyright 2015-2016 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,6 +28,7 @@ #include "DeviceObject.h" #include <unordered_map> +#include "STDAllocator.h" namespace Diligent { @@ -60,8 +61,9 @@ namespace Diligent /// Number of outstanding deleted objects to purge the registry. static const int DeletedObjectsToPurge = 32; - StateObjectsRegistry(const Char* RegistryName) : - m_RegistryName( RegistryName ) + StateObjectsRegistry(IMemoryAllocator &RawAllocator, const Char* RegistryName) : + m_RegistryName( RegistryName ), + m_DescToObjHashMap(STD_ALLOCATOR_RAW_MEM(HashMapElem, RawAllocator, "Allocator for unordered_map<ResourceDescType, RefCntWeakPtr<IDeviceObject> >") ) {} ~StateObjectsRegistry() @@ -196,7 +198,8 @@ namespace Diligent Atomics::AtomicLong m_NumDeletedObjects; /// Hash map that stores weak pointers to the referenced objects - std::unordered_map<ResourceDescType, Diligent::RefCntWeakPtr<IDeviceObject> > m_DescToObjHashMap; + typedef std::pair< ResourceDescType, RefCntWeakPtr<IDeviceObject> > HashMapElem; + std::unordered_map<ResourceDescType, RefCntWeakPtr<IDeviceObject>, std::hash<ResourceDescType>, std::equal_to<ResourceDescType>, STDAllocatorRawMem<HashMapElem> > m_DescToObjHashMap; /// Registry name used for debug output const String m_RegistryName; diff --git a/Graphics/GraphicsEngine/include/SwapChainBase.h b/Graphics/GraphicsEngine/include/SwapChainBase.h index c3400877..9b65e80f 100644 --- a/Graphics/GraphicsEngine/include/SwapChainBase.h +++ b/Graphics/GraphicsEngine/include/SwapChainBase.h @@ -1,4 +1,4 @@ -/* Copyright 2015 Egor Yusov +/* Copyright 2015-2016 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,17 +34,26 @@ namespace Diligent /// Base implementation of the swap chain. +/// \tparam BaseInterface - base interface that this class will inheret +/// (Diligent::ISwapChainGL, Diligent::ISwapChainD3D11, or Diligent::ISwapChainD3D12). +/// \tparam SwapChainAllocator - type of the allocator that is used to allocate memory for the swap chain object instance /// \remarks Swap chain holds the strong reference to the device and a weak reference to the /// immediate context. -template<class BaseInterface = ISwapChain> -class SwapChainBase : public ObjectBase<BaseInterface> +template<class BaseInterface, class SwapChainAllocator> +class SwapChainBase : public ObjectBase<BaseInterface, SwapChainAllocator> { public: - typedef ObjectBase<BaseInterface> TObjectBase; + typedef ObjectBase<BaseInterface, SwapChainAllocator> TObjectBase; - SwapChainBase( IRenderDevice *pDevice, - IDeviceContext *pDeviceContext, - const SwapChainDesc& SCDesc ) : + /// \param Allocator - allocator that was used to allocate memory for this instance of the swap chain object + /// \param pDevice - pointer to the device. + /// \param pDeviceContext - pointer to the device context. + /// \param SCDesc - swap chain description + SwapChainBase( SwapChainAllocator &Allocator, + IRenderDevice *pDevice, + IDeviceContext *pDeviceContext, + const SwapChainDesc& SCDesc ) : + TObjectBase(nullptr, &Allocator), m_pRenderDevice(pDevice), m_wpDeviceContext(pDeviceContext), m_SwapChainDesc(SCDesc) @@ -57,7 +66,8 @@ public: IMPLEMENT_QUERY_INTERFACE_IN_PLACE( IID_SwapChain, TObjectBase ) - virtual const SwapChainDesc& GetDesc()const + /// Implementation of ISwapChain::GetDesc() + virtual const SwapChainDesc& GetDesc()const override final { return m_SwapChainDesc; } @@ -70,6 +80,7 @@ protected: { m_SwapChainDesc.Width = NewWidth; m_SwapChainDesc.Height = NewHeight; + LOG_INFO_MESSAGE("Changing display resolution to ", m_SwapChainDesc.Width, "x", m_SwapChainDesc.Height); return true; } diff --git a/Graphics/GraphicsEngine/include/TextureBase.h b/Graphics/GraphicsEngine/include/TextureBase.h index 094de62d..4769a97f 100644 --- a/Graphics/GraphicsEngine/include/TextureBase.h +++ b/Graphics/GraphicsEngine/include/TextureBase.h @@ -1,4 +1,4 @@ -/* Copyright 2015 Egor Yusov +/* Copyright 2015-2016 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ #include "Texture.h" #include "DeviceObjectBase.h" #include "GraphicsUtilities.h" +#include "STDAllocator.h" #include <memory> namespace Diligent @@ -43,49 +44,61 @@ void VliadateCopyTextureDataParams( const TextureDesc &SrcTexDesc, Uint32 SrcMip /// Base implementation of the ITexture interface /// \tparam BaseInterface - base interface that this class will inheret -/// (Diligent::ITextureD3D11 or Diligent::ITextureGL). +/// (Diligent::ITextureD3D11, Diligent::ITextureD3D12 or Diligent::ITextureGL). /// \tparam TTextureViewImpl - type of the texture view implementation -/// (Diligent::TextureViewD3D11Impl or Diligent::TextureViewGLImpl). -template<class BaseInterface, class TTextureViewImpl> -class TextureBase : public DeviceObjectBase<BaseInterface, TextureDesc> +/// (Diligent::TextureViewD3D11Impl, Diligent::TextureViewD3D12Impl or Diligent::TextureViewGLImpl). +/// \tparam TTexObjAllocator - type of the allocator that is used to allocate memory for the texture object instances +/// \tparam TTexViewObjAllocator - type of the allocator that is used to allocate memory for the texture view object instances +template<class BaseInterface, class TTextureViewImpl, class TTexObjAllocator, class TTexViewObjAllocator> +class TextureBase : public DeviceObjectBase<BaseInterface, TextureDesc, TTexObjAllocator> { public: - typedef DeviceObjectBase<BaseInterface, TextureDesc> TDeviceObjectBase; + typedef DeviceObjectBase<BaseInterface, TextureDesc, TTexObjAllocator> TDeviceObjectBase; + /// \param TexObjAllocator - allocator that was used to allocate memory for this instance of the texture object + /// \param TexViewObjAllocator - allocator that is used to allocate memory for the instances of the texture view object. + /// This parameter is only used for debug purposes. /// \param pDevice - pointer to the device /// \param Desc - texture description /// \param bIsDeviceInternal - flag indicating if the texture is an internal device object and /// must not keep a strong reference to the device - TextureBase( IRenderDevice *pDevice, const TextureDesc& Desc, bool bIsDeviceInternal = false ) : - TDeviceObjectBase( pDevice, Desc, nullptr, bIsDeviceInternal ) + TextureBase( TTexObjAllocator &TexObjAllocator, + TTexViewObjAllocator &TexViewObjAllocator, + IRenderDevice *pDevice, + const TextureDesc& Desc, + bool bIsDeviceInternal = false ) : + TDeviceObjectBase( TexObjAllocator, pDevice, Desc, nullptr, bIsDeviceInternal ), +#ifdef _DEBUG + m_dbgTexViewObjAllocator(TexViewObjAllocator), +#endif + m_pDefaultSRV(nullptr, STDDeleter<TTextureViewImpl, TTexViewObjAllocator>(TexViewObjAllocator)), + m_pDefaultRTV(nullptr, STDDeleter<TTextureViewImpl, TTexViewObjAllocator>(TexViewObjAllocator)), + m_pDefaultDSV(nullptr, STDDeleter<TTextureViewImpl, TTexViewObjAllocator>(TexViewObjAllocator)), + m_pDefaultUAV(nullptr, STDDeleter<TTextureViewImpl, TTexViewObjAllocator>(TexViewObjAllocator)) { if( this->m_Desc.MipLevels == 0 ) { - // Compute the number of levels in the full mipmap chain based - // on the maximum texture dimension - Uint32 MaxDim = 0; - if( this->m_Desc.Type == TEXTURE_TYPE_1D || - this->m_Desc.Type == TEXTURE_TYPE_1D_ARRAY ) + // Compute the number of levels in the full mipmap chain + if( this->m_Desc.Type == RESOURCE_DIM_TEX_1D || + this->m_Desc.Type == RESOURCE_DIM_TEX_1D_ARRAY ) { - MaxDim = this->m_Desc.Width; + this->m_Desc.MipLevels = ComputeMipLevelsCount(this->m_Desc.Width); } - else if( this->m_Desc.Type == TEXTURE_TYPE_2D || - this->m_Desc.Type == TEXTURE_TYPE_2D_ARRAY ) + else if( this->m_Desc.Type == RESOURCE_DIM_TEX_2D || + this->m_Desc.Type == RESOURCE_DIM_TEX_2D_ARRAY || + this->m_Desc.Type == RESOURCE_DIM_TEX_CUBE || + this->m_Desc.Type == RESOURCE_DIM_TEX_CUBE_ARRAY ) { - MaxDim = std::max( this->m_Desc.Width, this->m_Desc.Height ); + this->m_Desc.MipLevels = ComputeMipLevelsCount( this->m_Desc.Width, this->m_Desc.Height ); } - else if( this->m_Desc.Type == TEXTURE_TYPE_3D ) + else if( this->m_Desc.Type == RESOURCE_DIM_TEX_3D ) { - MaxDim = std::max( this->m_Desc.Width, this->m_Desc.Height ); - MaxDim = std::max( MaxDim, this->m_Desc.Depth ); + this->m_Desc.MipLevels = ComputeMipLevelsCount( this->m_Desc.Width, this->m_Desc.Height, this->m_Desc.Depth ); } else { UNEXPECTED( "Unkwnown texture type" ); } - while( (MaxDim >> this->m_Desc.MipLevels) > 0 ) - ++this->m_Desc.MipLevels; - VERIFY( MaxDim >= (1U << (this->m_Desc.MipLevels-1)) && MaxDim < (1U << this->m_Desc.MipLevels), "Incorrect number of Mip levels" ) } // Validate correctness of texture description @@ -94,14 +107,17 @@ public: IMPLEMENT_QUERY_INTERFACE_IN_PLACE( IID_Texture, TDeviceObjectBase ) + /// Implementaiton of ITexture::CreateView(); calls CreateViewInternal() virtual function that + /// creates texture view for the specific engine implementation. virtual void CreateView( const struct TextureViewDesc &ViewDesc, ITextureView **ppView )override { CreateViewInternal( ViewDesc, ppView, false ); } + /// Base implementaiton of ITexture::UpdateData(); validates input parameters virtual void UpdateData( IDeviceContext *pContext, Uint32 MipLevel, Uint32 Slice, const Box &DstBox, const TextureSubResData &SubresData ) = 0; - + /// Base implementaiton of ITexture::CopyData(); validates input parameters virtual void CopyData( IDeviceContext *pContext, ITexture *pSrcTexture, Uint32 SrcMipLevel, @@ -113,22 +129,42 @@ public: Uint32 DstY, Uint32 DstZ ) = 0; + /// Base implementaiton of ITexture::Map() virtual void Map( IDeviceContext *pContext, MAP_TYPE MapType, Uint32 MapFlags, PVoid &pMappedData ) = 0; - virtual void Unmap( IDeviceContext *pContext ) = 0; + /// Base implementaiton of ITexture::Unmap() + virtual void Unmap( IDeviceContext *pContext, MAP_TYPE MapType ) = 0; + + /// Creates default texture views. + /// + /// - Creates default shader resource view addressing the entire texture if Diligent::BIND_SHADER_RESOURCE flag is set. + /// - Creates default render target view addressing the most detailed mip level if Diligent::BIND_RENDER_TARGET flag is set. + /// - Creates default depth-stencil view addressing the most detailed mip level if Diligent::BIND_DEPTH_STENCIL flag is set. + /// - Creates default unordered access view addressing the entire texture if Diligent::BIND_UNORDERED_ACCESS flag is set. + /// + /// The function calls CreateViewInternal(). void CreateDefaultViews(); protected: + /// Pure virtual function that creates texture view for the specific engine implementation. virtual void CreateViewInternal( const struct TextureViewDesc &ViewDesc, ITextureView **ppView, bool bIsDefaultView ) = 0; +#ifdef _DEBUG + TTexViewObjAllocator &m_dbgTexViewObjAllocator; +#endif // WARNING! We cannot use ITextureView here, because ITextureView has no virtual dtor! - std::unique_ptr<TTextureViewImpl> m_pDefaultSRV; - std::unique_ptr<TTextureViewImpl> m_pDefaultRTV; - std::unique_ptr<TTextureViewImpl> m_pDefaultDSV; - std::unique_ptr<TTextureViewImpl> m_pDefaultUAV; - + /// Default SRV addressing the entire texture + std::unique_ptr<TTextureViewImpl, STDDeleter<TTextureViewImpl, TTexViewObjAllocator>> m_pDefaultSRV; + /// Default RTV addressing the most detailed mip level + std::unique_ptr<TTextureViewImpl, STDDeleter<TTextureViewImpl, TTexViewObjAllocator>> m_pDefaultRTV; + /// Default DSV addressing the most detailed mip level + std::unique_ptr<TTextureViewImpl, STDDeleter<TTextureViewImpl, TTexViewObjAllocator>> m_pDefaultDSV; + /// Default UAV addressing the entire texture + std::unique_ptr<TTextureViewImpl, STDDeleter<TTextureViewImpl, TTexViewObjAllocator>> m_pDefaultUAV; + + /// Implementation of ITexture::GetDefaultView(). ITextureView* GetDefaultView( TEXTURE_VIEW_TYPE ViewType )override { switch( ViewType ) @@ -150,8 +186,8 @@ protected: }; -template<class BaseInterface, class TTextureViewImpl> -TEXTURE_FORMAT TextureBase<BaseInterface, TTextureViewImpl> :: CorrectTextureViewFormat( TEXTURE_FORMAT Fmt, TEXTURE_VIEW_TYPE TexViewType ) +template<class BaseInterface, class TTextureViewImpl, class TTexObjAllocator, class TTexViewObjAllocator> +TEXTURE_FORMAT TextureBase<BaseInterface, TTextureViewImpl, TTexObjAllocator, TTexViewObjAllocator> :: CorrectTextureViewFormat( TEXTURE_FORMAT Fmt, TEXTURE_VIEW_TYPE TexViewType ) { // Correct texture view format for depth stencil view if( TexViewType == TEXTURE_VIEW_DEPTH_STENCIL ) @@ -203,8 +239,8 @@ TEXTURE_FORMAT TextureBase<BaseInterface, TTextureViewImpl> :: CorrectTextureVie return Fmt; } -template<class BaseInterface, class TTextureViewImpl> -void TextureBase<BaseInterface, TTextureViewImpl> :: CorrectTextureViewDesc(struct TextureViewDesc &ViewDesc) +template<class BaseInterface, class TTextureViewImpl, class TTexObjAllocator, class TTexViewObjAllocator> +void TextureBase<BaseInterface, TTextureViewImpl, TTexObjAllocator, TTexViewObjAllocator> :: CorrectTextureViewDesc(struct TextureViewDesc &ViewDesc) { #define TEX_VIEW_VALIDATION_ERROR(...) LOG_ERROR_AND_THROW( "Texture view \"", ViewDesc.Name ? ViewDesc.Name : "", "\": ", ##__VA_ARGS__ ); @@ -217,65 +253,159 @@ void TextureBase<BaseInterface, TTextureViewImpl> :: CorrectTextureViewDesc(stru if( ViewDesc.Format == TEX_FORMAT_UNKNOWN ) ViewDesc.Format = CorrectTextureViewFormat( this->m_Desc.Format, ViewDesc.ViewType ); - if( ViewDesc.TextureType == TEXTURE_TYPE_UNDEFINED ) - ViewDesc.TextureType = this->m_Desc.Type; + if( ViewDesc.TextureDim == RESOURCE_DIM_UNDEFINED ) + { + if (this->m_Desc.Type == RESOURCE_DIM_TEX_CUBE || this->m_Desc.Type == RESOURCE_DIM_TEX_CUBE_ARRAY) + { + switch (ViewDesc.ViewType) + { + case TEXTURE_VIEW_SHADER_RESOURCE: + ViewDesc.TextureDim = this->m_Desc.Type; + break; + + case TEXTURE_VIEW_RENDER_TARGET: + case TEXTURE_VIEW_DEPTH_STENCIL: + case TEXTURE_VIEW_UNORDERED_ACCESS: + ViewDesc.TextureDim = RESOURCE_DIM_TEX_2D_ARRAY; + break; + + default: UNEXPECTED("Unexpected view type") + } + } + else + { + ViewDesc.TextureDim = this->m_Desc.Type; + } + } switch( this->m_Desc.Type ) { - case TEXTURE_TYPE_1D: - if( ViewDesc.TextureType != TEXTURE_TYPE_1D ) + case RESOURCE_DIM_TEX_1D: + if( ViewDesc.TextureDim != RESOURCE_DIM_TEX_1D ) { TEX_VIEW_VALIDATION_ERROR( "Incorrect texture type for Texture 1D view: only Texture 1D is allowed" ); } break; - case TEXTURE_TYPE_1D_ARRAY: - if( ViewDesc.TextureType != TEXTURE_TYPE_1D_ARRAY && - ViewDesc.TextureType != TEXTURE_TYPE_1D ) + case RESOURCE_DIM_TEX_1D_ARRAY: + if( ViewDesc.TextureDim != RESOURCE_DIM_TEX_1D_ARRAY && + ViewDesc.TextureDim != RESOURCE_DIM_TEX_1D ) { TEX_VIEW_VALIDATION_ERROR( "Incorrect view type for Texture 1D Array: only Texture 1D or Texture 1D Array are allowed" ); } break; - case TEXTURE_TYPE_2D: - if(ViewDesc.TextureType != TEXTURE_TYPE_2D ) + case RESOURCE_DIM_TEX_2D: + if(ViewDesc.TextureDim != RESOURCE_DIM_TEX_2D ) { TEX_VIEW_VALIDATION_ERROR( "Incorrect texture type for Texture 2D view: only Texture 2D is allowed" ); } break; - case TEXTURE_TYPE_2D_ARRAY: - if( ViewDesc.TextureType != TEXTURE_TYPE_2D_ARRAY && - ViewDesc.TextureType != TEXTURE_TYPE_2D ) + case RESOURCE_DIM_TEX_2D_ARRAY: + if( ViewDesc.TextureDim != RESOURCE_DIM_TEX_2D_ARRAY && + ViewDesc.TextureDim != RESOURCE_DIM_TEX_2D ) { TEX_VIEW_VALIDATION_ERROR( "Incorrect texture type for Texture 2D Array view: only Texture 2D or Texture 2D Array are allowed" ); } break; - case TEXTURE_TYPE_3D: - if( ViewDesc.TextureType != TEXTURE_TYPE_3D ) + case RESOURCE_DIM_TEX_3D: + if( ViewDesc.TextureDim != RESOURCE_DIM_TEX_3D ) { TEX_VIEW_VALIDATION_ERROR( "Incorrect texture type for Texture 3D view: only Texture 3D is allowed" ); } break; + case RESOURCE_DIM_TEX_CUBE: + if(ViewDesc.ViewType == TEXTURE_VIEW_SHADER_RESOURCE) + { + if(ViewDesc.TextureDim != RESOURCE_DIM_TEX_2D && + ViewDesc.TextureDim != RESOURCE_DIM_TEX_2D_ARRAY && + ViewDesc.TextureDim != RESOURCE_DIM_TEX_CUBE) + { + TEX_VIEW_VALIDATION_ERROR( "Incorrect texture type for Texture cube SRV: Texture 2D, Texture 2D array or Texture Cube is allowed" ); + } + } + else + { + if(ViewDesc.TextureDim != RESOURCE_DIM_TEX_2D && + ViewDesc.TextureDim != RESOURCE_DIM_TEX_2D_ARRAY) + { + TEX_VIEW_VALIDATION_ERROR( "Incorrect texture type for Texture cube non-shader resource view: Texture 2D or Texture 2D array is allowed" ); + } + } + break; + + case RESOURCE_DIM_TEX_CUBE_ARRAY: + if(ViewDesc.ViewType == TEXTURE_VIEW_SHADER_RESOURCE) + { + if(ViewDesc.TextureDim != RESOURCE_DIM_TEX_2D && + ViewDesc.TextureDim != RESOURCE_DIM_TEX_2D_ARRAY && + ViewDesc.TextureDim != RESOURCE_DIM_TEX_CUBE && + ViewDesc.TextureDim != RESOURCE_DIM_TEX_CUBE_ARRAY) + { + TEX_VIEW_VALIDATION_ERROR( "Incorrect texture type for Texture cube array SRV: Texture 2D, Texture 2D array, Texture Cube or Texture Cube Array is allowed" ); + } + } + else + { + if(ViewDesc.TextureDim != RESOURCE_DIM_TEX_2D && + ViewDesc.TextureDim != RESOURCE_DIM_TEX_2D_ARRAY) + { + TEX_VIEW_VALIDATION_ERROR( "Incorrect texture type for Texture cube array non-shader resource view: Texture 2D or Texture 2D array is allowed" ); + } + } + break; + default: UNEXPECTED( "Unexpected texture type" ); break; } - if( ViewDesc.TextureType == TEXTURE_TYPE_1D_ARRAY || - ViewDesc.TextureType == TEXTURE_TYPE_2D_ARRAY ) + if ( ViewDesc.TextureDim == RESOURCE_DIM_TEX_CUBE ) + { + VERIFY(ViewDesc.ViewType == TEXTURE_VIEW_SHADER_RESOURCE, "Unexpected view type: SRV is expected"); + if(ViewDesc.NumArraySlices != 6 && ViewDesc.NumArraySlices != 0) + TEX_VIEW_VALIDATION_ERROR( "Texture cube SRV is expected to have 6 array slices, while ", ViewDesc.NumArraySlices, " is provided" ); + if(ViewDesc.FirstArraySlice != 0) + TEX_VIEW_VALIDATION_ERROR( "First slice (", ViewDesc.FirstArraySlice, ") must be 0 for non-array texture cube SRV" ); + } + if ( ViewDesc.TextureDim == RESOURCE_DIM_TEX_CUBE_ARRAY ) + { + VERIFY(ViewDesc.ViewType == TEXTURE_VIEW_SHADER_RESOURCE, "Unexpected view type: SRV is expected"); + if((ViewDesc.NumArraySlices % 6) != 0) + TEX_VIEW_VALIDATION_ERROR( "Number of slices in texture cube array SRV is expected to be multiple of 6. ", ViewDesc.NumArraySlices, " slices provided." ); + } + + if (ViewDesc.TextureDim == RESOURCE_DIM_TEX_1D || + ViewDesc.TextureDim == RESOURCE_DIM_TEX_2D) + { + if(ViewDesc.FirstArraySlice != 0) + TEX_VIEW_VALIDATION_ERROR( "First slice (", ViewDesc.FirstArraySlice, ") must be 0 for non-array texture 1D/2D views" ); + + if(ViewDesc.NumArraySlices > 1) + TEX_VIEW_VALIDATION_ERROR( "Number of slices in the view (", ViewDesc.NumArraySlices, ") must be 1 (or 0) for non-array texture 1D/2D views" ); + } + else if( ViewDesc.TextureDim == RESOURCE_DIM_TEX_1D_ARRAY || + ViewDesc.TextureDim == RESOURCE_DIM_TEX_2D_ARRAY || + ViewDesc.TextureDim == RESOURCE_DIM_TEX_CUBE || + ViewDesc.TextureDim == RESOURCE_DIM_TEX_CUBE_ARRAY ) { if( ViewDesc.FirstArraySlice + ViewDesc.NumArraySlices > this->m_Desc.ArraySize ) TEX_VIEW_VALIDATION_ERROR( "First slice (", ViewDesc.FirstArraySlice, ") and number of slices in the view (", ViewDesc.NumArraySlices, ") specify more slices than target texture has (", this->m_Desc.ArraySize, ")" ); } - else if( ViewDesc.TextureType == TEXTURE_TYPE_3D ) + else if( ViewDesc.TextureDim == RESOURCE_DIM_TEX_3D ) { auto MipDepth = this->m_Desc.Depth >> ViewDesc.MostDetailedMip; if( ViewDesc.FirstDepthSlice + ViewDesc.NumDepthSlices > MipDepth ) TEX_VIEW_VALIDATION_ERROR( "First slice (", ViewDesc.FirstDepthSlice, ") and number of slices in the view (", ViewDesc.NumDepthSlices, ") specify more slices than target 3D texture mip level has (", MipDepth, ")" ); } + else + { + UNEXPECTED("Unexpected texture dimension") + } + #undef TEX_VIEW_VALIDATION_ERROR if( ViewDesc.NumMipLevels == 0 ) @@ -288,10 +418,12 @@ void TextureBase<BaseInterface, TTextureViewImpl> :: CorrectTextureViewDesc(stru if( ViewDesc.NumArraySlices == 0 ) { - if( ViewDesc.TextureType == TEXTURE_TYPE_1D_ARRAY || - ViewDesc.TextureType == TEXTURE_TYPE_2D_ARRAY ) + if( ViewDesc.TextureDim == RESOURCE_DIM_TEX_1D_ARRAY || + ViewDesc.TextureDim == RESOURCE_DIM_TEX_2D_ARRAY || + ViewDesc.TextureDim == RESOURCE_DIM_TEX_CUBE || + ViewDesc.TextureDim == RESOURCE_DIM_TEX_CUBE_ARRAY ) ViewDesc.NumArraySlices = this->m_Desc.ArraySize - ViewDesc.FirstArraySlice; - else if( ViewDesc.TextureType == TEXTURE_TYPE_3D ) + else if( ViewDesc.TextureDim == RESOURCE_DIM_TEX_3D ) { auto MipDepth = this->m_Desc.Depth >> ViewDesc.MostDetailedMip; ViewDesc.NumDepthSlices = MipDepth - ViewDesc.FirstDepthSlice; @@ -311,8 +443,8 @@ void TextureBase<BaseInterface, TTextureViewImpl> :: CorrectTextureViewDesc(stru } } -template<class BaseInterface, class TTextureViewImpl> -void TextureBase<BaseInterface, TTextureViewImpl> :: CreateDefaultViews() +template<class BaseInterface, class TTextureViewImpl, class TTexObjAllocator, class TTexViewObjAllocator> +void TextureBase<BaseInterface, TTextureViewImpl, TTexObjAllocator, TTexViewObjAllocator> :: CreateDefaultViews() { if(this->m_Desc.BindFlags & BIND_SHADER_RESOURCE ) { @@ -357,14 +489,14 @@ void TextureBase<BaseInterface, TTextureViewImpl> :: CreateDefaultViews() } -template<class BaseInterface, class TTextureViewImpl> -void TextureBase<BaseInterface, TTextureViewImpl> :: UpdateData( IDeviceContext *pContext, Uint32 MipLevel, Uint32 Slice, const Box &DstBox, const TextureSubResData &SubresData ) +template<class BaseInterface, class TTextureViewImpl, class TTexObjAllocator, class TTexViewObjAllocator> +void TextureBase<BaseInterface, TTextureViewImpl, TTexObjAllocator, TTexViewObjAllocator> :: UpdateData( IDeviceContext *pContext, Uint32 MipLevel, Uint32 Slice, const Box &DstBox, const TextureSubResData &SubresData ) { ValidateUpdateDataParams( this->m_Desc, MipLevel, Slice, DstBox, SubresData ); } -template<class BaseInterface, class TTextureViewImpl> -void TextureBase<BaseInterface, TTextureViewImpl> :: CopyData( IDeviceContext *pContext, +template<class BaseInterface, class TTextureViewImpl, class TTexObjAllocator, class TTexViewObjAllocator> +void TextureBase<BaseInterface, TTextureViewImpl, TTexObjAllocator, TTexViewObjAllocator> :: CopyData( IDeviceContext *pContext, ITexture *pSrcTexture, Uint32 SrcMipLevel, Uint32 SrcSlice, @@ -381,13 +513,13 @@ void TextureBase<BaseInterface, TTextureViewImpl> :: CopyData( IDeviceContext *p this->GetDesc(), DstMipLevel, DstSlice, DstX, DstY, DstZ ); } -template<class BaseInterface, class TTextureViewImpl> -void TextureBase<BaseInterface, TTextureViewImpl> :: Map( IDeviceContext *pContext, MAP_TYPE MapType, Uint32 MapFlags, PVoid &pMappedData ) +template<class BaseInterface, class TTextureViewImpl, class TTexObjAllocator, class TTexViewObjAllocator> +void TextureBase<BaseInterface, TTextureViewImpl, TTexObjAllocator, TTexViewObjAllocator> :: Map( IDeviceContext *pContext, MAP_TYPE MapType, Uint32 MapFlags, PVoid &pMappedData ) { } -template<class BaseInterface, class TTextureViewImpl> -void TextureBase<BaseInterface, TTextureViewImpl> :: Unmap( IDeviceContext *pContext ) +template<class BaseInterface, class TTextureViewImpl, class TTexObjAllocator, class TTexViewObjAllocator> +void TextureBase<BaseInterface, TTextureViewImpl, TTexObjAllocator, TTexViewObjAllocator> :: Unmap( IDeviceContext *pContext, MAP_TYPE MapType ) { } diff --git a/Graphics/GraphicsEngine/include/TextureViewBase.h b/Graphics/GraphicsEngine/include/TextureViewBase.h index af2c93d8..92dbb647 100644 --- a/Graphics/GraphicsEngine/include/TextureViewBase.h +++ b/Graphics/GraphicsEngine/include/TextureViewBase.h @@ -1,4 +1,4 @@ -/* Copyright 2015 Egor Yusov +/* Copyright 2015-2016 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,21 +37,31 @@ namespace Diligent /// Template class implementing base functionality for a texture view interface /// \tparam BaseInterface - base interface that this class will inheret -/// (Diligent::ITextureViewD3D11 or Diligent::ITextureViewGL). -template<class BaseInterface = ITextureView> -class TextureViewBase : public DeviceObjectBase<BaseInterface, TextureViewDesc> +/// (Diligent::ITextureViewD3D11, Diligent::ITextureViewD3D12 or Diligent::ITextureViewGL). +/// \taparam TexViewObjAllocator - type of the allocator that is used to allocate memory for the texture view object instances +template<class BaseInterface, class TexViewObjAllocator> +class TextureViewBase : public DeviceObjectBase<BaseInterface, TextureViewDesc, TexViewObjAllocator> { public: - typedef DeviceObjectBase<BaseInterface, TextureViewDesc> TDeviceObjectBase; + typedef DeviceObjectBase<BaseInterface, TextureViewDesc, TexViewObjAllocator> TDeviceObjectBase; - TextureViewBase( IRenderDevice *pDevice, - const TextureViewDesc& ViewDesc, - class ITexture *pTexture, - bool bIsDefaultView ) : + + /// \param ObjAllocator - allocator that was used to allocate memory for this instance of the texture view object + /// \param pDevice - pointer to the render device. + /// \param ViewDesc - texture view description. + /// \param pTexture - pointer to the texture that the view is to be created for. + /// \param bIsDefaultView - flag indicating if the view is default view, and is thus + /// part of the texture object. In this case the view will attach + /// to the texture's reference counters. + TextureViewBase( TexViewObjAllocator &ObjAllocator, + IRenderDevice *pDevice, + const TextureViewDesc& ViewDesc, + class ITexture *pTexture, + bool bIsDefaultView ) : // Default views are created as part of the texture, so we cannot not keep strong // reference to the texture to avoid cyclic links. Instead, we will attach to the // reference counters of the texture. - TDeviceObjectBase( pDevice, ViewDesc, bIsDefaultView ? pTexture : nullptr ), + TDeviceObjectBase( ObjAllocator, pDevice, ViewDesc, bIsDefaultView ? pTexture : nullptr ), m_pTexture( pTexture ), // For non-default view, we will keep strong reference to texture m_spTexture(bIsDefaultView ? nullptr : pTexture) @@ -59,18 +69,21 @@ public: IMPLEMENT_QUERY_INTERFACE_IN_PLACE( IID_TextureView, TDeviceObjectBase ) - virtual void SetSampler( class ISampler *pSampler ) + /// Implementation of ITextureView::SetSampler() + virtual void SetSampler( class ISampler *pSampler )override final { VERIFY( this->m_Desc.ViewType == TEXTURE_VIEW_SHADER_RESOURCE, "Texture view \"", this->m_Desc.Name, "\": A sampler can be attached to a shader resource view only. The view type is ", GetTexViewTypeLiteralName(this->m_Desc.ViewType) ); m_pSampler = pSampler; } - virtual ISampler* GetSampler() + /// Implementation of ITextureView::GetSampler() + virtual ISampler* GetSampler()override final { return m_pSampler; } - virtual ITexture* GetTexture() + /// Implementation of ITextureView::GetTexture() + virtual ITexture* GetTexture()override final { return m_pTexture; } diff --git a/Graphics/GraphicsEngine/include/VertexDescriptionBase.h b/Graphics/GraphicsEngine/include/VertexDescriptionBase.h deleted file mode 100644 index fdab3db6..00000000 --- a/Graphics/GraphicsEngine/include/VertexDescriptionBase.h +++ /dev/null @@ -1,96 +0,0 @@ -/* Copyright 2015 Egor Yusov - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. - * - * In no event and under no legal theory, whether in tort (including negligence), - * contract, or otherwise, unless required by applicable law (such as deliberate - * and grossly negligent acts) or agreed to in writing, shall any Contributor be - * liable for any damages, including any direct, indirect, special, incidental, - * or consequential damages of any character arising as a result of this License or - * out of the use or inability to use the software (including but not limited to damages - * for loss of goodwill, work stoppage, computer failure or malfunction, or any and - * all other commercial damages or losses), even if such Contributor has been advised - * of the possibility of such damages. - */ - -#pragma once - -/// \file -/// Implementation of the Diligent::VertexDescriptionBase template class - -#include "VertexDescription.h" -#include "DeviceObjectBase.h" -#include "GraphicsUtilities.h" - -namespace Diligent -{ - -/// Template class implementing base functionality for a vertex description object - -/// \tparam BaseInterface - base interface that this class will inheret -/// (Diligent::IVertexDescriptionD3D11 or Diligent::IVertexDescriptionGL). -template<class BaseInterface = IVertexDescription> -class VertexDescriptionBase : public DeviceObjectBase<BaseInterface, LayoutDesc> -{ -public: - typedef DeviceObjectBase<BaseInterface, LayoutDesc> TDeviceObjectBase; - - /// \param pDevice - pointer to the device. - /// \param LayoutDesc - layout description. - /// \param bIsDeviceInternal - flag indicating if the vertex description is an internal device object and - /// must not keep a strong reference to the device. - VertexDescriptionBase( IRenderDevice *pDevice, const LayoutDesc &LayoutDesc, bool bIsDeviceInternal = false ) : - TDeviceObjectBase( pDevice, LayoutDesc, nullptr, bIsDeviceInternal), - m_TightStrides( MaxBufferSlots ), // The size of this array must be equal to the - // maximum number of buffer slots, because a layout - // element can refer to any input slot - m_LayoutElements( LayoutDesc.NumElements ) - { - for( size_t Elem = 0; Elem < LayoutDesc.NumElements; ++Elem ) - m_LayoutElements[Elem] = LayoutDesc.LayoutElements[Elem]; - this->m_Desc.LayoutElements = m_LayoutElements.data(); - - // Correct description and compute offsets and tight strides - for( auto It = m_LayoutElements.begin(); It != m_LayoutElements.end(); ++It ) - { - if( It->ValueType == VT_FLOAT32 || It->ValueType == VT_FLOAT16 ) - It->IsNormalized = false; // Floating point values cannot be normalized - - auto BuffSlot = It->BufferSlot; - if( BuffSlot >= m_TightStrides.size() ) - m_TightStrides.resize( BuffSlot + 1 ); - - auto &CurrStride = m_TightStrides[BuffSlot]; - if( It->RelativeOffset < CurrStride ) - { - if( It->RelativeOffset == 0 ) - It->RelativeOffset = CurrStride; - else - UNEXPECTED( "Overlapping layout elements" ); - } - - CurrStride += It->NumComponents * GetValueSize( It->ValueType ); - } - } - - IMPLEMENT_QUERY_INTERFACE_IN_PLACE( IID_VertexDescription, TDeviceObjectBase ) - - virtual const Uint32* GetTightStrides() - { - return m_TightStrides.data(); - } - -protected: - std::vector<LayoutElement> m_LayoutElements; - std::vector<Uint32> m_TightStrides; -}; - -} diff --git a/Graphics/GraphicsEngine/include/pch.h b/Graphics/GraphicsEngine/include/pch.h index c911c398..cdc2f875 100644 --- a/Graphics/GraphicsEngine/include/pch.h +++ b/Graphics/GraphicsEngine/include/pch.h @@ -1,4 +1,4 @@ -/* Copyright 2015 Egor Yusov +/* Copyright 2015-2016 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngine/interface/BlendState.h b/Graphics/GraphicsEngine/interface/BlendState.h index 3673bfae..2e14e9eb 100644 --- a/Graphics/GraphicsEngine/interface/BlendState.h +++ b/Graphics/GraphicsEngine/interface/BlendState.h @@ -1,4 +1,4 @@ -/* Copyright 2015 Egor Yusov +/* Copyright 2015-2016 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,99 +24,94 @@ #pragma once /// \file -/// Definition of the Diligent::IBlendState interface and related data structures +/// Blend state description -#include "DeviceObject.h" +#include "BasicTypes.h" namespace Diligent { -/// IBlendState interface unique identifier -// {81CFB7AC-6B9F-45FA-ACE2-CC6A9EDE4E75} -static const Diligent::INTERFACE_ID IID_BlendState = -{ 0x81cfb7ac, 0x6b9f, 0x45fa, { 0xac, 0xe2, 0xcc, 0x6a, 0x9e, 0xde, 0x4e, 0x75 } }; - - /// Blend factors /// [D3D11_BLEND]: https://msdn.microsoft.com/en-us/library/windows/desktop/ff476086(v=vs.85).aspx +/// [D3D12_BLEND]: https://msdn.microsoft.com/en-us/library/windows/desktop/dn770338(v=vs.85).aspx /// [glBlendFuncSeparate]: https://www.opengl.org/wiki/GLAPI/glBlendFuncSeparate /// This enumeration defines blend factors for alpha-blending. -/// It generatlly mirrows [D3D11_BLEND][] enumeration and is used by RenderTargetBlendDesc structure +/// It generatlly mirrors [D3D11_BLEND][] and [D3D12_BLEND][] enumerations and is used by RenderTargetBlendDesc structure /// to define source and destination blend factors for color and alpha channels. -/// \sa [D3D11_BLEND on MSDN][D3D11_BLEND], [glBlendFuncSeparate on OpenGL.org][glBlendFuncSeparate] +/// \sa [D3D11_BLEND on MSDN][D3D11_BLEND], [D3D12_BLEND on MSDN][D3D12_BLEND], [glBlendFuncSeparate on OpenGL.org][glBlendFuncSeparate] enum BLEND_FACTOR : Int32 { /// Undefined blend factor BLEND_FACTOR_UNDEFINED = 0, /// The blend factor is zero.\n - /// D3D11 counterpart: D3D11_BLEND_ZERO. OpenGL counterpart: GL_ZERO. + /// Direct3D counterpart: D3D11_BLEND_ZERO/D3D12_BLEND_ZERO. OpenGL counterpart: GL_ZERO. BLEND_FACTOR_ZERO, /// The blend factor is one.\n - /// D3D11 counterpart: D3D11_BLEND_ONE. OpenGL counterpart: GL_ONE. + /// Direct3D counterpart: D3D11_BLEND_ONE/D3D12_BLEND_ONE. OpenGL counterpart: GL_ONE. BLEND_FACTOR_ONE, /// The blend factor is RGB data from a pixel shader.\n - /// D3D11 counterpart: D3D11_BLEND_SRC_COLOR. OpenGL counterpart: GL_SRC_COLOR. + /// Direct3D counterpart: D3D11_BLEND_SRC_COLOR/D3D12_BLEND_SRC_COLOR. OpenGL counterpart: GL_SRC_COLOR. BLEND_FACTOR_SRC_COLOR, /// The blend factor is 1-RGB, where RGB is the data from a pixel shader.\n - /// D3D11 counterpart: D3D11_BLEND_INV_SRC_COLOR. OpenGL counterpart: GL_ONE_MINUS_SRC_COLOR. + /// Direct3D counterpart: D3D11_BLEND_INV_SRC_COLOR/D3D12_BLEND_INV_SRC_COLOR. OpenGL counterpart: GL_ONE_MINUS_SRC_COLOR. BLEND_FACTOR_INV_SRC_COLOR, /// The blend factor is alpha (A) data from a pixel shader.\n - /// D3D11 counterpart: D3D11_BLEND_SRC_ALPHA. OpenGL counterpart: GL_SRC_ALPHA. + /// Direct3D counterpart: D3D11_BLEND_SRC_ALPHA/D3D12_BLEND_SRC_ALPHA. OpenGL counterpart: GL_SRC_ALPHA. BLEND_FACTOR_SRC_ALPHA, /// The blend factor is 1-A, where A is alpha data from a pixel shader.\n - /// D3D11 counterpart: D3D11_BLEND_INV_SRC_ALPHA. OpenGL counterpart: GL_ONE_MINUS_SRC_ALPHA. + /// Direct3D counterpart: D3D11_BLEND_INV_SRC_ALPHA/D3D12_BLEND_INV_SRC_ALPHA. OpenGL counterpart: GL_ONE_MINUS_SRC_ALPHA. BLEND_FACTOR_INV_SRC_ALPHA, /// The blend factor is alpha (A) data from a render target.\n - /// D3D11 counterpart: D3D11_BLEND_DEST_ALPHA. OpenGL counterpart: GL_DST_ALPHA. + /// Direct3D counterpart: D3D11_BLEND_DEST_ALPHA/D3D12_BLEND_DEST_ALPHA. OpenGL counterpart: GL_DST_ALPHA. BLEND_FACTOR_DEST_ALPHA, /// The blend factor is 1-A, where A is alpha data from a render target.\n - /// D3D11 counterpart: D3D11_BLEND_INV_DEST_ALPHA. OpenGL counterpart: GL_ONE_MINUS_DST_ALPHA. + /// Direct3D counterpart: D3D11_BLEND_INV_DEST_ALPHA/D3D12_BLEND_INV_DEST_ALPHA. OpenGL counterpart: GL_ONE_MINUS_DST_ALPHA. BLEND_FACTOR_INV_DEST_ALPHA, /// The blend factor is RGB data from a render target.\n - /// D3D11 counterpart: D3D11_BLEND_DEST_COLOR. OpenGL counterpart: GL_DST_COLOR. + /// Direct3D counterpart: D3D11_BLEND_DEST_COLOR/D3D12_BLEND_DEST_COLOR. OpenGL counterpart: GL_DST_COLOR. BLEND_FACTOR_DEST_COLOR, /// The blend factor is 1-RGB, where RGB is the data from a render target.\n - /// D3D11 counterpart: D3D11_BLEND_INV_DEST_COLOR. OpenGL counterpart: GL_ONE_MINUS_DST_COLOR. + /// Direct3D counterpart: D3D11_BLEND_INV_DEST_COLOR/D3D12_BLEND_INV_DEST_COLOR. OpenGL counterpart: GL_ONE_MINUS_DST_COLOR. BLEND_FACTOR_INV_DEST_COLOR, /// The blend factor is (f,f,f,1), where f = min(As, 1-Ad), /// As is alpha data from a pixel shader, and Ad is alpha data from a render target.\n - /// D3D11 counterpart: D3D11_BLEND_SRC_ALPHA_SAT. OpenGL counterpart: GL_SRC_ALPHA_SATURATE. + /// Direct3D counterpart: D3D11_BLEND_SRC_ALPHA_SAT/D3D12_BLEND_SRC_ALPHA_SAT. OpenGL counterpart: GL_SRC_ALPHA_SATURATE. BLEND_FACTOR_SRC_ALPHA_SAT, - /// The blend factor is the constant blend factor set with IDeviceContext::SetBlendState().\n - /// D3D11 counterpart: D3D11_BLEND_BLEND_FACTOR. OpenGL counterpart: GL_CONSTANT_COLOR. + /// The blend factor is the constant blend factor set with IDeviceContext::SetBlendFactors().\n + /// Direct3D counterpart: D3D11_BLEND_BLEND_FACTOR/D3D12_BLEND_BLEND_FACTOR. OpenGL counterpart: GL_CONSTANT_COLOR. BLEND_FACTOR_BLEND_FACTOR, - /// The blend factor is one minus constant blend factor set with IDeviceContext::SetBlendState().\n - /// D3D11 counterpart: D3D11_BLEND_INV_BLEND_FACTOR. OpenGL counterpart: GL_ONE_MINUS_CONSTANT_COLOR. + /// The blend factor is one minus constant blend factor set with IDeviceContext::SetBlendFactors().\n + /// Direct3D counterpart: D3D11_BLEND_INV_BLEND_FACTOR/D3D12_BLEND_INV_BLEND_FACTOR. OpenGL counterpart: GL_ONE_MINUS_CONSTANT_COLOR. BLEND_FACTOR_INV_BLEND_FACTOR, /// The blend factor is the second RGB data output from a pixel shader.\n - /// D3D11 counterpart: D3D11_BLEND_SRC1_COLOR. OpenGL counterpart: GL_SRC1_COLOR. + /// Direct3D counterpart: D3D11_BLEND_SRC1_COLOR/D3D12_BLEND_SRC1_COLOR. OpenGL counterpart: GL_SRC1_COLOR. BLEND_FACTOR_SRC1_COLOR, /// The blend factor is 1-RGB, where RGB is the second RGB data output from a pixel shader.\n - /// D3D11 counterpart: D3D11_BLEND_INV_SRC1_COLOR. OpenGL counterpart: GL_ONE_MINUS_SRC1_COLOR. + /// Direct3D counterpart: D3D11_BLEND_INV_SRC1_COLOR/D3D12_BLEND_INV_SRC1_COLOR. OpenGL counterpart: GL_ONE_MINUS_SRC1_COLOR. BLEND_FACTOR_INV_SRC1_COLOR, /// The blend factor is the second alpha (A) data output from a pixel shader.\n - /// D3D11 counterpart: D3D11_BLEND_SRC1_ALPHA. OpenGL counterpart: GL_SRC1_ALPHA. + /// Direct3D counterpart: D3D11_BLEND_SRC1_ALPHA/D3D12_BLEND_SRC1_ALPHA. OpenGL counterpart: GL_SRC1_ALPHA. BLEND_FACTOR_SRC1_ALPHA, /// The blend factor is 1-A, where A is the second alpha data output from a pixel shader.\n - /// D3D11 counterpart: D3D11_BLEND_INV_SRC1_ALPHA. OpenGL counterpart: GL_ONE_MINUS_SRC1_ALPHA. + /// Direct3D counterpart: D3D11_BLEND_INV_SRC1_ALPHA/D3D12_BLEND_INV_SRC1_ALPHA. OpenGL counterpart: GL_ONE_MINUS_SRC1_ALPHA. BLEND_FACTOR_INV_SRC1_ALPHA, /// Helper value that stores the total number of blend factors in the enumeration. @@ -126,34 +121,35 @@ enum BLEND_FACTOR : Int32 /// Blending operation /// [D3D11_BLEND_OP]: https://msdn.microsoft.com/en-us/library/windows/desktop/ff476088(v=vs.85).aspx +/// [D3D12_BLEND_OP]: https://msdn.microsoft.com/en-us/library/windows/desktop/dn770340(v=vs.85).aspx /// [glBlendEquationSeparate]: https://www.opengl.org/wiki/GLAPI/glBlendEquationSeparate -/// This enumeration describes blending operation for RGB or Alpha channels and generally mirrows -/// [D3D11_BLEND_OP][] enum. It is used by RenderTargetBlendDesc structure to define RGB and Alpha +/// This enumeration describes blending operation for RGB or Alpha channels and generally mirrors +/// [D3D11_BLEND_OP][] and [D3D12_BLEND_OP][] enums. It is used by RenderTargetBlendDesc structure to define RGB and Alpha /// blending operations -/// \sa [D3D11_BLEND_OP on MSDN][D3D11_BLEND_OP], [glBlendEquationSeparate on OpenGL.org][glBlendEquationSeparate] +/// \sa [D3D11_BLEND_OP on MSDN][D3D11_BLEND_OP], [D3D12_BLEND_OP on MSDN][D3D12_BLEND_OP], [glBlendEquationSeparate on OpenGL.org][glBlendEquationSeparate] enum BLEND_OPERATION : Int32 { /// Undefined blend operation BLEND_OPERATION_UNDEFINED = 0, /// Add source and destination color components.\n - /// D3D11 counterpart: D3D11_BLEND_OP_ADD. OpenGL counterpart: GL_FUNC_ADD. + /// Direct3D counterpart: D3D11_BLEND_OP_ADD/D3D12_BLEND_OP_ADD. OpenGL counterpart: GL_FUNC_ADD. BLEND_OPERATION_ADD, /// Subtract destination color components from source color components.\n - /// D3D11 counterpart: D3D11_BLEND_OP_SUBTRACT. OpenGL counterpart: GL_FUNC_SUBTRACT. + /// Direct3D counterpart: D3D11_BLEND_OP_SUBTRACT/D3D12_BLEND_OP_SUBTRACT. OpenGL counterpart: GL_FUNC_SUBTRACT. BLEND_OPERATION_SUBTRACT, /// Subtract source color components from destination color components.\n - /// D3D11 counterpart: D3D11_BLEND_OP_REV_SUBTRACT. OpenGL counterpart: GL_FUNC_REVERSE_SUBTRACT. + /// Direct3D counterpart: D3D11_BLEND_OP_REV_SUBTRACT/D3D12_BLEND_OP_REV_SUBTRACT. OpenGL counterpart: GL_FUNC_REVERSE_SUBTRACT. BLEND_OPERATION_REV_SUBTRACT, /// Compute the minimum of source and destination color components.\n - /// D3D11 counterpart: D3D11_BLEND_OP_MIN. OpenGL counterpart: GL_MIN. + /// Direct3D counterpart: D3D11_BLEND_OP_MIN/D3D12_BLEND_OP_MIN. OpenGL counterpart: GL_MIN. BLEND_OPERATION_MIN, /// Compute the maximum of source and destination color components.\n - /// D3D11 counterpart: D3D11_BLEND_OP_MAX. OpenGL counterpart: GL_MAX. + /// Direct3D counterpart: D3D11_BLEND_OP_MAX/D3D12_BLEND_OP_MAX. OpenGL counterpart: GL_MAX. BLEND_OPERATION_MAX, /// Helper value that stores the total number of blend operations in the enumeration. @@ -182,6 +178,84 @@ enum COLOR_MASK : Int32 COLOR_MASK_ALL = ( ( ( COLOR_MASK_RED | COLOR_MASK_GREEN ) | COLOR_MASK_BLUE ) | COLOR_MASK_ALPHA ) }; + +/// Logic operation + +/// [D3D12_LOGIC_OP]: https://msdn.microsoft.com/en-us/library/windows/desktop/dn770379(v=vs.85).aspx +/// This enumeration describes logic operation and generally mirrors [D3D12_LOGIC_OP][] enum. +/// It is used by RenderTargetBlendDesc structure to define logic operation. +/// Only available on D3D12 engine +/// \sa [D3D12_LOGIC_OP on MSDN][D3D12_LOGIC_OP] +enum LOGIC_OPERATION +{ + /// Clear the render target.\n + /// Direct3D12 counterpart: D3D12_LOGIC_OP_CLEAR. + LOGIC_OP_CLEAR = 0, + + /// Set the render target.\n + /// Direct3D12 counterpart: D3D12_LOGIC_OP_SET. + LOGIC_OP_SET, + + /// Copy the render target.\n + /// Direct3D12 counterpart: D3D12_LOGIC_OP_COPY. + LOGIC_OP_COPY, + + /// Perform an inverted-copy of the render target.\n + /// Direct3D12 counterpart: D3D12_LOGIC_OP_COPY_INVERTED. + LOGIC_OP_COPY_INVERTED, + + /// No operation is performed on the render target.\n + /// Direct3D12 counterpart: D3D12_LOGIC_OP_NOOP. + LOGIC_OP_NOOP, + + /// Invert the render target.\n + /// Direct3D12 counterpart: D3D12_LOGIC_OP_INVERT. + LOGIC_OP_INVERT, + + /// Perform a logical AND operation on the render target.\n + /// Direct3D12 counterpart: D3D12_LOGIC_OP_AND. + LOGIC_OP_AND, + + /// Perform a logical NAND operation on the render target.\n + /// Direct3D12 counterpart: D3D12_LOGIC_OP_NAND. + LOGIC_OP_NAND, + + /// Perform a logical OR operation on the render target.\n + /// Direct3D12 counterpart: D3D12_LOGIC_OP_OR. + LOGIC_OP_OR, + + /// Perform a logical NOR operation on the render target.\n + /// Direct3D12 counterpart: D3D12_LOGIC_OP_NOR. + LOGIC_OP_NOR, + + /// Perform a logical XOR operation on the render target.\n + /// Direct3D12 counterpart: D3D12_LOGIC_OP_XOR. + LOGIC_OP_XOR, + + /// Perform a logical equal operation on the render target.\n + /// Direct3D12 counterpart: D3D12_LOGIC_OP_EQUIV. + LOGIC_OP_EQUIV, + + /// Perform a logical AND and reverse operation on the render target.\n + /// Direct3D12 counterpart: D3D12_LOGIC_OP_AND_REVERSE. + LOGIC_OP_AND_REVERSE, + + /// Perform a logical AND and invert operation on the render target.\n + /// Direct3D12 counterpart: D3D12_LOGIC_OP_AND_INVERTED. + LOGIC_OP_AND_INVERTED, + + /// Perform a logical OR and reverse operation on the render target.\n + /// Direct3D12 counterpart: D3D12_LOGIC_OP_OR_REVERSE. + LOGIC_OP_OR_REVERSE, + + /// Perform a logical OR and invert operation on the render target.\n + /// Direct3D12 counterpart: D3D12_LOGIC_OP_OR_INVERTED. + LOGIC_OP_OR_INVERTED, + + /// Helper value that stores the total number of logical operations in the enumeration. + LOGIC_OP_NUM_OPERATIONS +}; + /// Describes a blend state for a single render target /// This structure is used by BlendStateDesc to describe @@ -191,6 +265,9 @@ struct RenderTargetBlendDesc /// Enable or disable blending for this render target. Bool BlendEnable; + /// Enable or disable a logical operation for this render target. + Bool LogicOperationEnable; + /// Specifies the blend factor to apply to the RGB value output from the pixel shader BLEND_FACTOR SrcBlend; @@ -213,6 +290,9 @@ struct RenderTargetBlendDesc /// after applying the SrcBlendAlpha and DestBlendAlpha factors. BLEND_OPERATION BlendOpAlpha; + /// Defines logical operation for the render target. + LOGIC_OPERATION LogicOp; + /// Render target write mask Uint32 RenderTargetWriteMask; @@ -221,21 +301,25 @@ struct RenderTargetBlendDesc /// Member | Default value /// ----------------------|-------------- /// BlendEnable | False - /// SrcBlend | BLEND_FACTOR_ONE - /// DestBlend | BLEND_FACTOR_ZERO - /// BlendOp | BLEND_OPERATION_ADD - /// SrcBlendAlpha | BLEND_FACTOR_ONE - /// DestBlendAlpha | BLEND_FACTOR_ZERO - /// BlendOpAlpha | BLEND_OPERATION_ADD - /// RenderTargetWriteMask | COLOR_MASK_ALL + /// LogicOperationEnable | False + /// SrcBlend | Diligent::BLEND_FACTOR_ONE + /// DestBlend | Diligent::BLEND_FACTOR_ZERO + /// BlendOp | Diligent::BLEND_OPERATION_ADD + /// SrcBlendAlpha | Diligent::BLEND_FACTOR_ONE + /// DestBlendAlpha | Diligent::BLEND_FACTOR_ZERO + /// BlendOpAlpha | Diligent::BLEND_OPERATION_ADD + /// LogicOp | Diligent::LOGIC_OP_NOOP + /// RenderTargetWriteMask | Diligent::COLOR_MASK_ALL RenderTargetBlendDesc() : BlendEnable ( False ), + LogicOperationEnable(False), SrcBlend ( BLEND_FACTOR_ONE ), DestBlend ( BLEND_FACTOR_ZERO ), BlendOp ( BLEND_OPERATION_ADD ), SrcBlendAlpha ( BLEND_FACTOR_ONE ), DestBlendAlpha ( BLEND_FACTOR_ZERO ), BlendOpAlpha ( BLEND_OPERATION_ADD ), + LogicOp ( LOGIC_OP_NOOP ), RenderTargetWriteMask( COLOR_MASK_ALL ) {} @@ -249,21 +333,22 @@ struct RenderTargetBlendDesc bool operator == (const RenderTargetBlendDesc& rhs)const { return BlendEnable == rhs.BlendEnable && + LogicOperationEnable == rhs.LogicOperationEnable && SrcBlend == rhs.SrcBlend && DestBlend == rhs.DestBlend && BlendOp == rhs.BlendOp && SrcBlendAlpha == rhs.SrcBlendAlpha && DestBlendAlpha == rhs.DestBlendAlpha && BlendOpAlpha == rhs.BlendOpAlpha && + LogicOp == rhs.LogicOp && RenderTargetWriteMask == rhs.RenderTargetWriteMask; } }; /// Blend state description -/// This structure describes the blend state which is used in a call to -/// IRenderDevice::CreateBlendState() to create a blend state object -struct BlendStateDesc : DeviceObjectAttribs +/// This structure describes the blend state and is part of the GraphicsPipelineDesc. +struct BlendStateDesc { /// Specifies whether to use alpha-to-coverage as a multisampling technique /// when setting a pixel to a render target. Default value: False. @@ -305,8 +390,6 @@ struct BlendStateDesc : DeviceObjectAttribs /// but differ in render target other than 0, the operator will return False /// even though the two blend states created from these structures will be identical. /// - False otherwise - /// \remarks - /// The operator ignores DeviceObjectAttribs::Name field as it does not affect the blend state. bool operator == (const BlendStateDesc& RHS)const { bool bRTsEqual = true; @@ -318,27 +401,9 @@ struct BlendStateDesc : DeviceObjectAttribs } return bRTsEqual && - // Name is primarily used for debug purposes and does not affect the state. - // It is ignored in comparison operation. - // strcmp(Name, RHS.Name) == 0 && AlphaToCoverageEnable == RHS.AlphaToCoverageEnable && IndependentBlendEnable== RHS.IndependentBlendEnable; } }; -/// Blend state interface - -/// The interface holds the blending state that can be bound to the pipeline by a call -/// to IDeviceContext::SetBlendState(). To create a blend state, call -/// IRenderDevice::CreateBlendState(). -class IBlendState : public IDeviceObject -{ -public: - /// Queries the specific interface, see IObject::QueryInterface() for details. - virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface ) = 0; - - /// Returns the blend state description used to create the object - virtual const BlendStateDesc& GetDesc()const = 0; -}; - } diff --git a/Graphics/GraphicsEngine/interface/Buffer.h b/Graphics/GraphicsEngine/interface/Buffer.h index 45dc21bc..847a04c1 100644 --- a/Graphics/GraphicsEngine/interface/Buffer.h +++ b/Graphics/GraphicsEngine/interface/Buffer.h @@ -1,4 +1,4 @@ -/* Copyright 2015 Egor Yusov +/* Copyright 2015-2016 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -129,9 +129,9 @@ struct BufferDesc : DeviceObjectAttribs /// --------------------|-------------- /// uiSizeInBytes | 0 /// BindFlags | 0 - /// Usage | USAGE_DEFAULT + /// Usage | Diligent::USAGE_DEFAULT /// CPUAccessFlags | 0 - /// Mode | BUFFER_MODE_UNDEFINED + /// Mode | Diligent::BUFFER_MODE_UNDEFINED /// ElementByteStride | 0 /// Members of BufferDesc::Format are initialized with default values by BufferFormat::BufferFormat() BufferDesc() : @@ -148,7 +148,7 @@ struct BufferDesc : DeviceObjectAttribs struct BufferData { /// Pointer to the data - PVoid pData; + const void* pData; /// Data size, in bytes Uint32 DataSize; @@ -206,7 +206,9 @@ public: /// Unmaps the previously mapped buffer /// \param [in] pContext - Pointer to the device context interface to be used to perform the operation. - virtual void Unmap( IDeviceContext *pContext ) = 0; + /// \param [in] MapType - Type of the map operation. This parameter must match to the type that was + /// provided to the Map() method. + virtual void Unmap( IDeviceContext *pContext, MAP_TYPE MapType ) = 0; /// Creates a new buffer view diff --git a/Graphics/GraphicsEngine/interface/BufferView.h b/Graphics/GraphicsEngine/interface/BufferView.h index 93d52887..f817b3e6 100644 --- a/Graphics/GraphicsEngine/interface/BufferView.h +++ b/Graphics/GraphicsEngine/interface/BufferView.h @@ -1,4 +1,4 @@ -/* Copyright 2015 Egor Yusov +/* Copyright 2015-2016 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -53,7 +53,7 @@ struct BufferViewDesc : DeviceObjectAttribs /// Default values: /// Member | Default value /// --------------------|-------------- - /// ViewType | BUFFER_VIEW_UNDEFINED + /// ViewType | Diligent::BUFFER_VIEW_UNDEFINED /// ByteOffset | 0 /// ByteWidth | 0 BufferViewDesc() : diff --git a/Graphics/GraphicsEngine/interface/CommandList.h b/Graphics/GraphicsEngine/interface/CommandList.h new file mode 100644 index 00000000..e6939c3d --- /dev/null +++ b/Graphics/GraphicsEngine/interface/CommandList.h @@ -0,0 +1,49 @@ +/* Copyright 2015-2016 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +/// \file +/// Defines Diligent::IBuffer interface and related data structures + +#include "DeviceObject.h" + +namespace Diligent +{ + +// {C38C68F2-8A8C-4ED5-B7EE-69126E75DCD8} +static const Diligent::INTERFACE_ID IID_CommandList = +{ 0xc38c68f2, 0x8a8c, 0x4ed5, { 0xb7, 0xee, 0x69, 0x12, 0x6e, 0x75, 0xdc, 0xd8 } }; + +/// Command list interface + +/// Command list has no methods. When command list recording is finished, it is executed by +/// IDeviceContext::ExecuteCommandList(). +class ICommandList : public IDeviceObject +{ +public: + + +}; + +} diff --git a/Graphics/GraphicsEngine/interface/Constants.h b/Graphics/GraphicsEngine/interface/Constants.h index 50d9d427..7c1505bb 100644 --- a/Graphics/GraphicsEngine/interface/Constants.h +++ b/Graphics/GraphicsEngine/interface/Constants.h @@ -1,4 +1,4 @@ -/* Copyright 2015 Egor Yusov +/* Copyright 2015-2016 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngine/interface/DepthStencilState.h b/Graphics/GraphicsEngine/interface/DepthStencilState.h index 75347935..de796255 100644 --- a/Graphics/GraphicsEngine/interface/DepthStencilState.h +++ b/Graphics/GraphicsEngine/interface/DepthStencilState.h @@ -1,4 +1,4 @@ -/* Copyright 2015 Egor Yusov +/* Copyright 2015-2016 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,22 +24,19 @@ #pragma once /// \file -/// Definition of the Diligent::IDepthStencilState interface and related data structures +/// Definition of data types that describe depth-stencil state -#include "DeviceObject.h" +#include "BasicTypes.h" namespace Diligent { -// {51C3A67F-FADD-411A-BA36-BDE9EE29722B} -static const Diligent::INTERFACE_ID IID_DepthStencilState = -{ 0x51c3a67f, 0xfadd, 0x411a, { 0xba, 0x36, 0xbd, 0xe9, 0xee, 0x29, 0x72, 0x2b } }; - /// Stencil operation /// [D3D11_STENCIL_OP]: https://msdn.microsoft.com/en-us/library/windows/desktop/ff476219(v=vs.85).aspx -/// This enumeration describes the stencil operation and generally mirrows -/// [D3D11_STENCIL_OP][] enumeration. +/// [D3D12_STENCIL_OP]: https://msdn.microsoft.com/en-us/library/windows/desktop/dn770409(v=vs.85).aspx +/// This enumeration describes the stencil operation and generally mirrors +/// [D3D11_STENCIL_OP][]/[D3D12_STENCIL_OP][] enumeration. /// It is used by Diligent::StencilOpDesc structure to describe the stencil fail, depth fail /// and stencil pass operations enum STENCIL_OP : Int32 @@ -48,37 +45,37 @@ enum STENCIL_OP : Int32 STENCIL_OP_UNDEFINED = 0, /// Keep the existing stencil data.\n - /// D3D11 Counterpart: D3D11_STENCIL_OP_KEEP. OpenGL counterpart: GL_KEEP. + /// Direct3D counterpart: D3D11_STENCIL_OP_KEEP/D3D12_STENCIL_OP_KEEP. OpenGL counterpart: GL_KEEP. STENCIL_OP_KEEP = 1, /// Set the stencil data to 0.\n - /// D3D11 Counterpart: D3D11_STENCIL_OP_ZERO. OpenGL counterpart: GL_ZERO. + /// Direct3D counterpart: D3D11_STENCIL_OP_ZERO/D3D12_STENCIL_OP_ZERO. OpenGL counterpart: GL_ZERO. STENCIL_OP_ZERO = 2, - /// Set the stencil data to the reference value set by calling IDeviceContext::SetDepthStencilState().\n - /// D3D11 Counterpart: D3D11_STENCIL_OP_REPLACE. OpenGL counterpart: GL_REPLACE. + /// Set the stencil data to the reference value set by calling IDeviceContext::SetStencilRef().\n + /// Direct3D counterpart: D3D11_STENCIL_OP_REPLACE/D3D12_STENCIL_OP_REPLACE. OpenGL counterpart: GL_REPLACE. STENCIL_OP_REPLACE = 3, /// Increment the current stencil value, and clamp to the maximum representable unsigned value.\n - /// D3D11 Counterpart: D3D11_STENCIL_OP_INCR_SAT. OpenGL counterpart: GL_INCR. + /// Direct3D counterpart: D3D11_STENCIL_OP_INCR_SAT/D3D12_STENCIL_OP_INCR_SAT. OpenGL counterpart: GL_INCR. STENCIL_OP_INCR_SAT = 4, /// Decrement the current stencil value, and clamp to 0.\n - /// D3D11 Counterpart: D3D11_STENCIL_OP_DECR_SAT. OpenGL counterpart: GL_DECR. + /// Direct3D counterpart: D3D11_STENCIL_OP_DECR_SAT/D3D12_STENCIL_OP_DECR_SAT. OpenGL counterpart: GL_DECR. STENCIL_OP_DECR_SAT = 5, /// Bitwise invert the current stencil buffer value.\n - /// D3D11 Counterpart: D3D11_STENCIL_OP_INVERT. OpenGL counterpart: GL_INVERT. + /// Direct3D counterpart: D3D11_STENCIL_OP_INVERT/D3D12_STENCIL_OP_INVERT. OpenGL counterpart: GL_INVERT. STENCIL_OP_INVERT = 6, /// Increment the current stencil value, and wrap the value to zero when incrementing /// the maximum representable unsigned value. \n - /// D3D11 Counterpart: D3D11_STENCIL_OP_INCR. OpenGL counterpart: GL_INCR_WRAP. + /// Direct3D counterpart: D3D11_STENCIL_OP_INCR/D3D12_STENCIL_OP_INCR. OpenGL counterpart: GL_INCR_WRAP. STENCIL_OP_INCR_WRAP = 7, /// Decrement the current stencil value, and wrap the value to the maximum representable /// unsigned value when decrementing a value of zero.\n - /// D3D11 Counterpart: D3D11_STENCIL_OP_DECR. OpenGL counterpart: GL_DECR_WRAP. + /// Direct3D counterpart: D3D11_STENCIL_OP_DECR/D3D12_STENCIL_OP_DECR. OpenGL counterpart: GL_DECR_WRAP. STENCIL_OP_DECR_WRAP = 8, /// Helper value that stores the total number of stencil operations in the enumeration. @@ -88,7 +85,8 @@ enum STENCIL_OP : Int32 /// Describes stencil operations that are performed based on the results of depth test. /// [D3D11_DEPTH_STENCILOP_DESC]: https://msdn.microsoft.com/en-us/library/windows/desktop/ff476109(v=vs.85).aspx -/// The structure generally mirrows [D3D11_DEPTH_STENCILOP_DESC][] structure. +/// [D3D12_DEPTH_STENCILOP_DESC]: https://msdn.microsoft.com/en-us/library/windows/desktop/dn770355(v=vs.85).aspx +/// The structure generally mirrors [D3D11_DEPTH_STENCILOP_DESC][]/[D3D12_DEPTH_STENCILOP_DESC][] structure. /// It is used by Diligent::DepthStencilStateDesc structure to describe the stencil /// operations for the front and back facing polygons. struct StencilOpDesc @@ -111,10 +109,10 @@ struct StencilOpDesc /// Default values: /// Member | Default value /// --------------------|-------------- - /// StencilFailOp | STENCIL_OP_KEEP - /// StencilDepthFailOp | STENCIL_OP_KEEP - /// StencilPassOp | STENCIL_OP_KEEP - /// StencilFunc | COMPARISON_FUNC_ALWAYS + /// StencilFailOp | Diligent::STENCIL_OP_KEEP + /// StencilDepthFailOp | Diligent::STENCIL_OP_KEEP + /// StencilPassOp | Diligent::STENCIL_OP_KEEP + /// StencilFunc | Diligent::COMPARISON_FUNC_ALWAYS StencilOpDesc() : StencilFailOp ( STENCIL_OP_KEEP ), StencilDepthFailOp( STENCIL_OP_KEEP ), @@ -140,10 +138,11 @@ struct StencilOpDesc /// Depth stencil state description /// [D3D11_DEPTH_STENCIL_DESC]: https://msdn.microsoft.com/en-us/library/windows/desktop/ff476110(v=vs.85).aspx -/// This structure describes the depth stencil state which is used in a call to -/// IRenderDevice::CreateDepthStencilState() and generally mirrows [D3D11_DEPTH_STENCIL_DESC][] +/// [D3D12_DEPTH_STENCIL_DESC]: https://msdn.microsoft.com/en-us/library/windows/desktop/dn770356(v=vs.85).aspx +/// This structure describes the depth stencil state and is part of the GraphicsPipelineDesc. +/// The structure generally mirrors [D3D11_DEPTH_STENCIL_DESC][]/[D3D12_DEPTH_STENCIL_DESC][] /// structure. -struct DepthStencilStateDesc : DeviceObjectAttribs +struct DepthStencilStateDesc { /// Enable depth-stencil operations. When it is set to False, /// depth test always passes, depth writes are disabled, @@ -179,7 +178,7 @@ struct DepthStencilStateDesc : DeviceObjectAttribs /// --------------------|-------------- /// DepthEnable | True /// DepthWriteEnable | True - /// DepthFunc | COMPARISON_FUNC_LESS + /// DepthFunc | Diligent::COMPARISON_FUNC_LESS /// StencilEnable | False /// StencilReadMask | 0xFF /// StencilWriteMask | 0xFF @@ -201,15 +200,9 @@ struct DepthStencilStateDesc : DeviceObjectAttribs /// \return /// - True if all members of the two structures are equal. /// - False otherwise - /// \remarks - /// The operator ignores DeviceObjectAttribs::Name field as it does not affect - /// the depth-stencil state. bool operator == (const DepthStencilStateDesc& rhs)const { - // Name is primarily used for debug purposes and does not affect the state. - // It is ignored in comparison operation. - return // strcmp(Name, rhs.Name) == 0 && - DepthEnable == rhs.DepthEnable && + return DepthEnable == rhs.DepthEnable && DepthWriteEnable == rhs.DepthWriteEnable && DepthFunc == rhs.DepthFunc && StencilEnable == rhs.StencilEnable && @@ -220,19 +213,4 @@ struct DepthStencilStateDesc : DeviceObjectAttribs } }; -/// Depth stencil state interface - -/// The interface holds the depth-stencil state that can be bound to the pipeline by a call -/// to IDeviceContext::SetDepthStencilState(). To create a depth-stencil state, call -/// IRenderDevice::CreateDepthStencilState(). -class IDepthStencilState : public IDeviceObject -{ -public: - /// Queries the specific interface, see IObject::QueryInterface() for details - virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface ) = 0; - - /// Returns the depth stencil state description used to create the object - virtual const DepthStencilStateDesc& GetDesc()const = 0; -}; - } diff --git a/Graphics/GraphicsEngine/interface/DeviceCaps.h b/Graphics/GraphicsEngine/interface/DeviceCaps.h index 3d8284ed..4265ce04 100644 --- a/Graphics/GraphicsEngine/interface/DeviceCaps.h +++ b/Graphics/GraphicsEngine/interface/DeviceCaps.h @@ -1,4 +1,4 @@ -/* Copyright 2015 Egor Yusov +/* Copyright 2015-2016 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,7 +34,8 @@ namespace Diligent enum class DeviceType : Int32 { Undefined = 0, ///< Undefined device - DirectX, ///< DirectX device + D3D11, ///< D3D11 device + D3D12, ///< D3D12 device OpenGL, ///< OpenGL device OpenGLES ///< OpenGLES device }; @@ -77,13 +78,17 @@ namespace Diligent /// Indicates if device supports texture views bool bTextureViewSupported; + /// Indicates if device supports cubemap arrays + bool bCubemapArraysSupported; + /// Initializes the structure members with default values TextureCaps(): bTexture1DSupported( True ), bTexture1DArraySupported( True ), bTexture2DMSSupported( True ), bTexture2DMSArraySupported( True ), - bTextureViewSupported( True ) + bTextureViewSupported( True ), + bCubemapArraysSupported( True ) {} }; @@ -110,6 +115,9 @@ namespace Diligent /// Indicates if device supports wireframe fill mode Bool bWireframeFillSupported; + /// Indicates if device supports multithreaded resource creation + Bool bMultithreadedResourceCreationSupported; + /// Texture sampling capabilities. See Diligent::SamplerCaps. SamplerCaps SamCaps; @@ -123,7 +131,8 @@ namespace Diligent MinorVersion( 0 ), bSeparableProgramSupported( True ), bIndirectRenderingSupported( True ), - bWireframeFillSupported( True ) + bWireframeFillSupported( True ), + bMultithreadedResourceCreationSupported( False ) {} }; } diff --git a/Graphics/GraphicsEngine/interface/DeviceContext.h b/Graphics/GraphicsEngine/interface/DeviceContext.h index c1998091..20a0f0b4 100644 --- a/Graphics/GraphicsEngine/interface/DeviceContext.h +++ b/Graphics/GraphicsEngine/interface/DeviceContext.h @@ -1,4 +1,4 @@ -/* Copyright 2015 Egor Yusov +/* Copyright 2015-2016 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,7 +30,7 @@ #include "DeviceCaps.h" #include "Constants.h" #include "Buffer.h" -#include "VertexDescription.h" +#include "InputLayout.h" #include "Shader.h" #include "Texture.h" #include "Sampler.h" @@ -39,6 +39,8 @@ #include "BufferView.h" #include "DepthStencilState.h" #include "BlendState.h" +#include "PipelineState.h" +#include "CommandList.h" namespace Diligent { @@ -56,19 +58,19 @@ enum PRIMITIVE_TOPOLOGY : Int32 PRIMITIVE_TOPOLOGY_UNDEFINED = 0, /// Interpret the vertex data as a list of triangles.\n - /// D3D11 counterpart: D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST. OpenGL counterpart: GL_TRIANGLES. + /// D3D counterpart: D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST. OpenGL counterpart: GL_TRIANGLES. PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, /// Interpret the vertex data as a triangle strip.\n - /// D3D11 counterpart: D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP. OpenGL counterpart: GL_TRIANGLE_STRIP. + /// D3D counterpart: D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP. OpenGL counterpart: GL_TRIANGLE_STRIP. PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, /// Interpret the vertex data as a list of points.\n - /// D3D11 counterpart: D3D11_PRIMITIVE_TOPOLOGY_POINTLIST. OpenGL counterpart: GL_POINTS. + /// D3D counterpart: D3D_PRIMITIVE_TOPOLOGY_POINTLIST. OpenGL counterpart: GL_POINTS. PRIMITIVE_TOPOLOGY_POINT_LIST, /// Interpret the vertex data as a list of lines.\n - /// D3D11 counterpart: D3D11_PRIMITIVE_TOPOLOGY_LINELIST. OpenGL counterpart: GL_LINES. + /// D3D counterpart: D3D_PRIMITIVE_TOPOLOGY_LINELIST. OpenGL counterpart: GL_LINES. PRIMITIVE_TOPOLOGY_LINE_LIST, /// Helper value that stores the total number of topologies in the enumeration @@ -228,6 +230,17 @@ enum SET_VERTEX_BUFFERS_FLAGS : Int32 SET_VERTEX_BUFFERS_FLAG_RESET = 0x01 }; +/// Defines allowed flags for IDeviceContext::CommitShaderResources() function. +enum COMMIT_SHADER_RESOURCES_FLAG +{ + /// Transition resources being committed + + /// If this flag is specified when IDeviceContext::CommitShaderResources() is called, + /// the engine will transition all shader resources to the correct state. + COMMIT_SHADER_RESOURCES_FLAG_TRANSITION_RESOURCES = 0x01 +}; + + /// Describes the viewport. /// This structure is used by IDeviceContext::SetViewports(). @@ -304,25 +317,51 @@ public: /// Queries the specific interface, see IObject::QueryInterface() for details virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface ) = 0; - /// Binds shaders to the pipeline + /// Sets the pipeline state + + /// \param [in] pPipelineState - Pointer to IPipelineState interface to bind to the context. + virtual void SetPipelineState(IPipelineState *pPipelineState) = 0; + + + /// Transitions shader resources to the require states. + /// \param [in] pPipelineState - Pipeline state object that was used to create the shader resource binding. + /// \param [in] pShaderResourceBinding - Shader resource binding whose resources will be transitioned. + /// \remarks This method explicitly transitiones all resources to the correct states. + /// If this method was called, there is no need to specify Diligent::COMMIT_SHADER_RESOURCES_FLAG_TRANSITION_RESOURCES + /// when calling IDeviceContext::CommitShaderResources() + virtual void TransitionShaderResources(IPipelineState *pPipelineState, IShaderResourceBinding *pShaderResourceBinding) = 0; + + /// Commits shader resources to the device context + + /// \param [in] pShaderResourceBinding - Shader resource binding whose resources will be committed. + /// If pipeline state contains no shader resources, this parameter + /// can be null. + /// \param [in] Flags - Additional flags for the operation. See Diligent::COMMIT_SHADER_RESOURCES_FLAG + /// for a list of allowed values. + /// + /// \remarks Pipeline state object that was used to create the shader resource binding must be bound + /// to the pipeline when CommitShaderResources() is called. If no pipeline state object is bound + /// or the pipeline state object does not match shader resource binding, the method will fail.\n + /// If Diligent::COMMIT_SHADER_RESOURCES_FLAG_TRANSITION_RESOURCES flag is specified, + /// the engine will also transition all shader resources to the correct state. If the flag + /// is not specified, it is assumed that all resources are already in correct states.\n + /// Resources can be explicitly transitioned to the required states by calling + /// IDeviceContext::TransitionShaderResources() + virtual void CommitShaderResources(IShaderResourceBinding *pShaderResourceBinding, Uint32 Flags) = 0; - /// \param [in] ppShaders - Array of pointers to IShader interface. - /// \param [in] NumShadersToSet - Number of shaders to bind. - /// \remarks All shaders must be set atomically. All shaders that are not specified - /// in a call to SetShaders() will be unbound.\n - /// The device context keeps strong references to all bound shaders. - /// Thus a shader cannot be released until it is unbound from the context. - virtual void SetShaders(IShader **ppShaders, Uint32 NumShadersToSet) = 0; + /// Sets the stencil reference value - /// Binds resources for all shaders bound to the pipeline + /// \param [in] StencilRef - Stencil reference value. + virtual void SetStencilRef(Uint32 StencilRef) = 0; - /// \param [in] pResourceMapping - Pointer to the resource mapping interface. - /// \param [in] Flags - Additional flags. See Diligent::BIND_SHADER_RESOURCES_FLAGS. - /// \remarks This function is intended to be used with older OpenGL devices that - /// do not support program pipelines (OpenGL4.1-, OpenGLES3.0-).\n - /// The function should be called AFTER all the required shaders are bound to the - /// context. It should also be called for every shader combination. - virtual void BindShaderResources( IResourceMapping *pResourceMapping, Uint32 Flags ) = 0; + + /// \param [in] pBlendFactors - Array of four blend factors, one for each RGBA component. + /// Theses factors are used if the blend state uses one of the + /// Diligent::BLEND_FACTOR_BLEND_FACTOR or + /// Diligent::BLEND_FACTOR_INV_BLEND_FACTOR + /// blend factors. If nullptr is provided, + /// default blend factors array {1,1,1,1} will be used. + virtual void SetBlendFactors(const float* pBlendFactors = nullptr) = 0; /// Binds vertex buffers to the pipeline. @@ -337,7 +376,7 @@ public: /// in the vertex-buffer array. Each stride is the size (in bytes) of the /// elements that are to be used from that vertex buffer. /// If this parameter is nullptr, tight strides from the input layout - /// will be used for each buffer. See IVertexDescription::GetTightStrides(). + /// will be used for each buffer. See IPipelineState::GetTightStrides(). /// \param [in] pOffsets - Pointer to an array of offset values; one offset value for each buffer /// in the vertex-buffer array. Each offset is the number of bytes between /// the first element of a vertex buffer and the first element that will be @@ -359,14 +398,6 @@ public: /// Clears the context state. virtual void ClearState() = 0; - /// Sets vertex description - - /// \param [in] pVertexDesc - Pointer to IVertexDescription interface that describes - /// how to read data from input vertex buffers. - /// \remarks The device context keeps strong reference to the vertex description. - /// Thus a vertex description object cannot be released until it is unbound - /// from the context. - virtual void SetVertexDescription(IVertexDescription *pVertexDesc) = 0; /// Binds an index buffer to the pipeline @@ -380,42 +411,6 @@ public: virtual void SetIndexBuffer(IBuffer *pIndexBuffer, Uint32 ByteOffset) = 0; - /// Sets the depth stencil state - - /// \param [in] pDepthStencilState - Pointer to the IDepthStencilState interface holding the state - /// \param [in] StencilRef - Stencil reference value used in stencil operations. - /// See DepthStencilStateDesc. - /// \remarks The device context keeps strong reference to the bound depth-stencil state. - /// Thus a depth-stencil state object cannot be released until it is unbound - /// from the context. - virtual void SetDepthStencilState( IDepthStencilState *pDepthStencilState, Uint32 StencilRef = 0 ) = 0; - - /// Sets the rasterizer state - - /// \param [in] pRS - Pointer to the IRasterizerState interface holding the state - /// \remarks The device context keeps strong reference to the bound rasterizer state. - /// Thus a rasterizer state object cannot be released until it is unbound - /// from the context. - virtual void SetRasterizerState( IRasterizerState *pRS ) = 0; - - /// Sets the blend state - - /// \param [in] pBS - Pointer to the IBlendState interface holding the state - /// \param [in] pBlendFactors - Array of four blend factors, one for each RGBA component. - /// Theses factors are used if the blend state uses one of the - /// Diligent::BLEND_FACTOR_BLEND_FACTOR or - /// Diligent::BLEND_FACTOR_INV_BLEND_FACTOR - /// blend factors. If nullptr is provided, - /// default blend factors array {1,1,1,1} will be used. - /// \param [in] SampleMask - 32-bit sample mask that determines which samples get updated - /// in all the active render targets. A sample mask is always applied; - /// it is independent of whether multisampling is enabled, and does not - /// depend on whether an application uses multisample render targets. - /// \remarks The device context keeps strong reference to the bound blend state. - /// Thus a blend state object cannot be released until it is unbound - /// from the context. - virtual void SetBlendState( IBlendState *pBS, const float* pBlendFactors = nullptr, Uint32 SampleMask = 0xFFFFFFFF ) = 0; - /// Sets an array of viewports /// \param [in] NumViewports - Number of viewports to set. @@ -503,6 +498,17 @@ public: /// \note The render target view must be bound to the pipeline for clear operation to be performed. virtual void ClearRenderTarget( ITextureView *pView, const float *RGBA = nullptr ) = 0; + /// Finishes recording commands and generates a command list + + /// \param [out] ppCommandList - Memory location where pointer to the recorded command list will be written. + virtual void FinishCommandList(class ICommandList **ppCommandList) = 0; + + /// Executes recorded commands in a command list + + /// \param [in] pCommandList - Pointer to the command list to executre. + /// \remarks After command list is executed, it is no longer valid and should be released. + virtual void ExecuteCommandList(class ICommandList *pCommandList) = 0; + /// Flushes the command buffer virtual void Flush() = 0; }; diff --git a/Graphics/GraphicsEngine/interface/DeviceObject.h b/Graphics/GraphicsEngine/interface/DeviceObject.h index 6a3cde70..00ce8eb8 100644 --- a/Graphics/GraphicsEngine/interface/DeviceObject.h +++ b/Graphics/GraphicsEngine/interface/DeviceObject.h @@ -1,4 +1,4 @@ -/* Copyright 2015 Egor Yusov +/* Copyright 2015-2016 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngine/interface/GraphicsTypes.h b/Graphics/GraphicsEngine/interface/GraphicsTypes.h index 4f8bbcba..c59295c4 100644 --- a/Graphics/GraphicsEngine/interface/GraphicsTypes.h +++ b/Graphics/GraphicsEngine/interface/GraphicsTypes.h @@ -1,4 +1,4 @@ -/* Copyright 2015 Egor Yusov +/* Copyright 2015-2016 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -55,7 +55,7 @@ namespace Diligent /// [D3D11_BIND_FLAG]: https://msdn.microsoft.com/en-us/library/windows/desktop/ff476085(v=vs.85).aspx /// /// This enumeration describes which parts of the pipeline a resource can be bound to. - /// It generally mirrows [D3D11_BIND_FLAG][] enumeration. It is used by + /// It generally mirrors [D3D11_BIND_FLAG][] enumeration. It is used by /// - BufferDesc to describe bind flags for a buffer /// - TextureDesc to describe bind flags for a texture enum BIND_FLAGS : Int32 @@ -77,7 +77,7 @@ namespace Diligent /// Resource usage /// [D3D11_USAGE]: https://msdn.microsoft.com/en-us/library/windows/desktop/ff476259(v=vs.85).aspx - /// This enumeration describes expected resource usage. It generally mirrows [D3D11_USAGE] enumeration. + /// This enumeration describes expected resource usage. It generally mirrors [D3D11_USAGE] enumeration. /// The enumeration is used by /// - BufferDesc to describe usage for a buffer /// - TextureDesc to describe usage for a texture @@ -119,7 +119,7 @@ namespace Diligent /// [D3D11_MAP]: https://msdn.microsoft.com/en-us/library/windows/desktop/ff476181(v=vs.85).aspx /// Describes how a mapped resource will be accessed. This enumeration generally - /// mirrows [D3D11_MAP][] enumeration. It is used by + /// mirrors [D3D11_MAP][] enumeration. It is used by /// - IBuffer::Map to describe buffer mapping type /// - ITexture::Map to describe texture mapping type enum MAP_TYPE : Int32 @@ -162,22 +162,23 @@ namespace Diligent MAP_FLAG_DO_NOT_WAIT = 0x001 }; - /// Describes texture type + /// Describes resource dimension /// This enumeration is used by /// - TextureDesc to describe texture type /// - TextureViewDesc to describe texture view type - enum TEXTURE_TYPE : Int32 + enum RESOURCE_DIMENSION : Int32 { - TEXTURE_TYPE_UNDEFINED = 0, ///< Texture type undefined - TEXTURE_TYPE_1D, ///< One-dimensional texture - TEXTURE_TYPE_1D_ARRAY, ///< One-dimensional texture array - TEXTURE_TYPE_2D, ///< Two-dimensional texture - TEXTURE_TYPE_2D_ARRAY, ///< Two-dimensional texture array - TEXTURE_TYPE_3D, ///< Three-dimensional texture - TEXTURE_TYPE_CUBE, ///< Cube-map texture - TEXTURE_TYPE_CUBE_ARRAY, ///< Cube-map array texture - TEXTURE_TYPE_NUM_TYPES ///< Helper value that stores the total number of texture types in the enumeration + RESOURCE_DIM_UNDEFINED = 0, ///< Texture type undefined + RESOURCE_DIM_BUFFER, ///< Buffer + RESOURCE_DIM_TEX_1D, ///< One-dimensional texture + RESOURCE_DIM_TEX_1D_ARRAY, ///< One-dimensional texture array + RESOURCE_DIM_TEX_2D, ///< Two-dimensional texture + RESOURCE_DIM_TEX_2D_ARRAY, ///< Two-dimensional texture array + RESOURCE_DIM_TEX_3D, ///< Three-dimensional texture + RESOURCE_DIM_TEX_CUBE, ///< Cube-map texture + RESOURCE_DIM_TEX_CUBE_ARRAY, ///< Cube-map array texture + RESOURCE_DIM_NUM_DIMENSIONS ///< Helper value that stores the total number of texture types in the enumeration }; /// Texture view type @@ -232,7 +233,7 @@ namespace Diligent /// Texture formats - /// This enumeration describes available texture formats and generally mirrows DXGI_FORMAT enumeration. + /// This enumeration describes available texture formats and generally mirrors DXGI_FORMAT enumeration. /// The table below provides detailed information on each format. Most of the formats are widely supported /// by all modern APIs (DX10+, OpenGL3.3+ and OpenGLES3.0+). Specific requirements are additionally indicated. /// \sa <a href = "https://msdn.microsoft.com/en-us/library/windows/desktop/bb173059(v=vs.85).aspx">DXGI_FORMAT enumeration on MSDN</a>, @@ -783,14 +784,21 @@ namespace Diligent FILTER_TYPE_COMPARISON_POINT, ///< Comparison-point filtering FILTER_TYPE_COMPARISON_LINEAR, ///< Comparison-linear filtering FILTER_TYPE_COMPARISON_ANISOTROPIC, ///< Comparison-anisotropic filtering + FILTER_TYPE_MINIMUM_POINT, ///< Minimum-point filtering (DX12 only) + FILTER_TYPE_MINIMUM_LINEAR, ///< Minimum-linear filtering (DX12 only) + FILTER_TYPE_MINIMUM_ANISOTROPIC, ///< Minimum-anisotropic filtering (DX12 only) + FILTER_TYPE_MAXIMUM_POINT, ///< Maximum-point filtering (DX12 only) + FILTER_TYPE_MAXIMUM_LINEAR, ///< Maximum-linear filtering (DX12 only) + FILTER_TYPE_MAXIMUM_ANISOTROPIC, ///< Maximum-anisotropic filtering (DX12 only) FILTER_TYPE_NUM_FILTERS ///< Helper value that stores the total number of filter types in the enumeration }; /// Texture address mode /// [D3D11_TEXTURE_ADDRESS_MODE]: https://msdn.microsoft.com/en-us/library/windows/desktop/ff476256(v=vs.85).aspx + /// [D3D12_TEXTURE_ADDRESS_MODE]: https://msdn.microsoft.com/en-us/library/windows/desktop/dn770441(v=vs.85).aspx /// Defines a technique for resolving texture coordinates that are outside of - /// the boundaries of a texture. The enumeration generally mirrows [D3D11_TEXTURE_ADDRESS_MODE][] enumeration. + /// the boundaries of a texture. The enumeration generally mirrors [D3D11_TEXTURE_ADDRESS_MODE][]/[D3D12_TEXTURE_ADDRESS_MODE][] enumeration. /// It is used by SamplerDesc structure to define the address mode for U,V and W texture coordinates. enum TEXTURE_ADDRESS_MODE : Int32 { @@ -798,27 +806,27 @@ namespace Diligent TEXTURE_ADDRESS_UNKNOWN = 0, /// Tile the texture at every integer junction. \n - /// D3D11 Counterpart: D3D11_TEXTURE_ADDRESS_WRAP. OpenGL counterpart: GL_REPEAT + /// Direct3D Counterpart: D3D11_TEXTURE_ADDRESS_WRAP/D3D12_TEXTURE_ADDRESS_MODE_WRAP. OpenGL counterpart: GL_REPEAT TEXTURE_ADDRESS_WRAP = 1, /// Flip the texture at every integer junction. \n - /// D3D11 Counterpart: D3D11_TEXTURE_ADDRESS_MIRROR. OpenGL counterpart: GL_MIRRORED_REPEAT + /// Direct3D Counterpart: D3D11_TEXTURE_ADDRESS_MIRROR/D3D12_TEXTURE_ADDRESS_MODE_MIRROR. OpenGL counterpart: GL_MIRRORED_REPEAT TEXTURE_ADDRESS_MIRROR = 2, /// Texture coordinates outside the range [0.0, 1.0] are set to the /// texture color at 0.0 or 1.0, respectively. \n - /// D3D11 Counterpart: D3D11_TEXTURE_ADDRESS_CLAMP. OpenGL counterpart: GL_CLAMP_TO_EDGE + /// Direct3D Counterpart: D3D11_TEXTURE_ADDRESS_CLAMP/D3D12_TEXTURE_ADDRESS_MODE_CLAMP. OpenGL counterpart: GL_CLAMP_TO_EDGE TEXTURE_ADDRESS_CLAMP = 3, /// Texture coordinates outside the range [0.0, 1.0] are set to the border color specified /// specified in SamplerDesc structure. \n - /// D3D11 Counterpart: D3D11_TEXTURE_ADDRESS_BORDER. OpenGL counterpart: GL_CLAMP_TO_BORDER + /// Direct3D Counterpart: D3D11_TEXTURE_ADDRESS_BORDER/D3D12_TEXTURE_ADDRESS_MODE_BORDER. OpenGL counterpart: GL_CLAMP_TO_BORDER TEXTURE_ADDRESS_BORDER = 4, /// Similar to TEXTURE_ADDRESS_MIRROR and TEXTURE_ADDRESS_CLAMP. Takes the absolute /// value of the texture coordinate (thus, mirroring around 0), and then clamps to /// the maximum value. \n - /// D3D11 Counterpart: D3D11_TEXTURE_ADDRESS_MIRROR_ONCE. OpenGL counterpart: GL_MIRROR_CLAMP_TO_EDGE + /// Direct3D Counterpart: D3D11_TEXTURE_ADDRESS_MIRROR_ONCE/D3D12_TEXTURE_ADDRESS_MODE_MIRROR_ONCE. OpenGL counterpart: GL_MIRROR_CLAMP_TO_EDGE /// \note GL_MIRROR_CLAMP_TO_EDGE is only available in OpenGL4.4+, and is not available until at least OpenGLES3.1 TEXTURE_ADDRESS_MIRROR_ONCE = 5, @@ -829,45 +837,46 @@ namespace Diligent /// Comparison function /// [D3D11_COMPARISON_FUNC]: https://msdn.microsoft.com/en-us/library/windows/desktop/ff476101(v=vs.85).aspx - /// This enumeartion defines a comparison function. It generally mirrows [D3D11_COMPARISON_FUNC] enum and is used by + /// [D3D12_COMPARISON_FUNC]: https://msdn.microsoft.com/en-us/library/windows/desktop/dn770349(v=vs.85).aspx + /// This enumeartion defines a comparison function. It generally mirrors [D3D11_COMPARISON_FUNC]/[D3D12_COMPARISON_FUNC] enum and is used by /// - SamplerDesc to define a comparison function if one of the comparison mode filters is used /// - StencilOpDesc to define a stencil function /// - DepthStencilStateDesc to define a depth function enum COMPARISON_FUNCTION : Int32 { /// Unknown comparison function - COMPARISON_FUNC_UNKNOW = 0, + COMPARISON_FUNC_UNKNOWN = 0, /// Comparison never passes. \n - /// D3D11 counterpart: D3D11_COMPARISON_NEVER. OpenGL counterpart: GL_NEVER. + /// Direct3D counterpart: D3D11_COMPARISON_NEVER/D3D12_COMPARISON_FUNC_NEVER. OpenGL counterpart: GL_NEVER. COMPARISON_FUNC_NEVER, /// Comparison passes if the source data is less than the destination data.\n - /// D3D11 counterpart: D3D11_COMPARISON_LESS. OpenGL counterpart: GL_LESS. + /// Direct3D counterpart: D3D11_COMPARISON_LESS/D3D12_COMPARISON_FUNC_LESS. OpenGL counterpart: GL_LESS. COMPARISON_FUNC_LESS, /// Comparison passes if the source data is equal to the destination data.\n - /// D3D11 counterpart: 3D11_COMPARISON_EQUAL. OpenGL counterpart: GL_EQUAL. + /// Direct3D counterpart: D3D11_COMPARISON_EQUAL/D3D12_COMPARISON_FUNC_EQUAL. OpenGL counterpart: GL_EQUAL. COMPARISON_FUNC_EQUAL, /// Comparison passes if the source data is less than or equal to the destination data.\n - /// D3D11 counterpart: D3D11_COMPARISON_LESS_EQUAL. OpenGL counterpart: GL_LEQUAL. + /// Direct3D counterpart: D3D11_COMPARISON_LESS_EQUAL/D3D12_COMPARISON_FUNC_LESS_EQUAL. OpenGL counterpart: GL_LEQUAL. COMPARISON_FUNC_LESS_EQUAL, /// Comparison passes if the source data is greater than the destination data.\n - /// D3D11 counterpart: 3D11_COMPARISON_GREATER. OpenGL counterpart: GL_GREATER. + /// Direct3D counterpart: 3D11_COMPARISON_GREATER/D3D12_COMPARISON_FUNC_GREATER. OpenGL counterpart: GL_GREATER. COMPARISON_FUNC_GREATER, /// Comparison passes if the source data is not equal to the destination data.\n - /// D3D11 counterpart: D3D11_COMPARISON_NOT_EQUAL. OpenGL counterpart: GL_NOTEQUAL. + /// Direct3D counterpart: D3D11_COMPARISON_NOT_EQUAL/D3D12_COMPARISON_FUNC_NOT_EQUAL. OpenGL counterpart: GL_NOTEQUAL. COMPARISON_FUNC_NOT_EQUAL, /// Comparison passes if the source data is greater than or equal to the destination data.\n - /// D3D11 counterpart: D3D11_COMPARISON_GREATER_EQUAL. OpenGL counterpart: GL_GEQUAL. + /// Direct3D counterpart: D3D11_COMPARISON_GREATER_EQUAL/D3D12_COMPARISON_FUNC_GREATER_EQUAL. OpenGL counterpart: GL_GEQUAL. COMPARISON_FUNC_GREATER_EQUAL, /// Comparison always passes. \n - /// D3D11 counterpart: D3D11_COMPARISON_ALWAYS. OpenGL counterpart: GL_ALWAYS. + /// Direct3D counterpart: D3D11_COMPARISON_ALWAYS/D3D12_COMPARISON_FUNC_ALWAYS. OpenGL counterpart: GL_ALWAYS. COMPARISON_FUNC_ALWAYS, /// Helper value that stores the total number of comparison functions in the enumeration @@ -915,13 +924,25 @@ namespace Diligent /// Sample count. Default value is 1 Uint32 SamplesCount; + /// Number of buffers int the swap chain + Uint32 BufferCount; + + /// Default depth value, which is used as optimized depth clear value in D3D12 + Float32 DefaultDepthValue; + + /// Default stencil value, which is used as optimized stencil clear value in D3D12 + Uint8 DefaultStencilValue; + /// Constructor intializes the structure members with default values SwapChainDesc() : Width(0), Height(0), ColorBufferFormat( TEX_FORMAT_RGBA8_UNORM_SRGB ), DepthBufferFormat( TEX_FORMAT_D32_FLOAT ), - SamplesCount( 1 ) + SamplesCount( 1 ), + BufferCount( 2 ), + DefaultDepthValue(1.f), + DefaultStencilValue(0) {} }; @@ -929,12 +950,47 @@ namespace Diligent struct EngineCreationAttribs { const Char* strShaderCachePath; - + /// Pointer to the raw memory allocator that will be used for all memory allocation/deallocation + /// operations in an engine + class IMemoryAllocator *pRawMemAllocator; EngineCreationAttribs() : - strShaderCachePath(nullptr) + strShaderCachePath(nullptr), + pRawMemAllocator(nullptr) {} }; + /// Attributes specific to D3D12 engine + struct EngineD3D12Attribs : public EngineCreationAttribs + { + /// Size of the CPU descriptor heap allocations for different heap types. + Uint32 CPUDescriptorHeapAllocationSize[4] = + { + 1024, // D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV + 256, // D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER + 128, // D3D12_DESCRIPTOR_HEAP_TYPE_RTV + 64 // D3D12_DESCRIPTOR_HEAP_TYPE_DSV + }; + + /// Size of the GPU descriptor heap allocations for different heap types. + Uint32 GPUDescriptorHeapSize[2] = + { + 16384, // D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV + 1024 // D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER + }; + + /// Size of the dynamic GPU descriptor heap region for different heap types. + Uint32 GPUDescriptorHeapDynamicSize[2] = + { + 4096, // D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV + 1024 // D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER + }; + + /// Number of commands to flush the command list. Only draw/dispatch commands count + /// towards the limit. Command lists are only flushed when pipeline state is changed + /// or when backbuffer is presented. + Uint32 NumCommandsToFlushCmdList = 256; + }; + /// Box struct Box { diff --git a/Graphics/GraphicsEngine/interface/VertexDescription.h b/Graphics/GraphicsEngine/interface/InputLayout.h index 4883ab40..fa37536e 100644 --- a/Graphics/GraphicsEngine/interface/VertexDescription.h +++ b/Graphics/GraphicsEngine/interface/InputLayout.h @@ -1,4 +1,4 @@ -/* Copyright 2015 Egor Yusov +/* Copyright 2015-2016 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,17 +24,13 @@ #pragma once /// \file -/// Definition of the Diligent::IVertexDescription interface and related data structures +/// Definition input layout -#include "DeviceObject.h" +#include "BasicTypes.h" namespace Diligent { -// {2D6915E5-003B-4C68-BDF0-8F93FA7AD4BC} -static const Diligent::INTERFACE_ID IID_VertexDescription = -{ 0x2d6915e5, 0x3b, 0x4c68, { 0xbd, 0xf0, 0x8f, 0x93, 0xfa, 0x7a, 0xd4, 0xbc } }; - static const Uint32 iMaxLayoutElements = 16; /// Description of a single element of the input layout @@ -107,34 +103,17 @@ struct LayoutElement /// Layout description -/// This structure is used by IRenderDevice::CreateVertexDescription(). -struct LayoutDesc : DeviceObjectAttribs +/// This structure is used by IRenderDevice::CreatePipelineState(). +struct InputLayoutDesc { /// Array of layout elements const LayoutElement *LayoutElements; + /// Number of layout elements Uint32 NumElements; - LayoutDesc() : + InputLayoutDesc() : LayoutElements(nullptr), NumElements(0) {} }; -/// Vertex description interface - -/// Vertex description is created by a call to IRenderDevice::CreateVertexDescription(). -/// To bind vertex descption, call IDeviceContext::SetVertexDescription(). -class IVertexDescription : public IDeviceObject -{ -public: - /// Queries the specific interface, see IObject::QueryInterface() for details - virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface ) = 0; - - /// Returns layout description used to create the object - virtual const LayoutDesc &GetDesc()const = 0; - - /// Returns tight strides for each input buffer slot. Tight strides are computed - /// assuming that all layout elements in the buffer are tightly packed. - virtual const Uint32* GetTightStrides() = 0; -}; - } diff --git a/Graphics/GraphicsEngine/interface/MapHelper.h b/Graphics/GraphicsEngine/interface/MapHelper.h index 9f2aae72..b0d54e69 100644 --- a/Graphics/GraphicsEngine/interface/MapHelper.h +++ b/Graphics/GraphicsEngine/interface/MapHelper.h @@ -1,4 +1,4 @@ -/* Copyright 2015 Egor Yusov +/* Copyright 2015-2016 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,21 +43,24 @@ namespace Diligent /// MapHelper<float> UniformData( pDeviceContext, pUniformBuff, MAP_WRITE_DISCARD, 0 ); /// UniformData[0] = UniformData[1] = UniformData[2] = UniformData[3] = 1; /// } -template<typename DataType> +template<typename DataType, bool KeepStrongReferences = false> class MapHelper { public: /// Initializes the class member with null values MapHelper() : - m_pMappedData(nullptr) + m_pMappedData(nullptr), + m_pBuffer(nullptr), + m_pContext(nullptr), + m_MapType(static_cast<MAP_TYPE>(-1)) { } /// Initializes the object and maps the provided resource. /// See Map() for details. MapHelper( IDeviceContext *pContext, IBuffer *pBuffer, MAP_TYPE MapType, Uint32 MapFlags ) : - m_pMappedData(nullptr) + MapHelper() { Map(pContext, pBuffer, MapType, MapFlags); } @@ -66,11 +69,13 @@ public: MapHelper(MapHelper&& Helper) : m_pBuffer( std::move(Helper.m_pBuffer) ), m_pMappedData( std::move(Helper.m_pMappedData) ), - m_pContext( std::move(Helper.m_pContext) ) + m_pContext( std::move(Helper.m_pContext) ), + m_MapType( std::move(Helper.m_MapType) ) { - Helper.m_pBuffer.Release(); - Helper.m_pContext.Release(); + Helper.m_pBuffer = nullptr; + Helper.m_pContext = nullptr; Helper.m_pMappedData = nullptr; + Helper.m_MapType = static_cast<MAP_TYPE>(-1); } /// Move-assignement operator: takes over resource ownership from Helper @@ -79,9 +84,11 @@ public: m_pBuffer = std::move(Helper.m_pBuffer); m_pMappedData = std::move(Helper.m_pMappedData); m_pContext = std::move( Helper.m_pContext ); - Helper.m_pBuffer.Release(); - Helper.m_pContext.Release(); + m_MapType = std::move(Helper.m_MapType); + Helper.m_pBuffer = nullptr; + Helper.m_pContext = nullptr; Helper.m_pMappedData = nullptr; + Helper.m_MapType = static_cast<MAP_TYPE>(-1); return *this; } @@ -97,6 +104,7 @@ public: Unmap(); m_pContext = pContext; m_pBuffer = pBuffer; + m_MapType = MapType; m_pBuffer->Map(m_pContext, MapType, MapFlags, (PVoid&)m_pMappedData); VERIFY( m_pMappedData, "Map failed" ); } @@ -106,10 +114,11 @@ public: { if( m_pBuffer ) { - m_pBuffer->Unmap(m_pContext); - m_pBuffer.Release(); + m_pBuffer->Unmap(m_pContext, m_MapType); + m_pBuffer = nullptr; + m_MapType = static_cast<MAP_TYPE>(-1); } - m_pContext.Release(); + m_pContext = nullptr; m_pMappedData = nullptr; } @@ -135,14 +144,31 @@ private: MapHelper(const MapHelper&); MapHelper& operator=(const MapHelper&); - /// Strong auto pointer to the resource - RefCntAutoPtr<IBuffer> m_pBuffer; + template<typename PtrType, bool UseStrongReference> + struct PtrTypeSelector{}; - /// Strong auto pointer to the context - RefCntAutoPtr<IDeviceContext> m_pContext; + template<typename PtrType> + struct PtrTypeSelector<PtrType, true> + { + typedef RefCntAutoPtr<PtrType> Type; + }; + + template<typename PtrType> + struct PtrTypeSelector<PtrType, false> + { + typedef PtrType* Type; + }; + + /// Pointer / strong auto pointer to the resource + typename PtrTypeSelector<IBuffer, KeepStrongReferences>::Type m_pBuffer; + + /// Pointer / strong auto pointer to the context + typename PtrTypeSelector<IDeviceContext, KeepStrongReferences>::Type m_pContext; /// Pointer to the mapped data DataType *m_pMappedData; + + MAP_TYPE m_MapType; }; } diff --git a/Graphics/GraphicsEngine/interface/PipelineState.h b/Graphics/GraphicsEngine/interface/PipelineState.h new file mode 100644 index 00000000..34503ef9 --- /dev/null +++ b/Graphics/GraphicsEngine/interface/PipelineState.h @@ -0,0 +1,233 @@ +/* Copyright 2015-2016 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +/// \file +/// Definition of the Diligent::IRenderDevice interface and related data structures + +#include "GraphicsTypes.h" +#include "Object.h" +#include "BlendState.h" +#include "RasterizerState.h" +#include "DepthStencilState.h" +#include "InputLayout.h" +#include "ShaderResourceBinding.h" + +namespace Diligent +{ + +/// Primitive topology type + +/// [D3D12_PRIMITIVE_TOPOLOGY_TYPE]: https://msdn.microsoft.com/en-us/library/windows/desktop/dn770385(v=vs.85).aspx +/// This enumeration describes primitive topology type. It generally mirrors [D3D12_PRIMITIVE_TOPOLOGY_TYPE] enumeration. +/// The enumeration is used by GraphicsPipelineDesc to describe how the pipeline interprets +/// geometry or hull shader input primitives +enum PRIMITIVE_TOPOLOGY_TYPE : Int32 +{ + /// Topology is not defined + PRIMITIVE_TOPOLOGY_TYPE_UNDEFINED = 0, + + /// Interpret the input primitive as a point. + PRIMITIVE_TOPOLOGY_TYPE_POINT, + + /// Interpret the input primitive as a line. + PRIMITIVE_TOPOLOGY_TYPE_LINE, + + /// Interpret the input primitive as a triangle. + PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE, + + /// Interpret the input primitive as a control point patch. + PRIMITIVE_TOPOLOGY_TYPE_PATCH, + + /// Total number of topology types + PRIMITIVE_TOPOLOGY_TYPE_NUM_TYPES +}; + +/// Sample description + +/// This structure is used by GraphicsPipelineDesc to describe multisampling parameters +struct SampleDesc +{ + /// Sample count + Uint32 Count; + + /// Quality + Uint32 Quality; + + SampleDesc() : + Count(1), + Quality(0) + {} +}; + + +/// Graphics pipeline state description + +/// This structure describes the graphics pipeline state and is part of the PipelineStateDesc structure. +struct GraphicsPipelineDesc +{ + /// Vertex shader to be used with the pipeline + IShader *pVS; + + /// Pixel shader to be used with the pipeline + IShader *pPS; + + /// Domain shader to be used with the pipeline + IShader *pDS; + + /// Hull shader to be used with the pipeline + IShader *pHS; + + /// Geometry shader to be used with the pipeline + IShader *pGS; + + //D3D12_STREAM_OUTPUT_DESC StreamOutput; + + /// Blend state description + BlendStateDesc BlendDesc; + + /// 32-bit sample mask that determines which samples get updated + /// in all the active render targets. A sample mask is always applied; + /// it is independent of whether multisampling is enabled, and does not + /// depend on whether an application uses multisample render targets. + Uint32 SampleMask; + + /// Rasterizer state description + RasterizerStateDesc RasterizerDesc; + + /// Depth-stencil state description + DepthStencilStateDesc DepthStencilDesc; + + /// Input layout + InputLayoutDesc InputLayout; + //D3D12_INDEX_BUFFER_STRIP_CUT_VALUE IBStripCutValue; + + /// Primitive topology type + PRIMITIVE_TOPOLOGY_TYPE PrimitiveTopologyType; + + /// Number of render targets in the RTVFormats member + Uint32 NumRenderTargets; + + /// Render target formats + TEXTURE_FORMAT RTVFormats[8]; + + /// Depth-stencil format + TEXTURE_FORMAT DSVFormat; + + /// Multisampling parameters + SampleDesc SmplDesc; + + /// Node mask. + Uint32 NodeMask; + + //D3D12_CACHED_PIPELINE_STATE CachedPSO; + //D3D12_PIPELINE_STATE_FLAGS Flags; + + GraphicsPipelineDesc() : + pVS(nullptr), + pPS(nullptr), + pDS(nullptr), + pHS(nullptr), + pGS(nullptr), + PrimitiveTopologyType(PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE), + SampleMask(0xFFFFFFFF), + NumRenderTargets(0), + NodeMask(0) + { + for(size_t rt = 0; rt < _countof(RTVFormats); ++rt) + RTVFormats[rt] = TEX_FORMAT_UNKNOWN; + DSVFormat = TEX_FORMAT_UNKNOWN; + }; +}; + + +/// Compute pipeline state description + +/// This structure describes the compute pipeline state and is part of the PipelineStateDesc structure. +struct ComputePipelineDesc +{ + /// Compute shader to be used with the pipeline + IShader *pCS; + ComputePipelineDesc() : + pCS(nullptr) + {} +}; + +/// Pipeline state description +struct PipelineStateDesc : DeviceObjectAttribs +{ + /// Flag indicating if pipeline state is a compute pipeline state + bool IsComputePipeline; + + /// Graphics pipeline state description. This memeber is ignored if IsComputePipeline == True + GraphicsPipelineDesc GraphicsPipeline; + + /// Compute pipeline state description. This memeber is ignored if IsComputePipeline == False + ComputePipelineDesc ComputePipeline; + + /// Shader resource binding allocation granularity + + /// This member defines allocation granularity for internal resources required by the shader resource + /// binding object instances. + Uint32 SRBAllocationGranularity; + + PipelineStateDesc() : + IsComputePipeline(false), + SRBAllocationGranularity(1) + {} +}; + +// {06084AE5-6A71-4FE8-84B9-395DD489A28C} +static const Diligent::INTERFACE_ID IID_PipelineState = +{ 0x6084ae5, 0x6a71, 0x4fe8, { 0x84, 0xb9, 0x39, 0x5d, 0xd4, 0x89, 0xa2, 0x8c } }; + +/** + * Pipeline state interface + */ +class IPipelineState : public IDeviceObject +{ +public: + /// Queries the specific interface, see IObject::QueryInterface() for details + virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface ) = 0; + + /// Returns the blend state description used to create the object + virtual const PipelineStateDesc& GetDesc()const = 0; + + /// Binds resources for all shaders in the pipeline state + + /// \param [in] pResourceMapping - Pointer to the resource mapping interface. + /// \param [in] Flags - Additional flags. See Diligent::BIND_SHADER_RESOURCES_FLAGS. + /// \remarks For older OpenGL devices that do not support program pipelines + /// (OpenGL4.1-, OpenGLES3.0-). This function is the only way to bind + /// shader resources. + virtual void BindShaderResources( IResourceMapping *pResourceMapping, Uint32 Flags ) = 0; + + /// Creates a shader resource binding object + + /// \param [out] ppShaderResourceBinding - memory location where pointer to the new shader resource + /// binding object is written. + virtual void CreateShaderResourceBinding( IShaderResourceBinding **ppShaderResourceBinding ) = 0; +}; + +} diff --git a/Graphics/GraphicsEngine/interface/RasterizerState.h b/Graphics/GraphicsEngine/interface/RasterizerState.h index e69bf635..a475595d 100644 --- a/Graphics/GraphicsEngine/interface/RasterizerState.h +++ b/Graphics/GraphicsEngine/interface/RasterizerState.h @@ -1,4 +1,4 @@ -/* Copyright 2015 Egor Yusov +/* Copyright 2015-2016 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,9 +24,9 @@ #pragma once /// \file -/// Definition of the Diligent::IRasterizerState interface and related data structures +/// Rasterizer state description -#include "DeviceObject.h" +#include "BasicTypes.h" namespace Diligent { @@ -34,19 +34,20 @@ namespace Diligent /// Fill mode /// [D3D11_FILL_MODE]: https://msdn.microsoft.com/en-us/library/windows/desktop/ff476131(v=vs.85).aspx -/// This enumeration determines the fill mode to use when rendering triangles and mirrows the -/// [D3D11_FILL_MODE][] enum. It is used by RasterizerStateDesc structure to define the fill mode. +/// [D3D12_FILL_MODE]: https://msdn.microsoft.com/en-us/library/windows/desktop/dn770366(v=vs.85).aspx +/// This enumeration determines the fill mode to use when rendering triangles and mirrors the +/// [D3D11_FILL_MODE][]/[D3D12_FILL_MODE][] enum. It is used by RasterizerStateDesc structure to define the fill mode. enum FILL_MODE : Int32 { /// Undefined fill mode. FILL_MODE_UNDEFINED = 0, /// Rasterize triangles using wireframe fill. \n - /// D3D11 counterpart: D3D11_FILL_WIREFRAME. OpenGL counterpart: GL_LINE. + /// Direct3D counterpart: D3D11_FILL_WIREFRAME/D3D12_FILL_MODE_WIREFRAME. OpenGL counterpart: GL_LINE. FILL_MODE_WIREFRAME, /// Rasterize triangles using solid fill. \n - /// D3D11 counterpart: D3D11_FILL_SOLID. OpenGL counterpart: GL_FILL. + /// Direct3D counterpart: D3D11_FILL_SOLID/D3D12_FILL_MODE_SOLID. OpenGL counterpart: GL_FILL. FILL_MODE_SOLID, /// Helper value that stores the total number of fill modes in the enumeration. @@ -56,40 +57,37 @@ enum FILL_MODE : Int32 /// Cull mode /// [D3D11_CULL_MODE]: https://msdn.microsoft.com/en-us/library/windows/desktop/ff476108(v=vs.85).aspx -/// This enumeration defines which triangles are not drawn during the rasterization and mirrows -/// [D3D11_CULL_MODE][] enum. It is used by RasterizerStateDesc structure to define the polygin cull mode. +/// [D3D12_CULL_MODE]: https://msdn.microsoft.com/en-us/library/windows/desktop/dn770354(v=vs.85).aspx +/// This enumeration defines which triangles are not drawn during the rasterization and mirrors +/// [D3D11_CULL_MODE][]/[D3D12_CULL_MODE][] enum. It is used by RasterizerStateDesc structure to define the polygon cull mode. enum CULL_MODE : Int32 { /// Undefined cull mode. CULL_MODE_UNDEFINED = 0, /// Draw all triangles. \n - /// D3D11 counterpart: D3D11_CULL_NONE. OpenGL counterpart: glDisable( GL_CULL_FACE ). + /// Direct3D counterpart: D3D11_CULL_NONE/D3D12_CULL_MODE_NONE. OpenGL counterpart: glDisable( GL_CULL_FACE ). CULL_MODE_NONE, /// Do not draw triangles that are front-facing. Front- and back-facing triangles are determined /// by the RasterizerStateDesc::FrontCounterClockwise member. \n - /// D3D11 counterpart: D3D11_CULL_FRONT. OpenGL counterpart: GL_FRONT. + /// Direct3D counterpart: D3D11_CULL_FRONT/D3D12_CULL_MODE_FRONT. OpenGL counterpart: GL_FRONT. CULL_MODE_FRONT, /// Do not draw triangles that are back-facing. Front- and back-facing triangles are determined /// by the RasterizerStateDesc::FrontCounterClockwise member. \n - /// D3D11 counterpart: D3D11_CULL_BACK. OpenGL counterpart: GL_BACK. + /// Direct3D counterpart: D3D11_CULL_BACK/D3D12_CULL_MODE_BACK. OpenGL counterpart: GL_BACK. CULL_MODE_BACK, /// Helper value that stores the total number of cull modes in the enumeration. CULL_MODE_NUM_MODES }; -// {530A181E-2777-4DAA-B837-ED7D3C28418E} -static const Diligent::INTERFACE_ID IID_RasterizerState = -{ 0x530a181e, 0x2777, 0x4daa, { 0xb8, 0x37, 0xed, 0x7d, 0x3c, 0x28, 0x41, 0x8e } }; /// Rasterizer state description -/// This structure describes the rasterizer state which is used in a call to -/// IRenderDevice::CreateRasterizerState() to create a rasterizer state object -struct RasterizerStateDesc : DeviceObjectAttribs +/// This structure describes the rasterizer state and is part of the GraphicsPipelineDesc. +struct RasterizerStateDesc { /// Determines traingle fill mode, see Diligent::FILL_MODE for details. FILL_MODE FillMode; @@ -157,14 +155,9 @@ struct RasterizerStateDesc : DeviceObjectAttribs /// \return /// - True if all members of the two structures are equal. /// - False otherwise - /// The operator ignores DeviceObjectAttribs::Name field as it does not affect - /// the rasterizer state. bool operator == (const RasterizerStateDesc& RHS)const { - // Name is primarily used for debug purposes and does not affect the state. - // It is ignored in comparison operation. - return // strcmp(Name, RHS.Name) == 0 && - FillMode == RHS.FillMode && + return FillMode == RHS.FillMode && CullMode == RHS.CullMode && FrontCounterClockwise == RHS.FrontCounterClockwise && DepthBias == RHS.DepthBias && @@ -176,19 +169,4 @@ struct RasterizerStateDesc : DeviceObjectAttribs } }; -/// Rasterizer state interface - -/// The interface holds the rasterizer state object that can be bound to the pipeline by a call -/// to IDeviceContext::SetRasterizerState(). To create a rasterizer state, call -/// IRenderDevice::CreateRasterizerState(). -class IRasterizerState : public IDeviceObject -{ -public: - /// Queries the specific interface, see IObject::QueryInterface() for details - virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface ) = 0; - - /// Returns the rasterizer state description used to create the object - virtual const RasterizerStateDesc& GetDesc()const = 0; -}; - -} +}
\ No newline at end of file diff --git a/Graphics/GraphicsEngine/interface/RenderDevice.h b/Graphics/GraphicsEngine/interface/RenderDevice.h index f8471e11..5a0ca892 100644 --- a/Graphics/GraphicsEngine/interface/RenderDevice.h +++ b/Graphics/GraphicsEngine/interface/RenderDevice.h @@ -1,4 +1,4 @@ -/* Copyright 2015 Egor Yusov +/* Copyright 2015-2016 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,13 +31,15 @@ #include "DeviceCaps.h" #include "Constants.h" #include "Buffer.h" -#include "VertexDescription.h" +#include "InputLayout.h" #include "Shader.h" #include "Texture.h" #include "Sampler.h" #include "ResourceMapping.h" #include "TextureView.h" #include "BufferView.h" +#include "PipelineState.h" + #include "DepthStencilState.h" #include "RasterizerState.h" #include "BlendState.h" @@ -49,9 +51,7 @@ namespace Diligent static const Diligent::INTERFACE_ID IID_RenderDevice = { 0xf0e9b607, 0xae33, 0x4b2b, { 0xb1, 0xaf, 0xa8, 0xb2, 0xc3, 0x10, 0x40, 0x22 } }; -/** - * Render device interface - */ +/// Render device interface class IRenderDevice : public IObject { public: @@ -78,22 +78,6 @@ public: const BufferData& BuffData, IBuffer **ppBuffer) = 0; - /// Creates a new vertex description object. - - /// \param [in] LayoutDesc - Layout description, see GraphisEngine::LayoutDesc for details. - /// \param [in] pVertexShader - Pointer to the vertex shader which this input layout - /// will be used with. If layout description is not compatible - /// with the shader's input signature, the method fails. - /// \param [out] ppVertexDesc - Address of the memory location where the pointer to the - /// vertex description interface will be stored. - /// The function calls AddRef(), so that the new object will contain - /// one refernce. - /// \remark The same vertex description object can be used with all shaders that have - /// the same input semantic. - virtual void CreateVertexDescription( const LayoutDesc& LayoutDesc, - IShader *pVertexShader, - IVertexDescription **ppVertexDesc ) = 0; - /// Creates a new shader object /// \param [in] CreationAttribs - Shader creation attributes, see @@ -154,44 +138,16 @@ public: virtual void CreateResourceMapping( const ResourceMappingDesc &MappingDesc, IResourceMapping **ppMapping ) = 0; - /// Creates a new depth stencil state object - - /// \param [in] DSSDesc - Depth-stencil state description, see Diligent::DepthStencilStateDesc for details. - /// \param [out] ppDepthStencilState - Address of the memory location where the pointer to the - /// depth-stencil state interface will be stored. - /// The function calls AddRef(), so that the new object will contain - /// one refernce. - /// \remark If an application attempts to create a depth-stencil state interface with the same attributes - /// as an existing interface, the same interface will be returned. - /// \note In D3D11, 4096 unique depth-stencil state objects can be created on a device at a time. - virtual void CreateDepthStencilState( const DepthStencilStateDesc &DSSDesc, - IDepthStencilState **ppDepthStencilState ) = 0; - - /// Creates a rasterizer state object - - /// \param [in] RSDesc - Rasterizer state description, see Diligent::RasterizerStateDesc for details. - /// \param [out] ppRasterizerState - Address of the memory location where the pointer to the - /// rasterizer state interface will be stored. - /// The function calls AddRef(), so that the new object will contain - /// one refernce. - /// \remark If an application attempts to create a rasterizer state interface with the same attributes - /// as an existing interface, the same interface will be returned. - /// \note In D3D11, 4096 unique rasterizer state objects can be created on a device at a time. - virtual void CreateRasterizerState( const RasterizerStateDesc &RSDesc, - IRasterizerState **ppRasterizerState ) = 0; + /// Creates a new pipeline state object - /// Creates a blend state object + /// \param [in] PipelineDesc - Pipeline state description, see Diligent::PipelineStateDesc for details. + /// \param [out] ppPipelineState - Address of the memory location where the pointer to the + /// pipeline state interface will be stored. + /// The function calls AddRef(), so that the new object will contain + /// one refernce. + virtual void CreatePipelineState( const PipelineStateDesc &PipelineDesc, + IPipelineState **ppPipelineState ) = 0; - /// \param [in] BSDesc - Blend state description, see Diligent::BlendStateDesc for details. - /// \param [out] ppBlendState - Address of the memory location where the pointer to the - /// blend state interface will be stored. - /// The function calls AddRef(), so that the new object will contain - /// one refernce. - /// \remark If an application attempts to create a blend state interface with the same attributes - /// as an existing interface, the same interface will be returned. - /// \note In D3D11, 4096 unique blend state objects can be created on a device at a time. - virtual void CreateBlendState( const BlendStateDesc &BSDesc, - IBlendState **ppBlendState ) = 0; /// Gets the device capabilities, see Diligent::DeviceCaps for details virtual const DeviceCaps& GetDeviceCaps()const = 0; diff --git a/Graphics/GraphicsEngine/interface/ResourceMapping.h b/Graphics/GraphicsEngine/interface/ResourceMapping.h index f4ee7a17..191ae66f 100644 --- a/Graphics/GraphicsEngine/interface/ResourceMapping.h +++ b/Graphics/GraphicsEngine/interface/ResourceMapping.h @@ -1,4 +1,4 @@ -/* Copyright 2015 Egor Yusov +/* Copyright 2015-2016 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,13 +43,16 @@ namespace Diligent /// Pointer to the object's interface IDeviceObject *pObject; + Uint32 ArrayIndex; /// Initializes the structure members - /// \param [in] InitName - Object name. Default value is nullptr - /// \param [in] pInitObject - Pointer to the object. Default value is nullptr - ResourceMappingEntry( const Char* InitName = nullptr, IDeviceObject *pInitObject = nullptr) : - Name( InitName ), - pObject( pInitObject ) + /// \param [in] _Name - Object name. Default value is nullptr + /// \param [in] _pObject - Pointer to the object. Default value is nullptr + /// \param [in] _ArrayIndex - For array resources, index in the array + ResourceMappingEntry( const Char* _Name = nullptr, IDeviceObject *_pObject = nullptr, Uint32 _ArrayIndex = 0) : + Name( _Name ), + pObject( _pObject ), + ArrayIndex(_ArrayIndex) {} }; @@ -92,25 +95,38 @@ namespace Diligent /// object will not be released as long as it is in the resource mapping. virtual void AddResource( const Char *Name, IDeviceObject *pObject, bool bIsUnique ) = 0; - /// Removes a resource from the mapping. - /// \param [in] pObject - Pointer to the object to remove. - virtual void RemoveResource( IDeviceObject *pObject ) = 0; + /// Adds resource array to the mapping. + + /// \param [in] Name - Resource array name. + /// \param [in] StartIndex - First index in the array, where the first element will be inserted + /// \param [in] ppObjects - Pointer to the array of objects. + /// \param [in] NumElements - Number of elements to add + /// \param [in] bIsUnique - Flag indicating if a resource with the same name + /// is allowed to be found in the mapping. In the latter + /// case, the new resource replaces the existing one. + /// + /// \remarks Resource mapping increases the reference counter for referenced objects. So an + /// object will not be released as long as it is in the resource mapping. + virtual void AddResourceArray( const Char *Name, Uint32 StartIndex, IDeviceObject* const* ppObjects, Uint32 NumElements, bool bIsUnique ) = 0; + /// Removes a resource from the mapping using its literal name. /// \param [in] Name - Name of the resource to remove. - virtual void RemoveResourceByName( const Char *Name ) = 0; + /// \param [in] ArrayIndex - For array resources, index in the array + virtual void RemoveResourceByName( const Char *Name, Uint32 ArrayIndex = 0 ) = 0; /// Finds a resource in the mapping. /// \param [in] Name - Resource name. + /// \param [in] ArrayIndex - for arrays, index of the array element. /// \param [out] ppResource - Address of the memory location where the pointer /// to the object with the given name will be written. /// If no object is found, nullptr will be written. /// \remarks The method increases the reference counter /// of the returned object, so Release() must be called. - virtual void GetResource( const Char *Name, IDeviceObject **ppResource ) = 0; + virtual void GetResource( const Char *Name, IDeviceObject **ppResource, Uint32 ArrayIndex = 0 ) = 0; /// Returns the size of the resource mapping, i.e. the number of objects. virtual size_t GetSize() = 0; diff --git a/Graphics/GraphicsEngine/interface/Sampler.h b/Graphics/GraphicsEngine/interface/Sampler.h index 52742b3c..1f3c82a2 100644 --- a/Graphics/GraphicsEngine/interface/Sampler.h +++ b/Graphics/GraphicsEngine/interface/Sampler.h @@ -1,4 +1,4 @@ -/* Copyright 2015 Egor Yusov +/* Copyright 2015-2016 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngine/interface/Shader.h b/Graphics/GraphicsEngine/interface/Shader.h index 61861648..15d81342 100644 --- a/Graphics/GraphicsEngine/interface/Shader.h +++ b/Graphics/GraphicsEngine/interface/Shader.h @@ -1,4 +1,4 @@ -/* Copyright 2015 Egor Yusov +/* Copyright 2015-2016 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ #include "DeviceObject.h" #include "ResourceMapping.h" #include "FileStream.h" +#include "Sampler.h" namespace Diligent { @@ -58,13 +59,20 @@ enum SHADER_PROFILE : Int32 SHADER_PROFILE_DEFAULT = 0, SHADER_PROFILE_DX_4_0, SHADER_PROFILE_DX_5_0, + SHADER_PROFILE_DX_5_1, SHADER_PROFILE_GL_4_2 }; +/// Describes shader source code language enum SHADER_SOURCE_LANGUAGE : Int32 { + /// Default language (GLSL for OpenGL/OpenGLES devices, HLSL for Direct3D11/Direct3D12 devices) SHADER_SOURCE_LANGUAGE_DEFAULT = 0, + + /// The source language is HLSL SHADER_SOURCE_LANGUAGE_HLSL, + + /// The source language is GLSL SHADER_SOURCE_LANGUAGE_GLSL }; @@ -72,8 +80,8 @@ enum SHADER_SOURCE_LANGUAGE : Int32 /// and IDeviceContext::BindShaderResources(). enum BIND_SHADER_RESOURCES_FLAGS : Int32 { - /// Reset all bindings. If this specified, all existing bindings will be - /// broken. By default all existing bindings are presereved. + /// Reset all bindings. If this flag is specified, all existing bindings will be + /// broken. By default all existing bindings are preserved. BIND_SHADER_RESOURCES_RESET_BINDINGS = 0x01, /// If this flag is specified, only unresolved bindings will be updated. @@ -84,10 +92,56 @@ enum BIND_SHADER_RESOURCES_FLAGS : Int32 /// If this flag is specified, all shader bindings are expected /// to be resolved after the call. If this is not the case, debug error - /// will be output. + /// will be displayed. BIND_SHADER_RESOURCES_ALL_RESOLVED = 0x04 }; +/// Describes shader variable type that is used by ShaderVariableDesc +enum SHADER_VARIABLE_TYPE : Int32 +{ + /// Shader variable is constant across all shader instances. + /// It must be set *once* directly through IShader::BindResources() or through + /// the shader variable. + SHADER_VARIABLE_TYPE_STATIC = 0, + + /// Shader variable is constant across shader resource bindings instance (see IShaderResourceBinding). + /// It must be set *once* through IShaderResourceBinding::BindResources() or through + /// the shader variable. It cannot be set through IShader interface + SHADER_VARIABLE_TYPE_MUTABLE, + + /// Shader variable is dynamic. It can be set multiple times for every instance of shader resource + /// bindings (see IShaderResourceBinding). It cannot be set through IShader interface + SHADER_VARIABLE_TYPE_DYNAMIC, + + /// Total number of shader variable types + SHADER_VARIABLE_TYPE_NUM_TYPES +}; + +/// Describes shader variable +struct ShaderVariableDesc +{ + /// Shader variable name + const char *Name; + + /// Shader variable type. See Diligent::SHADER_VARIABLE_TYPE for a list of allowed types + SHADER_VARIABLE_TYPE Type; + ShaderVariableDesc(const char *_Name = nullptr, SHADER_VARIABLE_TYPE _Type = SHADER_VARIABLE_TYPE_STATIC) : + Name(_Name), + Type(_Type) + {} +}; + + +/// Static sampler description +struct StaticSamplerDesc +{ + /// Sampler description + SamplerDesc Desc; + + /// Name of the texture variable that static sampler will be assigned to + const char* TextureName = nullptr; +}; + /// Shader description struct ShaderDesc : DeviceObjectAttribs { @@ -97,10 +151,32 @@ struct ShaderDesc : DeviceObjectAttribs Bool bCacheCompiledShader; SHADER_PROFILE TargetProfile; + /// Default shader variable type. This type will be used if shader + /// variable description is not found in array VariableDesc points to + /// or if VariableDesc == nullptr + SHADER_VARIABLE_TYPE DefaultVariableType; + + /// Array of shader variable descriptions + const ShaderVariableDesc *VariableDesc; + + /// Number of elements in VariableDesc array + Uint32 NumVariables; + + /// Number of static samplers in StaticSamplers array + Uint32 NumStaticSamplers; + + /// Array of static sampler descriptions + StaticSamplerDesc *StaticSamplers; + ShaderDesc() : ShaderType(SHADER_TYPE_VERTEX), bCacheCompiledShader(False), - TargetProfile(SHADER_PROFILE_DEFAULT) + TargetProfile(SHADER_PROFILE_DEFAULT), + DefaultVariableType(SHADER_VARIABLE_TYPE_STATIC), + VariableDesc(nullptr), + NumVariables(0), + NumStaticSamplers(0), + StaticSamplers(nullptr) {} }; @@ -170,12 +246,7 @@ public: /// be assigned to a constant buffer variable. virtual void Set(IDeviceObject *pObject) = 0; - /// Returns the shader which this shader variable - /// belongs to - - /// \remark The method does not increment the reference counter - /// of the returned interface. - virtual class IShader* GetShader() = 0; + virtual void SetArray(IDeviceObject* const* ppObjects, Uint32 FirstElement, Uint32 NumElements) = 0; }; /// Shader interface diff --git a/Graphics/GraphicsEngine/interface/ShaderResourceBinding.h b/Graphics/GraphicsEngine/interface/ShaderResourceBinding.h new file mode 100644 index 00000000..7a757a3f --- /dev/null +++ b/Graphics/GraphicsEngine/interface/ShaderResourceBinding.h @@ -0,0 +1,68 @@ +/* Copyright 2015-2016 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +/// \file +/// Definition of the Diligent::IShaderResourceBinding interface and related data structures + +#include "Object.h" + +namespace Diligent +{ + +// {061F8774-9A09-48E8-8411-B5BD20560104} +static const Diligent::INTERFACE_ID IID_ShaderResourceBinding = +{ 0x61f8774, 0x9a09, 0x48e8, { 0x84, 0x11, 0xb5, 0xbd, 0x20, 0x56, 0x1, 0x4 } }; + + +/// Shader resource binding interface +class IShaderResourceBinding : public IObject +{ +public: + /// Queries the specific interface, see IObject::QueryInterface() for details + virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface ) = 0; + + /// Returns pointer to the referenced buffer object. + + /// The method calls AddRef() on the returned interface, + /// so Release() must be called to avoid memory leaks. + virtual class IPipelineState* GetPipelineState() = 0; + + /// Binds all resource using the resource mapping + + /// \param [in] ShaderFlags - Flags for the shader stages, for which resources will be bound. + /// Any combination of Diligent::SHADER_TYPE may be specified. + /// \param [in] pResMapping - Shader resource mapping, where required resources will be looked up + /// \param [in] Flags - Additional flags. See Diligent::BIND_SHADER_RESOURCES_FLAGS. + virtual void BindResources(Uint32 ShaderFlags, IResourceMapping *pResMapping, Uint32 Flags) = 0; + + /// Returns variable + + /// \param [in] ShaderType - Type of the shader to look up the variable. + /// Must be one of Diligent::SHADER_TYPE. + /// \param Name - Variable name + virtual IShaderVariable *GetVariable(SHADER_TYPE ShaderType, const char *Name) = 0; +}; + +} diff --git a/Graphics/GraphicsEngine/interface/SwapChain.h b/Graphics/GraphicsEngine/interface/SwapChain.h index c451bbf6..aae576bb 100644 --- a/Graphics/GraphicsEngine/interface/SwapChain.h +++ b/Graphics/GraphicsEngine/interface/SwapChain.h @@ -1,4 +1,4 @@ -/* Copyright 2015 Egor Yusov +/* Copyright 2015-2016 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngine/interface/Texture.h b/Graphics/GraphicsEngine/interface/Texture.h index de352a3c..0c3c2c1e 100644 --- a/Graphics/GraphicsEngine/interface/Texture.h +++ b/Graphics/GraphicsEngine/interface/Texture.h @@ -1,4 +1,4 @@ -/* Copyright 2015 Egor Yusov +/* Copyright 2015-2016 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,11 +35,43 @@ namespace Diligent static const Diligent::INTERFACE_ID IID_Texture = { 0xa64b0e60, 0x1b5e, 0x4cfd, { 0xb8, 0x80, 0x66, 0x3a, 0x1a, 0xdc, 0xbe, 0x98 } }; +/// Defines optimized depth-stencil clear value. +struct DepthStencilClearValue +{ + /// Depth clear value + Float32 Depth; + /// Stencil clear value + Uint8 Stencil; + DepthStencilClearValue() : + Depth(1.f), + Stencil(0) + {} +}; + +/// Defines optimized clear value. +struct OptimizedClearValue +{ + /// Format + TEXTURE_FORMAT Format; + /// Render target clear value + Float32 Color[ 4 ]; + /// Depth stencil clear value + DepthStencilClearValue DepthStencil; + OptimizedClearValue() : + Format(TEX_FORMAT_UNKNOWN) + { + Color[0] = 0; + Color[1] = 0; + Color[2] = 0; + Color[3] = 0; + } +}; + /// Texture description struct TextureDesc : DeviceObjectAttribs { - /// Texture type. See Diligent::TEXTURE_TYPE for details. - TEXTURE_TYPE Type; + /// Texture type. See Diligent::RESOURCE_DIMENSION for details. + RESOURCE_DIMENSION Type; /// Texture width, in pixels. Uint32 Width; @@ -84,12 +116,15 @@ struct TextureDesc : DeviceObjectAttribs /// Miscellaneous flags, see Diligent::MISC_TEXTURE_FLAG for details. Uint32 MiscFlags; + /// Optimized clear value + OptimizedClearValue ClearValue; + /// Initializes the structure members with default values /// Default values: /// Member | Default value /// ----------------|-------------- - /// Type | TEXTURE_TYPE_UNDEFINED + /// Type | RESOURCE_DIM_UNDEFINED /// Width | 0 /// Height | 0 /// ArraySize | 1 @@ -101,7 +136,7 @@ struct TextureDesc : DeviceObjectAttribs /// CPUAccessFlags | 0 /// MiscFlags | 0 TextureDesc() : - Type(TEXTURE_TYPE_UNDEFINED), + Type(RESOURCE_DIM_UNDEFINED), Width(0), Height(0), ArraySize(1), @@ -142,6 +177,13 @@ struct TextureSubResData Stride(0), DepthStride(0) {} + + /// Initializes the structure members with provided values + TextureSubResData(void *_pData, Uint32 _Stride, Uint32 _DepthStride=0): + pData(_pData), + Stride(_Stride), + DepthStride(_DepthStride) + {} }; /// Describes the initial data to store in the texture @@ -248,7 +290,7 @@ public: /// Map the texture - not implemented yet virtual void Map( IDeviceContext *pContext, MAP_TYPE MapType, Uint32 MapFlags, PVoid &pMappedData ) = 0; /// Unmap the textute - not implemented yet - virtual void Unmap( IDeviceContext *pContext ) = 0; + virtual void Unmap( IDeviceContext *pContext, MAP_TYPE MapType ) = 0; }; } diff --git a/Graphics/GraphicsEngine/interface/TextureView.h b/Graphics/GraphicsEngine/interface/TextureView.h index b55e2f0e..63780f7d 100644 --- a/Graphics/GraphicsEngine/interface/TextureView.h +++ b/Graphics/GraphicsEngine/interface/TextureView.h @@ -1,4 +1,4 @@ -/* Copyright 2015 Egor Yusov +/* Copyright 2015-2016 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -59,10 +59,10 @@ struct TextureViewDesc : DeviceObjectAttribs /// View interpretation of the original texture. For instance, /// one slice of a 2D texture array can be viewed as a 2D texture. - /// See Diligent::TEXTURE_TYPE for a list of texture types. - /// If default value Diligent::TEXTURE_TYPE_UNDEFINED is provided, + /// See Diligent::RESOURCE_DIMENSION for a list of texture types. + /// If default value Diligent::RESOURCE_DIM_UNDEFINED is provided, /// the view type will match the type of the referenced texture. - TEXTURE_TYPE TextureType; + RESOURCE_DIMENSION TextureDim; /// View format. If default value Diligent::TEX_FORMAT_UNKNOWN is provided, /// the view format will match the referenced texture format. @@ -109,7 +109,7 @@ struct TextureViewDesc : DeviceObjectAttribs /// Member | Default value /// --------------------|-------------- /// ViewType | TEXTURE_VIEW_UNDEFINED - /// TextureType | TEXTURE_TYPE_UNDEFINED + /// TextureDim | RESOURCE_DIM_UNDEFINED /// Format | TEX_FORMAT_UNKNOWN /// MostDetailedMip | 0 /// NumMipLevels | 0 @@ -118,7 +118,7 @@ struct TextureViewDesc : DeviceObjectAttribs /// AccessFlags | 0 TextureViewDesc() : ViewType( TEXTURE_VIEW_UNDEFINED ), - TextureType( TEXTURE_TYPE_UNDEFINED ), + TextureDim( RESOURCE_DIM_UNDEFINED ), Format(TEX_FORMAT_UNKNOWN), MostDetailedMip(0), NumMipLevels(0), @@ -140,7 +140,7 @@ struct TextureViewDesc : DeviceObjectAttribs // It is ignored in comparison operation. return //strcmp(Name, RHS.Name) == 0 && ViewType == RHS.ViewType && - TextureType == RHS.TextureType && + TextureDim == RHS.TextureDim && Format == RHS.Format && MostDetailedMip == RHS.MostDetailedMip && NumMipLevels == RHS.NumMipLevels && diff --git a/Graphics/GraphicsEngine/src/EngineMemory.cpp b/Graphics/GraphicsEngine/src/EngineMemory.cpp new file mode 100644 index 00000000..b981724f --- /dev/null +++ b/Graphics/GraphicsEngine/src/EngineMemory.cpp @@ -0,0 +1,73 @@ +/* Copyright 2015-2016 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +// stdafx.cpp : source file that includes just the standard includes +// RenderEngine.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "pch.h" +#include "EngineMemory.h" +#include "DefaultRawMemoryAllocator.h" + +namespace Diligent +{ + +static IMemoryAllocator *g_pRawAllocator; +void SetRawAllocator(IMemoryAllocator *pRawAllocator) +{ + if (pRawAllocator == nullptr) + { + LOG_INFO_MESSAGE("User-defined allocator is not provided. Using default allocator.") + pRawAllocator = &DefaultRawMemoryAllocator::GetAllocator(); + } + g_pRawAllocator = pRawAllocator; +} + +IMemoryAllocator& GetRawAllocator() +{ + return *g_pRawAllocator; +} + +} +#if 0 + +void* operator new(size_t Size) +{ + return Diligent::GetRawAllocator().Allocate(Size, "<Unknown>", "<Unknown>", -1); +} + +void* operator new[](size_t Size) +{ + return Diligent::GetRawAllocator().Allocate(Size, "<Unknown>", "<Unknown>", -1); +} + +void operator delete(void* Ptr) +{ + Diligent::GetRawAllocator().Free(Ptr); +} + +void operator delete[](void* Ptr) +{ + Diligent::GetRawAllocator().Free(Ptr); +} +#endif diff --git a/Graphics/GraphicsEngine/src/ResourceMapping.cpp b/Graphics/GraphicsEngine/src/ResourceMapping.cpp index 47a54ed9..7bfb6ceb 100644 --- a/Graphics/GraphicsEngine/src/ResourceMapping.cpp +++ b/Graphics/GraphicsEngine/src/ResourceMapping.cpp @@ -1,4 +1,4 @@ -/* Copyright 2015 Egor Yusov +/* Copyright 2015-2016 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,71 +33,62 @@ namespace Diligent { } - IMPLEMENT_QUERY_INTERFACE( ResourceMappingImpl, IID_ResourceMapping, ObjectBase<IResourceMapping> ) + IMPLEMENT_QUERY_INTERFACE( ResourceMappingImpl, IID_ResourceMapping, TObjectBase ) ThreadingTools::LockHelper ResourceMappingImpl::Lock() { return std::move( ThreadingTools::LockHelper( m_LockFlag ) ); } - void ResourceMappingImpl::AddResource( const Char *Name, IDeviceObject *pObject, bool bIsUnique ) + void ResourceMappingImpl::AddResourceArray( const Char *Name, Uint32 StartIndex, IDeviceObject * const* ppObjects, Uint32 NumElements, bool bIsUnique ) { if( Name == nullptr || *Name == 0 ) return; auto LockHelper = Lock(); - // Try to construct new element in place - auto Elems = - m_HashTable.emplace( - make_pair( Diligent::HashMapStringKey(Name, true), // Make a copy of the source string - Diligent::RefCntAutoPtr<IDeviceObject>(pObject) - ) - ); - // If there is already element with the same name, replace it - if( !Elems.second && Elems.first->second != pObject ) + for(Uint32 Elem = 0; Elem < NumElements; ++Elem) { - if( bIsUnique ) + auto *pObject = ppObjects[Elem]; + + // Try to construct new element in place + auto Elems = + m_HashTable.emplace( + make_pair( Diligent::ResMappingHashKey(Name, true, StartIndex+Elem), // Make a copy of the source string + Diligent::RefCntAutoPtr<IDeviceObject>(pObject) + ) + ); + // If there is already element with the same name, replace it + if( !Elems.second && Elems.first->second != pObject ) { - UNEXPECTED( "Resource with the same name already exists" ); - LOG_WARNING_MESSAGE( - "Resource with name ", Name, " marked is unique, but already present in the hash.\n" - "New resource will be used\n." ); + if( bIsUnique ) + { + UNEXPECTED( "Resource with the same name already exists" ); + LOG_WARNING_MESSAGE( + "Resource with name ", Name, " marked is unique, but already present in the hash.\n" + "New resource will be used\n." ); + } + Elems.first->second = pObject; } - Elems.first->second = pObject; } } - void ResourceMappingImpl::RemoveResourceByName( const Char *Name ) + void ResourceMappingImpl::AddResource(const Char *Name, IDeviceObject *pObject, bool bIsUnique) { - if( *Name == 0 ) - return; - - auto LockHelper = Lock(); - // Remove object with the given name - // Name will be implicitly converted to HashMapStringKey without making a copy - auto It = m_HashTable.erase( Name ); + AddResourceArray( Name, 0, &pObject, 1, bIsUnique ); } - void ResourceMappingImpl::RemoveResource( IDeviceObject *pObject ) + void ResourceMappingImpl::RemoveResourceByName( const Char *Name, Uint32 ArrayIndex ) { - const auto *Name = pObject->GetDesc().Name; - VERIFY( Name, "Name is null" ); if( *Name == 0 ) return; auto LockHelper = Lock(); - - // Find active object with the same name + // Remove object with the given name // Name will be implicitly converted to HashMapStringKey without making a copy - auto It = m_HashTable.find( Name ); - // Check if the active object is in fact the object being removed - if( It != m_HashTable.end() && It->second == pObject ) - { - m_HashTable.erase( It ); - } + m_HashTable.erase( ResMappingHashKey(Name, false, ArrayIndex) ); } - void ResourceMappingImpl::GetResource( const Char *Name, IDeviceObject **ppResource ) + void ResourceMappingImpl::GetResource( const Char *Name, IDeviceObject **ppResource, Uint32 ArrayIndex ) { VERIFY(Name, "Name is null") if( *Name == 0 ) @@ -114,7 +105,7 @@ namespace Diligent // Find an object with the requested name // Name will be implicitly converted to HashMapStringKey without making a copy - auto It = m_HashTable.find( Name ); + auto It = m_HashTable.find( ResMappingHashKey(Name, false, ArrayIndex) ); if( It != m_HashTable.end() ) { *ppResource = It->second.RawPtr(); diff --git a/Graphics/GraphicsEngine/src/Texture.cpp b/Graphics/GraphicsEngine/src/Texture.cpp index 60440bdc..244e93b7 100644 --- a/Graphics/GraphicsEngine/src/Texture.cpp +++ b/Graphics/GraphicsEngine/src/Texture.cpp @@ -1,4 +1,4 @@ -/* Copyright 2015 Egor Yusov +/* Copyright 2015-2016 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,30 +32,39 @@ void ValidateTextureDesc( const TextureDesc& Desc ) #define LOG_TEXTURE_ERROR_AND_THROW(...) LOG_ERROR_AND_THROW("Texture \"", Desc.Name ? Desc.Name : "", "\": ", ##__VA_ARGS__) // Perform some parameter correctness check - if( Desc.Type == TEXTURE_TYPE_1D || Desc.Type == TEXTURE_TYPE_1D_ARRAY ) + if( Desc.Type == RESOURCE_DIM_TEX_1D || Desc.Type == RESOURCE_DIM_TEX_1D_ARRAY ) { if( Desc.Height != 1 ) LOG_TEXTURE_ERROR_AND_THROW("Height (", Desc.Height,") of Texture 1D/Texture 1D Array must be 1"); } - if( Desc.Type == TEXTURE_TYPE_1D || Desc.Type == TEXTURE_TYPE_2D ) + if( Desc.Type == RESOURCE_DIM_TEX_1D || Desc.Type == RESOURCE_DIM_TEX_2D ) { if( Desc.ArraySize != 1 ) LOG_TEXTURE_ERROR_AND_THROW("Texture 1D/2D must have one array slice (", Desc.ArraySize, " provided). Use Texture 1D/2D array if you need more than one slice."); } + if( Desc.Type == RESOURCE_DIM_TEX_CUBE || Desc.Type == RESOURCE_DIM_TEX_CUBE_ARRAY ) + { + if( Desc.Width != Desc.Height ) + LOG_TEXTURE_ERROR_AND_THROW("For cube map textures, texture width (", Desc.Width," provided) must match texture height (", Desc.Height, " provided)"); + + if( Desc.ArraySize < 6 ) + LOG_TEXTURE_ERROR_AND_THROW("Texture cube/cube array must have at least 6 slices (", Desc.ArraySize, " provided)."); + } + Uint32 MaxDim = 0; - if( Desc.Type == TEXTURE_TYPE_1D || Desc.Type == TEXTURE_TYPE_1D_ARRAY ) + if( Desc.Type == RESOURCE_DIM_TEX_1D || Desc.Type == RESOURCE_DIM_TEX_1D_ARRAY ) MaxDim = Desc.Width; - else if( Desc.Type == TEXTURE_TYPE_2D || Desc.Type == TEXTURE_TYPE_2D_ARRAY ) + else if( Desc.Type == RESOURCE_DIM_TEX_2D || Desc.Type == RESOURCE_DIM_TEX_2D_ARRAY || Desc.Type == RESOURCE_DIM_TEX_CUBE || Desc.Type == RESOURCE_DIM_TEX_CUBE_ARRAY ) MaxDim = std::max(Desc.Width, Desc.Height); - else if( Desc.Type == TEXTURE_TYPE_3D ) + else if( Desc.Type == RESOURCE_DIM_TEX_3D ) MaxDim = std::max( std::max(Desc.Width, Desc.Height), Desc.Depth ); VERIFY( MaxDim >= (1U << (Desc.MipLevels-1)), "Texture \"", Desc.Name ? Desc.Name : "", "\": Incorrect number of Mip levels (", Desc.MipLevels, ")" ) if( Desc.SampleCount > 1 ) { - if( !(Desc.Type == TEXTURE_TYPE_2D || Desc.Type == TEXTURE_TYPE_2D_ARRAY) ) + if( !(Desc.Type == RESOURCE_DIM_TEX_2D || Desc.Type == RESOURCE_DIM_TEX_2D_ARRAY) ) LOG_TEXTURE_ERROR_AND_THROW("Only Texture 2D/Texture 2D Array can be multisampled"); if( Desc.MipLevels != 1 ) @@ -80,14 +89,16 @@ void ValidateTextureDesc( const TextureDesc& Desc ) void ValidateTextureRegion(const TextureDesc &TexDesc, Uint32 MipLevel, Uint32 Slice, const Box &Box) { #define VERIFY_TEX_PARAMS(Expr, ...) VERIFY(Expr, "Texture \"", TexDesc.Name ? TexDesc.Name : "", "\": ", ##__VA_ARGS__) - +#ifdef _DEBUG VERIFY_TEX_PARAMS( MipLevel < TexDesc.MipLevels, "Mip level (", MipLevel, ") is out of allowed range [0, ", TexDesc.MipLevels-1, "]" ); VERIFY_TEX_PARAMS( Box.MinX < Box.MaxX, "Incorrect X range [",Box.MinX, ", ", Box.MaxX, ")" ); VERIFY_TEX_PARAMS( Box.MinY < Box.MaxY, "Incorrect Y range [",Box.MinY, ", ", Box.MaxY, ")" ); VERIFY_TEX_PARAMS( Box.MinZ < Box.MaxZ, "Incorrect Z range [",Box.MinZ, ", ", Box.MaxZ, ")" ); - if( TexDesc.Type == TEXTURE_TYPE_1D_ARRAY || - TexDesc.Type == TEXTURE_TYPE_2D_ARRAY ) + if( TexDesc.Type == RESOURCE_DIM_TEX_1D_ARRAY || + TexDesc.Type == RESOURCE_DIM_TEX_2D_ARRAY || + TexDesc.Type == RESOURCE_DIM_TEX_CUBE || + TexDesc.Type == RESOURCE_DIM_TEX_CUBE_ARRAY) { VERIFY_TEX_PARAMS( Slice < TexDesc.ArraySize, "Array slice (", Slice, ") is out of range [0,", TexDesc.ArraySize-1, "]" ); } @@ -96,20 +107,22 @@ void ValidateTextureRegion(const TextureDesc &TexDesc, Uint32 MipLevel, Uint32 S VERIFY_TEX_PARAMS( Slice == 0, "Array slice (", Slice, ") must be 0 for non-array textures" ); } + Uint32 MipWidth = std::max(TexDesc.Width >> MipLevel, 1U); VERIFY_TEX_PARAMS( Box.MaxX <= MipWidth, "Region max X coordinate (", Box.MaxX, ") is out of allowed range [0, ", MipWidth, "]" ); - if( TexDesc.Type != TEXTURE_TYPE_1D && - TexDesc.Type != TEXTURE_TYPE_1D_ARRAY ) + if( TexDesc.Type != RESOURCE_DIM_TEX_1D && + TexDesc.Type != RESOURCE_DIM_TEX_1D_ARRAY ) { Uint32 MipHeight = std::max(TexDesc.Height >> MipLevel, 1U); VERIFY_TEX_PARAMS( Box.MaxY <= MipHeight, "Region max Y coordinate (", Box.MaxY, ") is out of allowed range [0, ", MipHeight, "]" ); } - if( TexDesc.Type == TEXTURE_TYPE_3D ) + if( TexDesc.Type == RESOURCE_DIM_TEX_3D ) { Uint32 MipDepth = std::max(TexDesc.Depth >> MipLevel, 1U); VERIFY_TEX_PARAMS( Box.MaxZ <= MipDepth, "Region max Z coordinate (", Box.MaxZ, ") is out of allowed range [0, ", MipDepth, "]" ); } +#endif } void ValidateUpdateDataParams( const TextureDesc &TexDesc, Uint32 MipLevel, Uint32 Slice, const Box &DstBox, const TextureSubResData &SubresData ) @@ -128,13 +141,13 @@ void VliadateCopyTextureDataParams( const TextureDesc &SrcTexDesc, Uint32 SrcMip if( pSrcBox == nullptr ) { SrcBox.MaxX = std::max( SrcTexDesc.Width >> SrcMipLevel, 1u ); - if( SrcTexDesc.Type == TEXTURE_TYPE_1D || - SrcTexDesc.Type == TEXTURE_TYPE_1D_ARRAY ) + if( SrcTexDesc.Type == RESOURCE_DIM_TEX_1D || + SrcTexDesc.Type == RESOURCE_DIM_TEX_1D_ARRAY ) SrcBox.MaxY = 1; else SrcBox.MaxY = std::max( SrcTexDesc.Height >> SrcMipLevel, 1u ); - if( SrcTexDesc.Type == TEXTURE_TYPE_3D ) + if( SrcTexDesc.Type == RESOURCE_DIM_TEX_3D ) SrcBox.MaxZ = std::max( SrcTexDesc.Depth >> SrcMipLevel, 1u ); else SrcBox.MaxZ = 1; diff --git a/Graphics/GraphicsEngine/src/pch.cpp b/Graphics/GraphicsEngine/src/pch.cpp index bf010b17..b2c201a7 100644 --- a/Graphics/GraphicsEngine/src/pch.cpp +++ b/Graphics/GraphicsEngine/src/pch.cpp @@ -1,4 +1,4 @@ -/* Copyright 2015 Egor Yusov +/* Copyright 2015-2016 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. |
