summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineD3D11
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2015-10-21 03:46:28 +0000
committerEgor Yusov <egor.yusov@gmail.com>2015-10-21 03:46:28 +0000
commit9ccee73baca0fd7ecb95c90cb983133b737c6c55 (patch)
tree66fea1e6521df31727431520fe3c1ead1896bc5d /Graphics/GraphicsEngineD3D11
downloadDiligentCore-9ccee73baca0fd7ecb95c90cb983133b737c6c55.tar.gz
DiligentCore-9ccee73baca0fd7ecb95c90cb983133b737c6c55.zip
Release v1.0.0
Diffstat (limited to 'Graphics/GraphicsEngineD3D11')
-rw-r--r--Graphics/GraphicsEngineD3D11/build/Windows/EngineRoot.props22
-rw-r--r--Graphics/GraphicsEngineD3D11/build/Windows/GraphicsEngineD3D11.props10
-rw-r--r--Graphics/GraphicsEngineD3D11/build/Windows/GraphicsEngineD3D11.vcxproj336
-rw-r--r--Graphics/GraphicsEngineD3D11/build/Windows/GraphicsEngineD3D11.vcxproj.filters2
-rw-r--r--Graphics/GraphicsEngineD3D11/build/WindowsStore/EngineRoot.props18
-rw-r--r--Graphics/GraphicsEngineD3D11/build/WindowsStore/GraphicsEngineD3D11.Shared/GraphicsEngineD3D11.Shared.vcxitems89
-rw-r--r--Graphics/GraphicsEngineD3D11/build/WindowsStore/GraphicsEngineD3D11.Shared/GraphicsEngineD3D11.Shared.vcxitems.filters196
-rw-r--r--Graphics/GraphicsEngineD3D11/build/WindowsStore/GraphicsEngineD3D11.Windows/GraphicsEngineD3D11.Windows.vcxproj205
-rw-r--r--Graphics/GraphicsEngineD3D11/build/WindowsStore/GraphicsEngineD3D11.Windows/GraphicsEngineD3D11.Windows.vcxproj.filters2
-rw-r--r--Graphics/GraphicsEngineD3D11/build/WindowsStore/GraphicsEngineD3D11.WindowsPhone/GraphicsEngineD3D11.WindowsPhone.vcxproj144
-rw-r--r--Graphics/GraphicsEngineD3D11/build/WindowsStore/GraphicsEngineD3D11.WindowsPhone/GraphicsEngineD3D11.WindowsPhone.vcxproj.filters2
-rw-r--r--Graphics/GraphicsEngineD3D11/include/BlendStateD3D11Impl.h55
-rw-r--r--Graphics/GraphicsEngineD3D11/include/BufferD3D11Impl.h63
-rw-r--r--Graphics/GraphicsEngineD3D11/include/BufferViewD3D11Impl.h56
-rw-r--r--Graphics/GraphicsEngineD3D11/include/D3D11DebugUtilities.h57
-rw-r--r--Graphics/GraphicsEngineD3D11/include/D3D11TypeConversions.h147
-rw-r--r--Graphics/GraphicsEngineD3D11/include/D3DErrors.h89
-rw-r--r--Graphics/GraphicsEngineD3D11/include/DSStateD3D11Impl.h54
-rw-r--r--Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.h260
-rw-r--r--Graphics/GraphicsEngineD3D11/include/HLSLDefinitions.fxh61
-rw-r--r--Graphics/GraphicsEngineD3D11/include/HLSLDefinitions_inc.fxh61
-rw-r--r--Graphics/GraphicsEngineD3D11/include/RasterizerStateD3D11Impl.h54
-rw-r--r--Graphics/GraphicsEngineD3D11/include/RenderDeviceD3D11Impl.h73
-rw-r--r--Graphics/GraphicsEngineD3D11/include/SamplerD3D11Impl.h55
-rw-r--r--Graphics/GraphicsEngineD3D11/include/ShaderD3D11Impl.h231
-rw-r--r--Graphics/GraphicsEngineD3D11/include/SwapChainD3D11Impl.h66
-rw-r--r--Graphics/GraphicsEngineD3D11/include/Texture1D_D3D11.h47
-rw-r--r--Graphics/GraphicsEngineD3D11/include/Texture2D_D3D11.h47
-rw-r--r--Graphics/GraphicsEngineD3D11/include/Texture3D_D3D11.h47
-rw-r--r--Graphics/GraphicsEngineD3D11/include/TextureBaseD3D11.h81
-rw-r--r--Graphics/GraphicsEngineD3D11/include/TextureViewD3D11Impl.h59
-rw-r--r--Graphics/GraphicsEngineD3D11/include/VertexDescD3D11Impl.h55
-rw-r--r--Graphics/GraphicsEngineD3D11/include/pch.h55
-rw-r--r--Graphics/GraphicsEngineD3D11/include/targetver.h31
-rw-r--r--Graphics/GraphicsEngineD3D11/interface/BlendStateD3D11.h50
-rw-r--r--Graphics/GraphicsEngineD3D11/interface/BufferD3D11.h50
-rw-r--r--Graphics/GraphicsEngineD3D11/interface/BufferViewD3D11.h50
-rw-r--r--Graphics/GraphicsEngineD3D11/interface/DepthStencilStateD3D11.h50
-rw-r--r--Graphics/GraphicsEngineD3D11/interface/DeviceContextD3D11.h50
-rw-r--r--Graphics/GraphicsEngineD3D11/interface/RasterizerStateD3D11.h50
-rw-r--r--Graphics/GraphicsEngineD3D11/interface/RenderDeviceD3D11.h50
-rw-r--r--Graphics/GraphicsEngineD3D11/interface/RenderDeviceFactoryD3D11.h95
-rw-r--r--Graphics/GraphicsEngineD3D11/interface/SamplerD3D11.h50
-rw-r--r--Graphics/GraphicsEngineD3D11/interface/ShaderD3D11.h50
-rw-r--r--Graphics/GraphicsEngineD3D11/interface/SwapChainD3D11.h50
-rw-r--r--Graphics/GraphicsEngineD3D11/interface/TextureD3D11.h50
-rw-r--r--Graphics/GraphicsEngineD3D11/interface/TextureViewD3D11.h50
-rw-r--r--Graphics/GraphicsEngineD3D11/interface/VertexDescriptionD3D11.h50
-rw-r--r--Graphics/GraphicsEngineD3D11/src/BlendStateD3D11Impl.cpp144
-rw-r--r--Graphics/GraphicsEngineD3D11/src/BufferD3D11Impl.cpp237
-rw-r--r--Graphics/GraphicsEngineD3D11/src/BufferViewD3D11Impl.cpp47
-rw-r--r--Graphics/GraphicsEngineD3D11/src/D3D11DebugUtilities.cpp198
-rw-r--r--Graphics/GraphicsEngineD3D11/src/D3D11TypeConversions.cpp504
-rw-r--r--Graphics/GraphicsEngineD3D11/src/DLLMain.cpp49
-rw-r--r--Graphics/GraphicsEngineD3D11/src/DSStateD3D11Impl.cpp66
-rw-r--r--Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp1308
-rw-r--r--Graphics/GraphicsEngineD3D11/src/GraphicsEngineD3D11.def3
-rw-r--r--Graphics/GraphicsEngineD3D11/src/RasterizerStateD3D11Impl.cpp110
-rw-r--r--Graphics/GraphicsEngineD3D11/src/RenderDeviceD3D11Impl.cpp440
-rw-r--r--Graphics/GraphicsEngineD3D11/src/RenderDeviceFactoryD3D11.cpp198
-rw-r--r--Graphics/GraphicsEngineD3D11/src/SamplerD3D11Impl.cpp60
-rw-r--r--Graphics/GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp838
-rw-r--r--Graphics/GraphicsEngineD3D11/src/SwapChainD3D11Impl.cpp254
-rw-r--r--Graphics/GraphicsEngineD3D11/src/Texture1D_D3D11.cpp226
-rw-r--r--Graphics/GraphicsEngineD3D11/src/Texture2D_D3D11.cpp284
-rw-r--r--Graphics/GraphicsEngineD3D11/src/Texture3D_D3D11.cpp154
-rw-r--r--Graphics/GraphicsEngineD3D11/src/TextureBaseD3D11.cpp216
-rw-r--r--Graphics/GraphicsEngineD3D11/src/TextureViewD3D11Impl.cpp61
-rw-r--r--Graphics/GraphicsEngineD3D11/src/VertexDescD3D11Impl.cpp72
-rw-r--r--Graphics/GraphicsEngineD3D11/src/pch.cpp31
70 files changed, 9075 insertions, 0 deletions
diff --git a/Graphics/GraphicsEngineD3D11/build/Windows/EngineRoot.props b/Graphics/GraphicsEngineD3D11/build/Windows/EngineRoot.props
new file mode 100644
index 00000000..02287e9c
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/build/Windows/EngineRoot.props
@@ -0,0 +1,22 @@
+<?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>
+ <ProjectRoot>..\..</ProjectRoot>
+ </PropertyGroup>
+ <PropertyGroup />
+ <ItemDefinitionGroup />
+ <ItemGroup>
+ <BuildMacro Include="EngineRoot">
+ <Value>$(EngineRoot)</Value>
+ </BuildMacro>
+ <BuildMacro Include="GraphicsRoot">
+ <Value>$(GraphicsRoot)</Value>
+ </BuildMacro>
+ <BuildMacro Include="ProjectRoot">
+ <Value>$(ProjectRoot)</Value>
+ </BuildMacro>
+ </ItemGroup>
+</Project> \ No newline at end of file
diff --git a/Graphics/GraphicsEngineD3D11/build/Windows/GraphicsEngineD3D11.props b/Graphics/GraphicsEngineD3D11/build/Windows/GraphicsEngineD3D11.props
new file mode 100644
index 00000000..db23faae
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/build/Windows/GraphicsEngineD3D11.props
@@ -0,0 +1,10 @@
+<?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)\GraphicsEngineD3D11\include;$(GraphicsRoot)\GraphicsEngineD3D11\interface;$(GraphicsRoot)\GraphicsEngine\include;$(GraphicsRoot)\GraphicsEngine\interface;$(GraphicsRoot)\GraphicsTools\include;$(EngineRoot)\Common\include;$(EngineRoot)\Common\interface;$(EngineRoot)\Platforms\interface;$(VC_IncludePath);$(WindowsSDK_IncludePath)</IncludePath>
+ </PropertyGroup>
+ <ItemDefinitionGroup />
+ <ItemGroup />
+</Project> \ No newline at end of file
diff --git a/Graphics/GraphicsEngineD3D11/build/Windows/GraphicsEngineD3D11.vcxproj b/Graphics/GraphicsEngineD3D11/build/Windows/GraphicsEngineD3D11.vcxproj
new file mode 100644
index 00000000..7a6e1ebd
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/build/Windows/GraphicsEngineD3D11.vcxproj
@@ -0,0 +1,336 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="DbgDLL|Win32">
+ <Configuration>DbgDLL</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="DbgDLL|x64">
+ <Configuration>DbgDLL</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Debug|Win32">
+ <Configuration>Debug</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Debug|x64">
+ <Configuration>Debug</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="RelDLL|Win32">
+ <Configuration>RelDLL</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="RelDLL|x64">
+ <Configuration>RelDLL</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|Win32">
+ <Configuration>Release</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|x64">
+ <Configuration>Release</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\..\..\..\Common\build\Windows\Common.vcxproj">
+ <Project>{7380f7e6-315f-4b4e-92eb-e6aeee865298}</Project>
+ </ProjectReference>
+ <ProjectReference Include="..\..\..\..\Platforms\Basic\build\Windows\BasicPlatform.vcxproj">
+ <Project>{8ada5f93-7a38-4ad8-b8f5-1ffd4d4f630c}</Project>
+ </ProjectReference>
+ <ProjectReference Include="..\..\..\..\Platforms\Windows\build\Windows\WindowsPlatform.vcxproj">
+ <Project>{58f32677-436b-412a-bbf8-2b1310d82cd8}</Project>
+ </ProjectReference>
+ <ProjectReference Include="..\..\..\GraphicsEngine\build\Windows\GraphicsEngine.vcxproj">
+ <Project>{052dd700-477c-4512-a7f4-b05ebef5c80e}</Project>
+ </ProjectReference>
+ <ProjectReference Include="..\..\..\GraphicsTools\build\Windows\GraphicsTools.vcxproj">
+ <Project>{c6014499-0cf2-43ec-a773-a4e354fb2d74}</Project>
+ </ProjectReference>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>{FE289CC7-15D6-4A76-B9CB-F61CAB3192C9}</ProjectGuid>
+ <Keyword>Win32Proj</Keyword>
+ <RootNamespace>GraphicsEngineD3D11</RootNamespace>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <CharacterSet>Unicode</CharacterSet>
+ <PlatformToolset>v140</PlatformToolset>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DbgDLL|Win32'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <CharacterSet>Unicode</CharacterSet>
+ <PlatformToolset>v140</PlatformToolset>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <CharacterSet>Unicode</CharacterSet>
+ <PlatformToolset>v140</PlatformToolset>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DbgDLL|x64'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <CharacterSet>Unicode</CharacterSet>
+ <PlatformToolset>v140</PlatformToolset>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>Unicode</CharacterSet>
+ <PlatformToolset>v140</PlatformToolset>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='RelDLL|Win32'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>Unicode</CharacterSet>
+ <PlatformToolset>v140</PlatformToolset>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>Unicode</CharacterSet>
+ <PlatformToolset>v140</PlatformToolset>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='RelDLL|x64'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>Unicode</CharacterSet>
+ <PlatformToolset>v140</PlatformToolset>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ <Import Project="..\WindowsStore\GraphicsEngineD3D11.Shared\GraphicsEngineD3D11.Shared.vcxitems" Label="Shared" Condition="Exists('..\WindowsStore\GraphicsEngineD3D11.Shared\GraphicsEngineD3D11.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="GraphicsEngineD3D11.props" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='DbgDLL|Win32'" 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\Win32d.props" />
+ <Import Project="EngineRoot.props" />
+ <Import Project="GraphicsEngineD3D11.props" />
+ <Import Project="..\..\..\Shared\build\Windows\DLLCommon.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="GraphicsEngineD3D11.props" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='DbgDLL|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="GraphicsEngineD3D11.props" />
+ <Import Project="..\..\..\Shared\build\Windows\DLLCommon.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="GraphicsEngineD3D11.props" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='RelDLL|Win32'" 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\Win32r.props" />
+ <Import Project="EngineRoot.props" />
+ <Import Project="GraphicsEngineD3D11.props" />
+ <Import Project="..\..\..\Shared\build\Windows\DLLCommon.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="GraphicsEngineD3D11.props" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='RelDLL|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="GraphicsEngineD3D11.props" />
+ <Import Project="..\..\..\Shared\build\Windows\DLLCommon.props" />
+ </ImportGroup>
+ <PropertyGroup Label="UserMacros" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <LibraryPath>$(VCInstallDir)lib;$(VCInstallDir)atlmfc\lib;$(WindowsSdkDir)lib;$(FrameworkSDKDir)\lib</LibraryPath>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DbgDLL|Win32'" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <LibraryPath>$(VCInstallDir)lib;$(VCInstallDir)atlmfc\lib;$(WindowsSdkDir)lib;$(FrameworkSDKDir)\lib</LibraryPath>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DbgDLL|x64'" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <LibraryPath>$(VCInstallDir)lib;$(VCInstallDir)atlmfc\lib;$(WindowsSdkDir)lib;$(FrameworkSDKDir)\lib</LibraryPath>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='RelDLL|Win32'" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <LibraryPath>$(VCInstallDir)lib;$(VCInstallDir)atlmfc\lib;$(WindowsSdkDir)lib;$(FrameworkSDKDir)\lib</LibraryPath>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='RelDLL|x64'" />
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <PreprocessorDefinitions>WIN32;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ </ClCompile>
+ <Link>
+ <SubSystem>Windows</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ </Link>
+ <Lib>
+ <AdditionalDependencies>
+ </AdditionalDependencies>
+ </Lib>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='DbgDLL|Win32'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <PreprocessorDefinitions>WIN32;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ </ClCompile>
+ <Link>
+ <SubSystem>Windows</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <AdditionalDependencies>d3d11.lib;d3dcompiler.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <ModuleDefinitionFile>..\..\src\GraphicsEngineD3D11.def</ModuleDefinitionFile>
+ </Link>
+ <Lib>
+ <AdditionalDependencies>
+ </AdditionalDependencies>
+ </Lib>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <PreprocessorDefinitions>WIN32;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ </ClCompile>
+ <Link>
+ <SubSystem>Windows</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ </Link>
+ <Lib>
+ <AdditionalDependencies>
+ </AdditionalDependencies>
+ <TargetMachine>MachineX64</TargetMachine>
+ </Lib>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='DbgDLL|x64'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <PreprocessorDefinitions>WIN32;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ </ClCompile>
+ <Link>
+ <SubSystem>Windows</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <AdditionalDependencies>d3d11.lib;d3dcompiler.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <ModuleDefinitionFile>..\..\src\GraphicsEngineD3D11.def</ModuleDefinitionFile>
+ </Link>
+ <Lib>
+ <AdditionalDependencies>
+ </AdditionalDependencies>
+ <TargetMachine>MachineX64</TargetMachine>
+ </Lib>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <PreprocessorDefinitions>WIN32;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ </ClCompile>
+ <Link>
+ <SubSystem>Windows</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ </Link>
+ <Lib>
+ <AdditionalDependencies>
+ </AdditionalDependencies>
+ </Lib>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='RelDLL|Win32'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <PreprocessorDefinitions>WIN32;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ </ClCompile>
+ <Link>
+ <SubSystem>Windows</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ <AdditionalDependencies>d3d11.lib;d3dcompiler.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <ModuleDefinitionFile>..\..\src\GraphicsEngineD3D11.def</ModuleDefinitionFile>
+ </Link>
+ <Lib>
+ <AdditionalDependencies>
+ </AdditionalDependencies>
+ </Lib>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <PreprocessorDefinitions>WIN32;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ </ClCompile>
+ <Link>
+ <SubSystem>Windows</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ </Link>
+ <Lib>
+ <AdditionalDependencies>
+ </AdditionalDependencies>
+ <TargetMachine>MachineX64</TargetMachine>
+ </Lib>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='RelDLL|x64'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <PreprocessorDefinitions>WIN32;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ </ClCompile>
+ <Link>
+ <SubSystem>Windows</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ <AdditionalDependencies>d3d11.lib;d3dcompiler.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <ModuleDefinitionFile>..\..\src\GraphicsEngineD3D11.def</ModuleDefinitionFile>
+ </Link>
+ <Lib>
+ <AdditionalDependencies>
+ </AdditionalDependencies>
+ <TargetMachine>MachineX64</TargetMachine>
+ </Lib>
+ </ItemDefinitionGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project> \ No newline at end of file
diff --git a/Graphics/GraphicsEngineD3D11/build/Windows/GraphicsEngineD3D11.vcxproj.filters b/Graphics/GraphicsEngineD3D11/build/Windows/GraphicsEngineD3D11.vcxproj.filters
new file mode 100644
index 00000000..9cd85105
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/build/Windows/GraphicsEngineD3D11.vcxproj.filters
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" /> \ No newline at end of file
diff --git a/Graphics/GraphicsEngineD3D11/build/WindowsStore/EngineRoot.props b/Graphics/GraphicsEngineD3D11/build/WindowsStore/EngineRoot.props
new file mode 100644
index 00000000..fcb891c0
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/build/WindowsStore/EngineRoot.props
@@ -0,0 +1,18 @@
+<?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/GraphicsEngineD3D11/build/WindowsStore/GraphicsEngineD3D11.Shared/GraphicsEngineD3D11.Shared.vcxitems b/Graphics/GraphicsEngineD3D11/build/WindowsStore/GraphicsEngineD3D11.Shared/GraphicsEngineD3D11.Shared.vcxitems
new file mode 100644
index 00000000..0850b1e0
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/build/WindowsStore/GraphicsEngineD3D11.Shared/GraphicsEngineD3D11.Shared.vcxitems
@@ -0,0 +1,89 @@
+<?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>{3c22010c-99f3-4321-8f55-36da8f97a980}</ItemsProjectGuid>
+ <ItemsRootNamespace>GraphicsEngineD3D11</ItemsRootNamespace>
+ <ItemsProjectName>GraphicsEngineD3D11.Shared</ItemsProjectName>
+ <CodeSharingProject>248F659F-DAC5-46E8-AC09-60EC9FC95053</CodeSharingProject>
+ </PropertyGroup>
+ <ItemDefinitionGroup>
+ <ClCompile>
+ <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory)</AdditionalIncludeDirectories>
+ </ClCompile>
+ </ItemDefinitionGroup>
+ <ItemGroup>
+ <ProjectCapability Include="SourceItemsFromImports" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\BlendStateD3D11Impl.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\BufferD3D11Impl.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\BufferViewD3D11Impl.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\D3DErrors.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\D3D11DebugUtilities.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\D3D11TypeConversions.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\DeviceContextD3D11Impl.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\DSStateD3D11Impl.h" />
+ <CustomBuild Include="$(MSBuildThisFileDirectory)..\..\..\include\HLSLDefinitions.fxh">
+ <FileType>CppHeader</FileType>
+ <Command>$(EngineRoot)\Utilities\File2Include\File2String.exe %(FullPath) $(ProjectRoot)\include\%(Filename)_inc.fxh</Command>
+ <Outputs>$(ProjectRoot)\include\%(Filename)_inc.h</Outputs>
+ </CustomBuild>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\RasterizerStateD3D11Impl.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\RenderDeviceD3D11Impl.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\SamplerD3D11Impl.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\ShaderD3D11Impl.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\pch.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\SwapChainD3D11Impl.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\targetver.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\Texture1D_D3D11.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\Texture2D_D3D11.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\Texture3D_D3D11.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\TextureBaseD3D11.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\TextureViewD3D11Impl.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\VertexDescD3D11Impl.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\BlendStateD3D11.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\BufferD3D11.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\BufferViewD3D11.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\DepthStencilStateD3D11.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\DeviceContextD3D11.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\RasterizerStateD3D11.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\RenderDeviceD3D11.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\RenderDeviceFactoryD3D11.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\SamplerD3D11.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\ShaderD3D11.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\SwapChainD3D11.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\TextureD3D11.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\TextureViewD3D11.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\VertexDescriptionD3D11.h" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\BlendStateD3D11Impl.cpp" />
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\BufferD3D11Impl.cpp" />
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\BufferViewD3D11Impl.cpp" />
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\D3D11DebugUtilities.cpp" />
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\D3D11TypeConversions.cpp" />
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\DeviceContextD3D11Impl.cpp" />
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\DLLMain.cpp" />
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\DSStateD3D11Impl.cpp" />
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\RasterizerStateD3D11Impl.cpp" />
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\RenderDeviceD3D11Impl.cpp" />
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\RenderDeviceFactoryD3D11.cpp" />
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\SamplerD3D11Impl.cpp" />
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\ShaderD3D11Impl.cpp" />
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\pch.cpp">
+ <PrecompiledHeader>Create</PrecompiledHeader>
+ </ClCompile>
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\SwapChainD3D11Impl.cpp" />
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\Texture1D_D3D11.cpp" />
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\Texture2D_D3D11.cpp" />
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\Texture3D_D3D11.cpp" />
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\TextureBaseD3D11.cpp" />
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\TextureViewD3D11Impl.cpp" />
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\VertexDescD3D11Impl.cpp" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="$(MSBuildThisFileDirectory)..\..\..\src\GraphicsEngineD3D11.def" />
+ </ItemGroup>
+</Project> \ No newline at end of file
diff --git a/Graphics/GraphicsEngineD3D11/build/WindowsStore/GraphicsEngineD3D11.Shared/GraphicsEngineD3D11.Shared.vcxitems.filters b/Graphics/GraphicsEngineD3D11/build/WindowsStore/GraphicsEngineD3D11.Shared/GraphicsEngineD3D11.Shared.vcxitems.filters
new file mode 100644
index 00000000..dd1617f1
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/build/WindowsStore/GraphicsEngineD3D11.Shared/GraphicsEngineD3D11.Shared.vcxitems.filters
@@ -0,0 +1,196 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup>
+ <Filter Include="src">
+ <UniqueIdentifier>{326ec87b-f6ab-4291-a28f-631b2b240d3a}</UniqueIdentifier>
+ </Filter>
+ <Filter Include="include">
+ <UniqueIdentifier>{a12cf1d4-8cb0-4360-898a-d69d16e288c5}</UniqueIdentifier>
+ </Filter>
+ <Filter Include="interface">
+ <UniqueIdentifier>{e3e50068-d75b-4663-bee9-5ca137971e89}</UniqueIdentifier>
+ </Filter>
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\DepthStencilStateD3D11.h">
+ <Filter>interface</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\DeviceContextD3D11.h">
+ <Filter>interface</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\RasterizerStateD3D11.h">
+ <Filter>interface</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\RenderDeviceD3D11.h">
+ <Filter>interface</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\RenderDeviceFactoryD3D11.h">
+ <Filter>interface</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\SamplerD3D11.h">
+ <Filter>interface</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\ShaderD3D11.h">
+ <Filter>interface</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\TextureD3D11.h">
+ <Filter>interface</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\TextureViewD3D11.h">
+ <Filter>interface</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\VertexDescriptionD3D11.h">
+ <Filter>interface</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\BlendStateD3D11.h">
+ <Filter>interface</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\BufferD3D11.h">
+ <Filter>interface</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\BufferViewD3D11.h">
+ <Filter>interface</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\DSStateD3D11Impl.h">
+ <Filter>include</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\RasterizerStateD3D11Impl.h">
+ <Filter>include</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\RenderDeviceD3D11Impl.h">
+ <Filter>include</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\SamplerD3D11Impl.h">
+ <Filter>include</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\ShaderD3D11Impl.h">
+ <Filter>include</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\Texture1D_D3D11.h">
+ <Filter>include</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\Texture2D_D3D11.h">
+ <Filter>include</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\Texture3D_D3D11.h">
+ <Filter>include</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\TextureBaseD3D11.h">
+ <Filter>include</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\TextureViewD3D11Impl.h">
+ <Filter>include</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\VertexDescD3D11Impl.h">
+ <Filter>include</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\BlendStateD3D11Impl.h">
+ <Filter>include</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\BufferD3D11Impl.h">
+ <Filter>include</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\BufferViewD3D11Impl.h">
+ <Filter>include</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\D3D11TypeConversions.h">
+ <Filter>include</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\DeviceContextD3D11Impl.h">
+ <Filter>include</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\pch.h">
+ <Filter>include</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\interface\SwapChainD3D11.h">
+ <Filter>interface</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\SwapChainD3D11Impl.h">
+ <Filter>include</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\targetver.h">
+ <Filter>include</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\D3D11DebugUtilities.h">
+ <Filter>include</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\include\D3DErrors.h">
+ <Filter>include</Filter>
+ </ClInclude>
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\RenderDeviceD3D11Impl.cpp">
+ <Filter>src</Filter>
+ </ClCompile>
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\SamplerD3D11Impl.cpp">
+ <Filter>src</Filter>
+ </ClCompile>
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\ShaderD3D11Impl.cpp">
+ <Filter>src</Filter>
+ </ClCompile>
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\Texture1D_D3D11.cpp">
+ <Filter>src</Filter>
+ </ClCompile>
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\Texture2D_D3D11.cpp">
+ <Filter>src</Filter>
+ </ClCompile>
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\Texture3D_D3D11.cpp">
+ <Filter>src</Filter>
+ </ClCompile>
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\TextureBaseD3D11.cpp">
+ <Filter>src</Filter>
+ </ClCompile>
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\TextureViewD3D11Impl.cpp">
+ <Filter>src</Filter>
+ </ClCompile>
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\VertexDescD3D11Impl.cpp">
+ <Filter>src</Filter>
+ </ClCompile>
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\BlendStateD3D11Impl.cpp">
+ <Filter>src</Filter>
+ </ClCompile>
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\BufferD3D11Impl.cpp">
+ <Filter>src</Filter>
+ </ClCompile>
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\BufferViewD3D11Impl.cpp">
+ <Filter>src</Filter>
+ </ClCompile>
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\D3D11TypeConversions.cpp">
+ <Filter>src</Filter>
+ </ClCompile>
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\DeviceContextD3D11Impl.cpp">
+ <Filter>src</Filter>
+ </ClCompile>
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\DSStateD3D11Impl.cpp">
+ <Filter>src</Filter>
+ </ClCompile>
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\RasterizerStateD3D11Impl.cpp">
+ <Filter>src</Filter>
+ </ClCompile>
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\pch.cpp">
+ <Filter>src</Filter>
+ </ClCompile>
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\SwapChainD3D11Impl.cpp">
+ <Filter>src</Filter>
+ </ClCompile>
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\RenderDeviceFactoryD3D11.cpp">
+ <Filter>src</Filter>
+ </ClCompile>
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\D3D11DebugUtilities.cpp">
+ <Filter>src</Filter>
+ </ClCompile>
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\src\DLLMain.cpp">
+ <Filter>src</Filter>
+ </ClCompile>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="$(MSBuildThisFileDirectory)..\..\..\src\GraphicsEngineD3D11.def">
+ <Filter>src</Filter>
+ </None>
+ </ItemGroup>
+ <ItemGroup>
+ <CustomBuild Include="$(MSBuildThisFileDirectory)..\..\..\include\HLSLDefinitions.fxh">
+ <Filter>include</Filter>
+ </CustomBuild>
+ </ItemGroup>
+</Project> \ No newline at end of file
diff --git a/Graphics/GraphicsEngineD3D11/build/WindowsStore/GraphicsEngineD3D11.Windows/GraphicsEngineD3D11.Windows.vcxproj b/Graphics/GraphicsEngineD3D11/build/WindowsStore/GraphicsEngineD3D11.Windows/GraphicsEngineD3D11.Windows.vcxproj
new file mode 100644
index 00000000..095b7883
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/build/WindowsStore/GraphicsEngineD3D11.Windows/GraphicsEngineD3D11.Windows.vcxproj
@@ -0,0 +1,205 @@
+<?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="Debug|x64">
+ <Configuration>Debug</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|ARM">
+ <Configuration>Release</Configuration>
+ <Platform>ARM</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|Win32">
+ <Configuration>Release</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|x64">
+ <Configuration>Release</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>{3838fd2b-3c87-4caf-95de-95e7c3947c26}</ProjectGuid>
+ <RootNamespace>GraphicsEngineD3D11</RootNamespace>
+ <DefaultLanguage>en-US</DefaultLanguage>
+ <MinimumVisualStudioVersion>12.0</MinimumVisualStudioVersion>
+ <AppContainerApplication>true</AppContainerApplication>
+ <ApplicationType>Windows Store</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</PlatformToolset>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v120</PlatformToolset>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v120</PlatformToolset>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <PlatformToolset>v120</PlatformToolset>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <PlatformToolset>v120</PlatformToolset>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <PlatformToolset>v120</PlatformToolset>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <Import Project="..\GraphicsEngineD3D11.Shared\GraphicsEngineD3D11.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\GraphicsEngineD3D11.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\GraphicsEngineD3D11.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\GraphicsEngineD3D11.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\GraphicsEngineD3D11.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\GraphicsEngineD3D11.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\GraphicsEngineD3D11.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>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <GenerateManifest>false</GenerateManifest>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <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>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <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|x64'">
+ <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/GraphicsEngineD3D11/build/WindowsStore/GraphicsEngineD3D11.Windows/GraphicsEngineD3D11.Windows.vcxproj.filters b/Graphics/GraphicsEngineD3D11/build/WindowsStore/GraphicsEngineD3D11.Windows/GraphicsEngineD3D11.Windows.vcxproj.filters
new file mode 100644
index 00000000..4228787f
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/build/WindowsStore/GraphicsEngineD3D11.Windows/GraphicsEngineD3D11.Windows.vcxproj.filters
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" /> \ No newline at end of file
diff --git a/Graphics/GraphicsEngineD3D11/build/WindowsStore/GraphicsEngineD3D11.WindowsPhone/GraphicsEngineD3D11.WindowsPhone.vcxproj b/Graphics/GraphicsEngineD3D11/build/WindowsStore/GraphicsEngineD3D11.WindowsPhone/GraphicsEngineD3D11.WindowsPhone.vcxproj
new file mode 100644
index 00000000..37889180
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/build/WindowsStore/GraphicsEngineD3D11.WindowsPhone/GraphicsEngineD3D11.WindowsPhone.vcxproj
@@ -0,0 +1,144 @@
+<?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>{581c72cf-7f31-4eba-8f6e-743ca5774742}</ProjectGuid>
+ <RootNamespace>GraphicsEngineD3D11</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="..\GraphicsEngineD3D11.Shared\GraphicsEngineD3D11.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\GraphicsEngineD3D11.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\GraphicsEngineD3D11.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\GraphicsEngineD3D11.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\GraphicsEngineD3D11.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/GraphicsEngineD3D11/build/WindowsStore/GraphicsEngineD3D11.WindowsPhone/GraphicsEngineD3D11.WindowsPhone.vcxproj.filters b/Graphics/GraphicsEngineD3D11/build/WindowsStore/GraphicsEngineD3D11.WindowsPhone/GraphicsEngineD3D11.WindowsPhone.vcxproj.filters
new file mode 100644
index 00000000..4228787f
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/build/WindowsStore/GraphicsEngineD3D11.WindowsPhone/GraphicsEngineD3D11.WindowsPhone.vcxproj.filters
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" /> \ No newline at end of file
diff --git a/Graphics/GraphicsEngineD3D11/include/BlendStateD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/BlendStateD3D11Impl.h
new file mode 100644
index 00000000..9bfc8af2
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/include/BlendStateD3D11Impl.h
@@ -0,0 +1,55 @@
+/* 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
+/// Declaration of Diligent::BlendStateD3D11Impl class
+
+#include "BlendStateD3D11.h"
+#include "RenderDeviceD3D11.h"
+#include "BlendStateBase.h"
+
+namespace Diligent
+{
+
+/// Implementation of the Diligent::IBlendStateD3D11 interface
+class BlendStateD3D11Impl : public BlendStateBase<IBlendStateD3D11, IRenderDeviceD3D11>
+{
+public:
+ typedef BlendStateBase<IBlendStateD3D11, IRenderDeviceD3D11 > TBlendStateBase;
+
+ BlendStateD3D11Impl(class RenderDeviceD3D11Impl *pDeviceD3D11, const BlendStateDesc& BuffDesc);
+ ~BlendStateD3D11Impl();
+
+ virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface );
+
+ /// Implementation of the IBlendStateD3D11::GetD3D11BlendState() method.
+ ID3D11BlendState *GetD3D11BlendState(){ return m_pd3d11BlendState; }
+
+private:
+ /// D3D11 Blend state object
+ Diligent::CComPtr<ID3D11BlendState> m_pd3d11BlendState;
+};
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/include/BufferD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/BufferD3D11Impl.h
new file mode 100644
index 00000000..190599cd
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/include/BufferD3D11Impl.h
@@ -0,0 +1,63 @@
+/* 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
+/// Declaration of Diligent::BufferD3D11Impl class
+
+#include "BufferD3D11.h"
+#include "RenderDeviceD3D11.h"
+#include "BufferBase.h"
+#include "BufferViewD3D11Impl.h"
+
+namespace Diligent
+{
+
+/// Implementation of the Diligent::IBufferD3D11 interface
+class BufferD3D11Impl : public BufferBase<IBufferD3D11, BufferViewD3D11Impl>
+{
+public:
+ typedef BufferBase<IBufferD3D11, BufferViewD3D11Impl> TBufferBase;
+ BufferD3D11Impl(class RenderDeviceD3D11Impl *pDeviceD3D11, const BufferDesc& BuffDesc, const BufferData &BuffData = BufferData());
+ ~BufferD3D11Impl();
+
+ virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )override;
+
+ virtual void UpdateData( IDeviceContext *pContext, Uint32 Offset, Uint32 Size, const PVoid pData )override;
+ virtual void CopyData( IDeviceContext *pContext, IBuffer *pSrcBuffer, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size )override;
+ virtual void Map( IDeviceContext *pContext, MAP_TYPE MapType, Uint32 MapFlags, PVoid &pMappedData )override;
+ virtual void Unmap( IDeviceContext *pContext )override;
+ virtual ID3D11Buffer *GetD3D11Buffer()override{ return m_pd3d11Buffer; }
+
+private:
+ virtual void CreateViewInternal( const struct BufferViewDesc &ViewDesc, IBufferView **ppView, bool bIsDefaultView )override;
+
+ void CreateUAV( struct BufferViewDesc &UAVDesc, ID3D11UnorderedAccessView **ppD3D11UAV );
+ void CreateSRV( struct BufferViewDesc &SRVDesc, ID3D11ShaderResourceView **ppD3D11SRV );
+
+ friend class DeviceContextD3D11Impl;
+ Diligent::CComPtr<ID3D11Buffer> m_pd3d11Buffer; ///< D3D11 buffer object
+};
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/include/BufferViewD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/BufferViewD3D11Impl.h
new file mode 100644
index 00000000..37308ae9
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/include/BufferViewD3D11Impl.h
@@ -0,0 +1,56 @@
+/* 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
+/// Declaration of Diligent::BufferViewD3D11Impl class
+
+#include "BufferViewD3D11.h"
+#include "RenderDeviceD3D11.h"
+#include "BufferViewBase.h"
+
+namespace Diligent
+{
+
+/// Implementation of the Diligent::IBufferViewD3D11 interface
+class BufferViewD3D11Impl : public BufferViewBase<IBufferViewD3D11>
+{
+public:
+ typedef BufferViewBase<IBufferViewD3D11> TBufferViewBase;
+
+ BufferViewD3D11Impl( IRenderDevice *pDevice,
+ const BufferViewDesc& ViewDesc,
+ class IBuffer *pBuffer,
+ ID3D11View* pD3D11View,
+ bool bIsDefaultView);
+
+ virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface );
+
+ virtual ID3D11View* GetD3D11View();
+
+protected:
+ Diligent::CComPtr<ID3D11View> m_pD3D11View; ///<D3D11 view
+};
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/include/D3D11DebugUtilities.h b/Graphics/GraphicsEngineD3D11/include/D3D11DebugUtilities.h
new file mode 100644
index 00000000..1becfb17
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/include/D3D11DebugUtilities.h
@@ -0,0 +1,57 @@
+/* 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
+/// Debug utilities
+
+#include "DeviceObject.h"
+#include "ShaderD3D11Impl.h"
+
+#ifdef _DEBUG
+# define VERIFY_RESOURCE_ARRAYS
+#endif
+
+namespace Diligent
+{
+#ifdef VERIFY_RESOURCE_ARRAYS
+
+ /// Debug function that verifies that cached engine objects and d3d11 shader resource views in two provided arrays are consistent
+ void dbgVerifyResourceArrays( const std::vector< ShaderD3D11Impl::BoundSRV > &SRVs, const std::vector<ID3D11ShaderResourceView*> d3d11SRVs, IShader *pShader );
+
+ /// Debug function that verifies that cached engine objects and d3d11 unordered access views in two provided arrays are consistent
+ void dbgVerifyResourceArrays( const std::vector< ShaderD3D11Impl::BoundUAV > &UAVs, const std::vector<ID3D11UnorderedAccessView*> d3d11UAVs, IShader *pShader );
+
+ /// Debug function that verifies that cached engine objects and d3d11 constant buffers in two provided arrays are consistent
+ void dbgVerifyResourceArrays( const std::vector< ShaderD3D11Impl::BoundCB > &CBs, const std::vector<ID3D11Buffer*> d3d11CBs, IShader *pShader );
+
+ /// Debug function that verifies that cached engine objects and d3d11 samplers in two provided arrays are consistent
+ void dbgVerifyResourceArrays( const std::vector< ShaderD3D11Impl::BoundSampler >&Samplers, const std::vector<ID3D11SamplerState*> d3d11Samplers, IShader *pShader );
+
+#else
+
+ #define dbgVerifyResourceArrays(...)
+
+#endif
+}
diff --git a/Graphics/GraphicsEngineD3D11/include/D3D11TypeConversions.h b/Graphics/GraphicsEngineD3D11/include/D3D11TypeConversions.h
new file mode 100644
index 00000000..ddc76591
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/include/D3D11TypeConversions.h
@@ -0,0 +1,147 @@
+/* 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
+/// Type conversion routines
+
+#include "GraphicsTypes.h"
+
+namespace Diligent
+{
+
+inline UINT BindFlagsToD3D11BindFlags(Uint32 BindFlags)
+{
+ UINT D3D11BindFlags = 0;
+ D3D11BindFlags = D3D11BindFlags | ((BindFlags & BIND_VERTEX_BUFFER) ? D3D11_BIND_VERTEX_BUFFER : 0);
+ D3D11BindFlags = D3D11BindFlags | ((BindFlags & BIND_INDEX_BUFFER) ? D3D11_BIND_INDEX_BUFFER : 0);
+ D3D11BindFlags = D3D11BindFlags | ((BindFlags & BIND_UNIFORM_BUFFER) ? D3D11_BIND_CONSTANT_BUFFER : 0);
+ D3D11BindFlags = D3D11BindFlags | ((BindFlags & BIND_SHADER_RESOURCE) ? D3D11_BIND_SHADER_RESOURCE : 0);
+ D3D11BindFlags = D3D11BindFlags | ((BindFlags & BIND_STREAM_OUTPUT) ? D3D11_BIND_STREAM_OUTPUT : 0);
+ D3D11BindFlags = D3D11BindFlags | ((BindFlags & BIND_RENDER_TARGET) ? D3D11_BIND_RENDER_TARGET : 0);
+ D3D11BindFlags = D3D11BindFlags | ((BindFlags & BIND_DEPTH_STENCIL) ? D3D11_BIND_DEPTH_STENCIL : 0);
+ D3D11BindFlags = D3D11BindFlags | ((BindFlags & BIND_UNORDERED_ACCESS) ? D3D11_BIND_UNORDERED_ACCESS : 0);
+ return D3D11BindFlags;
+}
+
+inline D3D11_PRIMITIVE_TOPOLOGY TopologyToDX11Topology(PRIMITIVE_TOPOLOGY Topology)
+{
+ switch( Topology )
+ {
+ case PRIMITIVE_TOPOLOGY_UNDEFINED: return D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED;
+ case PRIMITIVE_TOPOLOGY_TRIANGLE_LIST: return D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
+ case PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP: return D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP;
+ case PRIMITIVE_TOPOLOGY_POINT_LIST: return D3D11_PRIMITIVE_TOPOLOGY_POINTLIST;
+ case PRIMITIVE_TOPOLOGY_LINE_LIST: return D3D11_PRIMITIVE_TOPOLOGY_LINELIST;
+ default: UNEXPECTED("Unsupported primitive topology" ); return D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED;
+ }
+}
+
+DXGI_FORMAT TypeToDXGI_Format(VALUE_TYPE ValType, Uint32 NumComponents, Bool bIsNormalized);
+
+DXGI_FORMAT TexFormatToDXGI_Format(TEXTURE_FORMAT TexFormat, Uint32 BindFlags = 0);
+
+inline D3D11_USAGE UsageToD3D11Usage(USAGE Usage)
+{
+ switch(Usage)
+ {
+ case USAGE_STATIC: return D3D11_USAGE_IMMUTABLE;
+ case USAGE_DEFAULT: return D3D11_USAGE_DEFAULT;
+ case USAGE_DYNAMIC: return D3D11_USAGE_DYNAMIC;
+ case USAGE_CPU_ACCESSIBLE: return D3D11_USAGE_STAGING;
+ default: UNEXPECTED("Unknow usage" ); return D3D11_USAGE_DEFAULT;
+ }
+}
+
+inline D3D11_MAP MapTypeToD3D11MapType(MAP_TYPE MapType)
+{
+ switch(MapType)
+ {
+ case MAP_READ: return D3D11_MAP_READ;
+ case MAP_WRITE: return D3D11_MAP_WRITE;
+ case MAP_READ_WRITE: return D3D11_MAP_READ_WRITE;
+ case MAP_WRITE_DISCARD: return D3D11_MAP_WRITE_DISCARD;
+ case MAP_WRITE_NO_OVERWRITE:return D3D11_MAP_WRITE_NO_OVERWRITE;
+ default: UNEXPECTED( "Unknown map type" ); return D3D11_MAP_READ;
+ }
+}
+
+inline UINT MapFlagsToD3D11MapFlags(Uint32 MapFlags)
+{
+ UINT D3D11MapFlags = 0;
+ D3D11MapFlags |= (MapFlags & MAP_FLAG_DO_NOT_WAIT) ? D3D11_MAP_FLAG_DO_NOT_WAIT : 0;
+ return D3D11MapFlags;
+}
+
+inline UINT CPUAccessFlagsToD3D11CPUAccessFlags(Uint32 Flags)
+{
+ UINT D3D11CPUAccessFlags = 0;
+ D3D11CPUAccessFlags |= (Flags & CPU_ACCESS_READ) ? D3D11_CPU_ACCESS_READ : 0;
+ D3D11CPUAccessFlags |= (Flags & CPU_ACCESS_WRITE) ? D3D11_CPU_ACCESS_WRITE : 0;
+ return D3D11CPUAccessFlags;
+}
+
+inline UINT MiscTextureFlagsToD3D11Flags(Uint32 Flags)
+{
+ UINT D3D11MiscFlags = 0;
+ D3D11MiscFlags |= (Flags & MISC_TEXTURE_FLAG_GENERATE_MIPS) ? D3D11_RESOURCE_MISC_GENERATE_MIPS : 0;
+ return D3D11MiscFlags;
+}
+
+D3D11_FILTER FilterTypeToD3D11Filter(FILTER_TYPE MinFilter, FILTER_TYPE MagFilter, FILTER_TYPE MipFilter);
+
+inline D3D11_TEXTURE_ADDRESS_MODE TexAddressModeToD3D11AddressMode(TEXTURE_ADDRESS_MODE Mode)
+{
+ switch(Mode)
+ {
+ case TEXTURE_ADDRESS_UNKNOWN: UNEXPECTED("Texture address mode is not specified" ); return D3D11_TEXTURE_ADDRESS_CLAMP;
+ case TEXTURE_ADDRESS_WRAP: return D3D11_TEXTURE_ADDRESS_WRAP;
+ case TEXTURE_ADDRESS_MIRROR: return D3D11_TEXTURE_ADDRESS_MIRROR;
+ case TEXTURE_ADDRESS_CLAMP: return D3D11_TEXTURE_ADDRESS_CLAMP;
+ case TEXTURE_ADDRESS_BORDER: return D3D11_TEXTURE_ADDRESS_BORDER;
+ case TEXTURE_ADDRESS_MIRROR_ONCE: return D3D11_TEXTURE_ADDRESS_MIRROR_ONCE;
+ default: UNEXPECTED("Unknown texture address mode" ); return D3D11_TEXTURE_ADDRESS_CLAMP;
+ }
+}
+
+inline D3D11_COMPARISON_FUNC ComparisonFuncToD3D11ComparisonFunc(COMPARISON_FUNCTION Func)
+{
+ switch(Func)
+ {
+ case COMPARISON_FUNC_UNKNOW: UNEXPECTED("Comparison function is not specified" ); return D3D11_COMPARISON_ALWAYS;
+ case COMPARISON_FUNC_NEVER: return D3D11_COMPARISON_NEVER;
+ case COMPARISON_FUNC_LESS: return D3D11_COMPARISON_LESS;
+ case COMPARISON_FUNC_EQUAL: return D3D11_COMPARISON_EQUAL;
+ case COMPARISON_FUNC_LESS_EQUAL: return D3D11_COMPARISON_LESS_EQUAL;
+ case COMPARISON_FUNC_GREATER: return D3D11_COMPARISON_GREATER;
+ case COMPARISON_FUNC_NOT_EQUAL: return D3D11_COMPARISON_NOT_EQUAL;
+ case COMPARISON_FUNC_GREATER_EQUAL: return D3D11_COMPARISON_GREATER_EQUAL;
+ case COMPARISON_FUNC_ALWAYS: return D3D11_COMPARISON_ALWAYS;
+ default: UNEXPECTED("Unknown comparison function" ); return D3D11_COMPARISON_ALWAYS;
+ }
+}
+
+D3D11_STENCIL_OP StencilOpToD3D11StencilOp( STENCIL_OP );
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/include/D3DErrors.h b/Graphics/GraphicsEngineD3D11/include/D3DErrors.h
new file mode 100644
index 00000000..00029230
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/include/D3DErrors.h
@@ -0,0 +1,89 @@
+/* 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
+
+#include "Errors.h"
+
+/// \file
+/// Declaration of Diligent::ComErrorDesc class
+
+namespace Diligent
+{
+
+/// Helper class that provides description of a COM error
+class ComErrorDesc
+{
+public:
+ ComErrorDesc( HRESULT hr )
+ {
+ FormatMessageA(
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ hr,
+ MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ),
+ m_Msg,
+ _countof(m_Msg),
+ NULL );
+ auto nLen = strlen( m_Msg );
+ if( nLen > 1 && m_Msg[nLen - 1] == '\n' )
+ {
+ m_Msg[nLen - 1] = 0;
+ if( m_Msg[nLen - 2] == '\r' )
+ {
+ m_Msg[nLen - 2] = 0;
+ }
+ }
+ }
+
+ const char* Get(){ return m_Msg; }
+
+private:
+ char m_Msg[4096];
+};
+
+}
+
+
+#define CHECK_D3D_RESULT_THROW(Expr, Message)\
+{ \
+ HRESULT _hr_ = Expr; \
+ if(FAILED(_hr_)) \
+ { \
+ ComErrorDesc ErrDesc( _hr_ ); \
+ LOG_ERROR_AND_THROW( Message, "\nHRESULT Desc: ", ErrDesc.Get());\
+ } \
+}
+
+#define CHECK_D3D_RESULT_THROW_EX(Expr, ...)\
+{ \
+ HRESULT _hr_ = Expr; \
+ if(FAILED(_hr_)) \
+ { \
+ Diligent::MsgStream ms; \
+ Diligent::FormatMsg(ms, __VA_ARGS__); \
+ ComErrorDesc ErrDesc( _hr_ ); \
+ LOG_ERROR_AND_THROW( ms.str(), "\nHRESULT Desc: ", ErrDesc.Get());\
+ } \
+}
diff --git a/Graphics/GraphicsEngineD3D11/include/DSStateD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/DSStateD3D11Impl.h
new file mode 100644
index 00000000..55aaa2ce
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/include/DSStateD3D11Impl.h
@@ -0,0 +1,54 @@
+/* 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
+/// Declaration of Diligent::DSStateD3D11Impl class
+
+#include "DepthStencilStateD3D11.h"
+#include "RenderDeviceD3D11.h"
+#include "DepthStencilStateBase.h"
+
+namespace Diligent
+{
+
+/// Implementation of the Diligent::IDepthStencilStateD3D11 interface
+class DSStateD3D11Impl : public DepthStencilStateBase<IDepthStencilStateD3D11, IRenderDeviceD3D11 >
+{
+public:
+ typedef DepthStencilStateBase<IDepthStencilStateD3D11, IRenderDeviceD3D11 > TDepthStencilStateBase;
+
+ DSStateD3D11Impl(class RenderDeviceD3D11Impl *pDeviceD3D11, const DepthStencilStateDesc& BuffDesc);
+ ~DSStateD3D11Impl();
+
+ virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface );
+
+ ID3D11DepthStencilState *GetD3D11DepthStencilState(){ return m_pd3d11DepthStencilState; }
+
+private:
+ /// D3D11 depth-stencil state
+ Diligent::CComPtr<ID3D11DepthStencilState> m_pd3d11DepthStencilState;
+};
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.h
new file mode 100644
index 00000000..a4102db6
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.h
@@ -0,0 +1,260 @@
+/* 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
+/// Declaration of Diligent::DeviceContextD3D11Impl class
+
+#include "DeviceContextD3D11.h"
+#include "DeviceContextBase.h"
+#include "ShaderD3D11Impl.h"
+
+#ifdef _DEBUG
+# define VERIFY_CONTEXT_BINDINGS
+#endif
+
+namespace Diligent
+{
+
+/// Implementation of the Diligent::IDeviceContextD3D11 interface
+class DeviceContextD3D11Impl : public DeviceContextBase<IDeviceContextD3D11>
+{
+public:
+ typedef DeviceContextBase<IDeviceContextD3D11> TDeviceContextBase;
+
+ DeviceContextD3D11Impl(IRenderDevice *pDevice, ID3D11DeviceContext *pd3d11DeviceContext);
+ virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )override;
+
+ virtual void SetShaders( IShader **ppShaders, Uint32 NumShadersToSet )override;
+
+ virtual void BindShaderResources( IResourceMapping *pResourceMapping, Uint32 Flags )override;
+
+ virtual void SetVertexBuffers( Uint32 StartSlot, Uint32 NumBuffersSet, IBuffer **ppBuffers, Uint32 *pStrides, Uint32 *pOffsets, Uint32 Flags )override;
+ virtual void ClearState()override;
+
+ virtual void SetVertexDescription( IVertexDescription *pVertexDesc )override;
+
+ virtual void SetIndexBuffer( IBuffer *pIndexBuffer, Uint32 ByteOffset )override;
+
+ virtual void SetDepthStencilState( IDepthStencilState *pDepthStencilState, Uint32 StencilRef = 0 )override;
+
+ virtual void SetRasterizerState( IRasterizerState *pRS )override;
+
+ virtual void SetBlendState( IBlendState *pBS, const float* pBlendFactors, Uint32 SampleMask )override;
+
+ virtual void SetViewports( Uint32 NumViewports, const Viewport *pViewports, Uint32 RTWidth, Uint32 RTHeight )override;
+
+ virtual void SetScissorRects( Uint32 NumRects, const Rect *pRects, Uint32 RTWidth, Uint32 RTHeight )override;
+
+ virtual void SetRenderTargets( Uint32 NumRenderTargets, ITextureView *ppRenderTargets[], ITextureView *pDepthStencil )override;
+
+ virtual void Draw( DrawAttribs &DrawAttribs )override;
+
+ virtual void DispatchCompute( const DispatchComputeAttribs &DispatchAttrs )override;
+
+ virtual void ClearDepthStencil( ITextureView *pView, Uint32 ClearFlags, float fDepth, Uint8 Stencil)override;
+
+ virtual void ClearRenderTarget( ITextureView *pView, const float *RGBA )override;
+
+ virtual void Flush()override;
+
+ ID3D11DeviceContext* GetD3D11DeviceContext(){ return m_pd3d11DeviceContext; }
+
+ void RebindRenderTargets();
+
+ /// Clears the state caches. This function is called once per frame
+ /// (before present) to release all outstanding objects
+ /// that are only kept alive by references in the cache
+ void ClearShaderStateCache();
+
+ /// Number of different shader types (Vertex, Pixel, Geometry, Domain, Hull, Compute)
+ static const int NumShaderTypes = 6;
+
+private:
+
+ /// Goes through the list of bound shaders and binds all required
+ /// d3d11 resource to the d3d11 device context, for each shader.
+ void SetD3DShadersAndResources();
+
+ /// Binds d3d11 index buffer to the d3d11 device context.
+ void SetD3DIndexBuffer(VALUE_TYPE IndexType);
+
+ /// Binds d3d11 vertex buffers to the d3d11 device context.
+ void SetD3DVertexBuffers();
+
+ /// Binds d3d11 constant buffers to the d3d11 device context
+ void SetD3DConstantBuffers ( class ShaderD3D11Impl *pShader );
+ /// Binds d3d11 shader resource views to the d3d11 device context
+ void SetD3DSRVs ( class ShaderD3D11Impl *pShader );
+ /// Binds d3d11 unordered access views to the d3d11 device context
+ void SetD3DUAVs ( class ShaderD3D11Impl *pShader );
+ /// Binds d3d11 samplers to the d3d11 device context
+ void SetD3DSamplers ( class ShaderD3D11Impl *pShader );
+
+ /// Helper template function used to facilitate resource unbinding
+ template<typename TBoundResourceType,
+ typename TD3D11ResourceType,
+ typename TSetD3D11View>
+ void UnbindResourceView(std::vector<TBoundResourceType> BoundResourcesArr[],
+ std::vector<TD3D11ResourceType> BoundD3D11ResourcesArr[],
+ IDeviceObject *pResToUnbind,
+ TSetD3D11View SetD3D11ViewMethods[]);
+
+ /// Unbinds a texture from the shader resource view slots.
+ /// \note The function only unbinds the texture from d3d11 device
+ /// context. All shader bindings are retained.
+ void UnbindTextureFromInput(ITexture *pTexture);
+
+ /// Unbinds a buffer from the input (shader resource views slots, index
+ /// and vertex buffer slots).
+ /// \note The function only unbinds the buffer from d3d11 device
+ /// context. All shader bindings are retained.
+ void UnbindBufferFromInput(IBuffer *pBuffer);
+
+ /// Unbinds a resource from the UAV slots.
+ /// \note The function only unbinds the texture from the device
+ /// context. All shader bindings are retained.
+ void UnbindResourceFromUAV(IDeviceObject *pResource);
+
+ /// Unbinds a texture from render target slots.
+ void UnbindTextureFromRenderTarget(IDeviceObject *pResource);
+
+ /// Unbinds a texture from depth-stencil.
+ void UnbindTextureFromDepthStencil(IDeviceObject *pResource);
+
+ /// Helper template function that facilitates shader binding
+ /// \tparam TD3D11ShaderType - Type of D3D11 shader being set (ID3D11PixelShader, ID3D11VertexShader, etc.)
+ /// \tparam TBindShaderMethdType - Type of the d3d11 device context mehtod that sets the shader
+ /// (ID3D11DeviceContext::VSSetShader, ID3D11DeviceContext::PSSetShader, etc.)
+ /// \param BoundShaderFlags - Flags indicating which shader stages are currently active
+ /// \param NewShaders - Array of pointers to the new shaders to be bound
+ /// \param ShaderType - Type of the shader being bound
+ /// \param BindShaderMethod - Pointer to the d3d11 device context mehtod that sets the shader
+ /// (ID3D11DeviceContext::VSSetShader, ID3D11DeviceContext::PSSetShader, etc.)
+ template<typename TD3D11ShaderType, typename TBindShaderMethdType>
+ void SetD3D11ShaderHelper(Uint32 BoundShaderFlags,
+ ShaderD3D11Impl* NewShaders[],
+ SHADER_TYPE ShaderType,
+ TBindShaderMethdType BindShaderMethod);
+
+ Diligent::CComPtr<ID3D11DeviceContext> m_pd3d11DeviceContext; ///< D3D11 device context
+ DrawAttribs m_LastDrawAttribs;
+
+ /// An array of D3D11 constant buffers currently bound to the D3D11 device context,
+ /// for each shader type.
+ std::vector<ID3D11Buffer*> m_BoundD3D11CBs [NumShaderTypes];
+ /// An array of D3D11 shader resource views currently bound to the D3D11 device context,
+ /// for each shader type.
+ std::vector<ID3D11ShaderResourceView*> m_BoundD3D11SRVs [NumShaderTypes];
+ /// An array of D3D11 samplers currently bound to the D3D11 device context,
+ /// for each shader type.
+ std::vector<ID3D11SamplerState*> m_BoundD3D11Samplers[NumShaderTypes];
+ /// An array of D3D11 UAVs currently bound to the D3D11 device context,
+ /// for each shader type.
+ std::vector<ID3D11UnorderedAccessView*> m_BoundD3D11UAVs [NumShaderTypes];
+
+ /// An array of strong references to resources associated with the bound
+ /// constant buffers, for each shader type.
+ std::vector<ShaderD3D11Impl::BoundCB> m_BoundCBs[NumShaderTypes];
+ /// An array of strong references to resources associated with the
+ /// bound SRV, for each shader type.
+ std::vector<ShaderD3D11Impl::BoundSRV> m_BoundSRVs[NumShaderTypes];
+ /// An array of strong references to resources associated with the
+ /// bound samplers, for each shader type.
+ std::vector<ShaderD3D11Impl::BoundSampler> m_BoundSamplers[NumShaderTypes];
+ /// An array of strong references to resources associated with the
+ /// bound UAVs, for each shader type.
+ std::vector<ShaderD3D11Impl::BoundUAV> m_BoundUAVs[NumShaderTypes];
+
+ /// An array of D3D11 vertex buffers currently bound to the D3D device context
+ std::vector< Diligent::CComPtr<ID3D11Buffer> > m_BoundD3D11VertexBuffers;
+ /// An array of strides of currently bound vertex buffers
+ std::vector< UINT > m_BoundD3D11VBStrides;
+ /// An array of offsets of currently bound vertex buffers
+ std::vector< UINT > m_BoundD3D11VBOffsets;
+
+ /// Strong reference to the D3D11 buffer currently bound as index buffer
+ /// to the D3D device context
+ Diligent::CComPtr<ID3D11Buffer> m_BoundD3D11IndexBuffer;
+ /// Format of currently bound D3D11 index buffer
+ DXGI_FORMAT m_BoundD3D11IndexFmt;
+ /// Offset of currently bound D3D11 index buffer
+ Uint32 m_BoundD3D11IndexDataStartOffset;
+
+ /// Strong references to the currently bound D3D11 shaders
+ Diligent::CComPtr<ID3D11DeviceChild> m_BoundD3DShaders[NumShaderTypes];
+
+#ifdef VERIFY_CONTEXT_BINDINGS
+ /// Helper template function used to facilitate context verification
+ template<UINT MaxResources, typename TD3D11ResourceType, typename TGetD3D11ResourcesType>
+ void dbgVerifyContextResources(std::vector<TD3D11ResourceType> BoundD3D11ResourcesArr[],
+ TGetD3D11ResourcesType GetD3D11ResMethods[],
+ const Char *ResourceName,
+ SHADER_TYPE ShaderType);
+
+ /// Debug function that verifies that SRVs cached in m_BoundD3D11SRVs
+ /// array comply with resources actually bound to the D3D11 device context
+ void dbgVerifyContextSRVs(SHADER_TYPE ShaderType = SHADER_TYPE_UNKNOWN);
+
+ /// Debug function that verifies that UAVs cached in m_BoundD3D11UAVs
+ /// array comply with resources actually bound to the D3D11 device context
+ void dbgVerifyContextUAVs(SHADER_TYPE ShaderType = SHADER_TYPE_UNKNOWN);
+
+ /// Debug function that verifies that samplers cached in m_BoundD3D11Samplers
+ /// array comply with resources actually bound to the D3D11 device context
+ void dbgVerifyContextSamplers(SHADER_TYPE ShaderType = SHADER_TYPE_UNKNOWN);
+
+ /// Debug function that verifies that constant buffers cached in m_BoundD3D11CBs
+ /// array comply with buffers actually bound to the D3D11 device context
+ void dbgVerifyContextCBs(SHADER_TYPE ShaderType = SHADER_TYPE_UNKNOWN);
+
+ /// Debug function that verifies that the index buffer cached in
+ /// m_BoundD3D11IndexBuffer is the buffer actually bound to the D3D11
+ /// device context
+ void dbgVerifyIndexBuffer();
+
+ /// Debug function that verifies that vertex buffers cached in
+ /// m_BoundD3D11VertexBuffers are the buffers actually bound to the D3D11
+ /// device context
+ void dbgVerifyVertexBuffers();
+
+ /// Debug function that verifies that shaders cached in
+ /// m_BoundD3DShaders are the shaders actually bound to the D3D11
+ /// device context
+ void dbgVerifyShaders();
+
+#else
+
+ #define dbgVerifyContextSRVs(...)
+ #define dbgVerifyContextUAVs(...)
+ #define dbgVerifyContextSamplers(...)
+ #define dbgVerifyContextCBs(...)
+ #define dbgVerifyIndexBuffer(...)
+ #define dbgVerifyVertexBuffers(...)
+ #define dbgVerifyShaders(...)
+
+#endif
+};
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/include/HLSLDefinitions.fxh b/Graphics/GraphicsEngineD3D11/include/HLSLDefinitions.fxh
new file mode 100644
index 00000000..fd19be08
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/include/HLSLDefinitions.fxh
@@ -0,0 +1,61 @@
+#ifndef _HLSL_DEFINITIONS_
+#define _HLSL_DEFINITIONS_
+
+#define HLSL
+
+#define NDC_MIN_Z 0.0 // Minimal z in the normalized device space
+
+#define F3NDC_XYZ_TO_UVD_SCALE float3(0.5, -0.5, 1.0)
+
+float2 NormalizedDeviceXYToTexUV( float2 f2ProjSpaceXY )
+{
+ return float2(0.5,0.5) + float2(0.5,-0.5) * f2ProjSpaceXY.xy;
+}
+
+float NormalizedDeviceZToDepth(float fNDC_Z)
+{
+ return fNDC_Z;
+}
+
+float DepthToNormalizedDeviceZ(float fDepth)
+{
+ return fDepth;
+}
+
+// Relational and logical operators
+#define Less(x,y) ((x)<(y))
+#define LessEqual(x,y) ((x)<=(y))
+#define Greater(x,y) ((x)>(y))
+#define GreaterEqual(x,y) ((x)>=(y))
+#define Equal(x,y) ((x)==(y))
+#define NotEqual(x,y) ((x)!=(y))
+#define Not(x) (!(x))
+#define And(x,y) ((x)&&(y))
+#define Or(x,y) ((x)||(y))
+
+float4 BoolToFloat( bool4 b4 )
+{
+ return float4(b4.x ? 1.0 : 0.0,
+ b4.y ? 1.0 : 0.0,
+ b4.z ? 1.0 : 0.0,
+ b4.w ? 1.0 : 0.0);
+}
+float3 BoolToFloat( bool3 b3 )
+{
+ return float3(b3.x ? 1.0 : 0.0,
+ b3.y ? 1.0 : 0.0,
+ b3.z ? 1.0 : 0.0);
+}
+float2 BoolToFloat( bool2 b2 )
+{
+ return float2(b2.x ? 1.0 : 0.0,
+ b2.y ? 1.0 : 0.0);
+}
+float BoolToFloat( bool b )
+{
+ return b.x ? 1.0 : 0.0;
+}
+
+#define MATRIX_ELEMENT(mat, row, col) mat[row][col]
+
+#endif // _HLSL_DEFINITIONS_
diff --git a/Graphics/GraphicsEngineD3D11/include/HLSLDefinitions_inc.fxh b/Graphics/GraphicsEngineD3D11/include/HLSLDefinitions_inc.fxh
new file mode 100644
index 00000000..84012ff1
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/include/HLSLDefinitions_inc.fxh
@@ -0,0 +1,61 @@
+"#ifndef _HLSL_DEFINITIONS_\n"
+"#define _HLSL_DEFINITIONS_\n"
+"\n"
+"#define HLSL\n"
+"\n"
+"#define NDC_MIN_Z 0.0 // Minimal z in the normalized device space\n"
+"\n"
+"#define F3NDC_XYZ_TO_UVD_SCALE float3(0.5, -0.5, 1.0)\n"
+"\n"
+"float2 NormalizedDeviceXYToTexUV( float2 f2ProjSpaceXY )\n"
+"{\n"
+" return float2(0.5,0.5) + float2(0.5,-0.5) * f2ProjSpaceXY.xy;\n"
+"}\n"
+"\n"
+"float NormalizedDeviceZToDepth(float fNDC_Z)\n"
+"{\n"
+" return fNDC_Z;\n"
+"}\n"
+"\n"
+"float DepthToNormalizedDeviceZ(float fDepth)\n"
+"{\n"
+" return fDepth;\n"
+"}\n"
+"\n"
+"// Relational and logical operators\n"
+"#define Less(x,y) ((x)<(y))\n"
+"#define LessEqual(x,y) ((x)<=(y))\n"
+"#define Greater(x,y) ((x)>(y))\n"
+"#define GreaterEqual(x,y) ((x)>=(y))\n"
+"#define Equal(x,y) ((x)==(y))\n"
+"#define NotEqual(x,y) ((x)!=(y))\n"
+"#define Not(x) (!(x))\n"
+"#define And(x,y) ((x)&&(y))\n"
+"#define Or(x,y) ((x)||(y))\n"
+"\n"
+"float4 BoolToFloat( bool4 b4 )\n"
+"{\n"
+" return float4(b4.x ? 1.0 : 0.0,\n"
+" b4.y ? 1.0 : 0.0,\n"
+" b4.z ? 1.0 : 0.0,\n"
+" b4.w ? 1.0 : 0.0);\n"
+"}\n"
+"float3 BoolToFloat( bool3 b3 )\n"
+"{\n"
+" return float3(b3.x ? 1.0 : 0.0,\n"
+" b3.y ? 1.0 : 0.0,\n"
+" b3.z ? 1.0 : 0.0);\n"
+"}\n"
+"float2 BoolToFloat( bool2 b2 )\n"
+"{\n"
+" return float2(b2.x ? 1.0 : 0.0,\n"
+" b2.y ? 1.0 : 0.0);\n"
+"}\n"
+"float BoolToFloat( bool b )\n"
+"{\n"
+" return b.x ? 1.0 : 0.0;\n"
+"}\n"
+"\n"
+"#define MATRIX_ELEMENT(mat, row, col) mat[row][col]\n"
+"\n"
+"#endif // _HLSL_DEFINITIONS_\n"
diff --git a/Graphics/GraphicsEngineD3D11/include/RasterizerStateD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/RasterizerStateD3D11Impl.h
new file mode 100644
index 00000000..aad6f2ad
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/include/RasterizerStateD3D11Impl.h
@@ -0,0 +1,54 @@
+/* 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
+/// Declaration of Diligent::RasterizerStateD3D11Impl class
+
+#include "RasterizerStateD3D11.h"
+#include "RenderDeviceD3D11.h"
+#include "RasterizerStateBase.h"
+
+namespace Diligent
+{
+
+/// Implementation of the Diligent::IRasterizerStateD3D11 interface
+class RasterizerStateD3D11Impl : public RasterizerStateBase<IRasterizerStateD3D11, IRenderDeviceD3D11>
+{
+public:
+ typedef RasterizerStateBase<IRasterizerStateD3D11, IRenderDeviceD3D11 > TRasterizerStateBase;
+
+ RasterizerStateD3D11Impl(class RenderDeviceD3D11Impl *pDeviceD3D11, const RasterizerStateDesc& BuffDesc);
+ ~RasterizerStateD3D11Impl();
+
+ virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface );
+
+ ID3D11RasterizerState *GetD3D11RasterizerState(){ return m_pd3d11RasterizerState; }
+
+private:
+ /// D3D11 rasterizer state
+ Diligent::CComPtr<ID3D11RasterizerState> m_pd3d11RasterizerState;
+};
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/include/RenderDeviceD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/RenderDeviceD3D11Impl.h
new file mode 100644
index 00000000..0f374b5c
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/include/RenderDeviceD3D11Impl.h
@@ -0,0 +1,73 @@
+/* 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
+/// Declaration of Diligent::RenderDeviceD3D11Impl class
+
+#include "RenderDeviceD3D11.h"
+#include "RenderDeviceBase.h"
+#include "DeviceContextD3D11.h"
+
+/// Namespace for the Direct3D11 implementation of the graphics engine
+namespace Diligent
+{
+
+/// Implementation of the Diligent::IRenderDeviceD3D11 interface
+class RenderDeviceD3D11Impl : public RenderDeviceBase<IRenderDeviceD3D11>
+{
+public:
+ typedef RenderDeviceBase<IRenderDeviceD3D11> TRenderDeviceBase;
+
+ RenderDeviceD3D11Impl( ID3D11Device *pd3d11Device );
+ virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface );
+
+ virtual void CreateBuffer(const BufferDesc& BuffDesc, const BufferData &BuffData, IBuffer **ppBuffer);
+
+ virtual void CreateVertexDescription( const LayoutDesc& LayoutDesc, IShader *pVertexShader, IVertexDescription **ppVertexDesc );
+
+ virtual void CreateShader(const ShaderCreationAttribs &ShaderCreationAttribs, IShader **ppShader);
+
+ virtual void CreateTexture(const TextureDesc& TexDesc, const TextureData &Data, ITexture **ppTexture);
+
+ virtual void CreateSampler(const SamplerDesc& SamplerDesc, ISampler **ppSampler);
+
+ virtual void CreateDepthStencilState( const DepthStencilStateDesc &DSSDesc, IDepthStencilState **ppDepthStencilState );
+
+ virtual void CreateRasterizerState( const RasterizerStateDesc &RSDesc, IRasterizerState **ppRasterizerState );
+
+ virtual void CreateBlendState( const BlendStateDesc &BSDesc, IBlendState **ppBlendState );
+
+ ID3D11Device* GetD3D11Device(){return m_pd3d11Device;}
+
+private:
+ virtual void TestTextureFormat( TEXTURE_FORMAT TexFormat );
+
+ void FlagSupportedTexFormats();
+
+ /// D3D11 device
+ Diligent::CComPtr<ID3D11Device> m_pd3d11Device;
+};
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/include/SamplerD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/SamplerD3D11Impl.h
new file mode 100644
index 00000000..f48d645e
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/include/SamplerD3D11Impl.h
@@ -0,0 +1,55 @@
+/* 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
+/// Declaration of Diligent::SamplerD3D11Impl class
+
+#include "SamplerD3D11.h"
+#include "RenderDeviceD3D11.h"
+#include "SamplerBase.h"
+
+namespace Diligent
+{
+
+/// Implementation of the Diligent::ISamplerD3D11 interface
+class SamplerD3D11Impl : public SamplerBase<ISamplerD3D11, IRenderDeviceD3D11>
+{
+public:
+ typedef SamplerBase<ISamplerD3D11, IRenderDeviceD3D11> TSamplerBase;
+
+ SamplerD3D11Impl(class RenderDeviceD3D11Impl *pRenderDeviceD3D11, const SamplerDesc& SamplerDesc);
+ ~SamplerD3D11Impl();
+
+ virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface );
+
+ virtual ID3D11SamplerState* GetD3D11SamplerState(){ return m_pd3dSampler; }
+
+private:
+ friend class ShaderD3D11Impl;
+ /// D3D11 sampler
+ Diligent::CComPtr<ID3D11SamplerState> m_pd3dSampler;
+};
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/include/ShaderD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/ShaderD3D11Impl.h
new file mode 100644
index 00000000..4066947e
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/include/ShaderD3D11Impl.h
@@ -0,0 +1,231 @@
+/* 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
+/// Declaration of Diligent::ShaderD3D11Impl class
+
+#include "ShaderD3D11.h"
+#include "RenderDeviceD3D11.h"
+#include "ShaderBase.h"
+
+#ifdef _DEBUG
+# define VERIFY_SHADER_BINDINGS
+#endif
+
+namespace Diligent
+{
+
+class ResourceMapping;
+
+/// Implementation of the Diligent::IShaderD3D11 interface
+class ShaderD3D11Impl : public ShaderBase<IShaderD3D11, IRenderDeviceD3D11>
+{
+public:
+ typedef ShaderBase<IShaderD3D11, IRenderDeviceD3D11> TShaderBase;
+
+ ShaderD3D11Impl(class RenderDeviceD3D11Impl *pRenderDeviceD3D11, const ShaderCreationAttribs &ShaderCreationAttribs);
+ ~ShaderD3D11Impl();
+
+ virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )override;
+
+ virtual void BindResources( IResourceMapping* pResourceMapping, Uint32 Flags )override;
+
+ virtual IShaderVariable* GetShaderVariable( const Char* Name )override;
+
+ /// Describes resources associated with the bound constant buffer
+ struct BoundCB
+ {
+ /// Strong reference to the buffer
+ Diligent::RefCntAutoPtr<IDeviceObject> pBuff;
+ /// Strong referene to the D3D11 buffer interface
+ Diligent::CComPtr<ID3D11Buffer> pd3d11Buff;
+ };
+
+ /// Describes resources associated with the bound sampler
+ struct BoundSampler
+ {
+ /// Strong reference to the sampler
+ Diligent::RefCntAutoPtr<IDeviceObject> pSampler;
+ /// Strong referene to the D3D11 sampler state interface
+ Diligent::CComPtr<ID3D11SamplerState> pd3d11Sampler;
+ };
+
+ /// Describes resources associated with the bound SRV
+ struct BoundSRV
+ {
+ /// Strong reference to the resource bound as SRV
+ Diligent::RefCntAutoPtr<IDeviceObject> pResource;
+ /// Strong reference to the resource view
+ Diligent::RefCntAutoPtr<IDeviceObject> pView;
+ /// Strong referene to the D3D11 SRV interface
+ Diligent::CComPtr<ID3D11ShaderResourceView> pd3d11View;
+ };
+
+ /// Describes resources associated with the bound UAV
+ struct BoundUAV
+ {
+ /// Strong reference to the resource bound as UAV
+ Diligent::RefCntAutoPtr<IDeviceObject> pResource;
+ /// Strong reference to the resource view
+ Diligent::RefCntAutoPtr<IDeviceObject> pView;
+ /// Strong referene to the D3D11 UAV interface
+ Diligent::CComPtr<ID3D11UnorderedAccessView> pd3d11View;
+ };
+
+ /// Returns a const reference to the zero-slot-based array of bound constant buffers
+ const std::vector< BoundCB >& GetBoundCBs() { return m_BoundCBs; }
+ /// Returns a const reference to the zero-slot-based array of bound samplers
+ const std::vector< BoundSampler >& GetBoundSamplers() { return m_BoundSamplers; }
+ /// Returns a const reference to the zero-slot-based array bound SRVs
+ const std::vector< BoundSRV >& GetBoundSRVs() { return m_BoundSRVs; }
+ /// Returns a const reference to the zero-slot-based array bound UAVs
+ const std::vector< BoundUAV >& GetBoundUAVs() { return m_BoundUAVs; }
+
+ virtual ID3D11DeviceChild* GetD3D11Shader()override{ return m_pShader; }
+
+#ifdef VERIFY_SHADER_BINDINGS
+ void dbgVerifyBindings();
+#endif
+
+private:
+ void BindConstantBuffers( IResourceMapping* pResourceMapping, Uint32 Flags );
+
+ void BindSRVsAndSamplers( IResourceMapping* pResourceMapping, Uint32 Flags );
+
+ void BindUAVs( IResourceMapping* pResourceMapping, Uint32 Flags );
+
+ static const String m_SamplerSuffix;
+
+ struct D3D11ShaderVarBase : ShaderVariableBase
+ {
+ D3D11ShaderVarBase( ShaderD3D11Impl *pShader, const String& _Name, UINT _BindPoint ) :
+ ShaderVariableBase( pShader ),
+ Name(_Name),
+ BindPoint(_BindPoint)
+ {}
+
+ String Name;
+ UINT BindPoint;
+ const String& GetName(){ return Name; }
+ };
+
+ struct ConstBuffBindInfo : D3D11ShaderVarBase
+ {
+ ConstBuffBindInfo( ShaderD3D11Impl *pShader, const String& _Name, UINT _BindPoint ) :
+ D3D11ShaderVarBase( pShader, _Name, _BindPoint )
+ {}
+ virtual void Set(IDeviceObject *pObject)override;
+ bool IsBound();
+ };
+
+ struct TexAndSamplerBindInfo : D3D11ShaderVarBase
+ {
+ TexAndSamplerBindInfo( ShaderD3D11Impl *pShader, const String& _TexName, UINT _TexBindPoint, const String &_SamplerName, UINT _SamplerBindPoint ) :
+ D3D11ShaderVarBase( pShader, _TexName, _TexBindPoint),
+ SamplerName(_SamplerName),
+ SamplerBindPoint(_SamplerBindPoint)
+ {}
+
+ String SamplerName;
+ UINT SamplerBindPoint;
+ virtual void Set(IDeviceObject *pObject)override;
+ bool IsBound();
+ };
+
+ struct UAVBindInfoBase : public D3D11ShaderVarBase
+ {
+ UAVBindInfoBase( ShaderD3D11Impl *pShader, const String& _Name, UINT _BindPoint, D3D_SHADER_INPUT_TYPE _Type ) :
+ D3D11ShaderVarBase( pShader, _Name, _BindPoint),
+ Type(_Type)
+ {}
+
+ bool IsBound();
+ D3D_SHADER_INPUT_TYPE Type;
+ };
+
+ struct TexUAVBindInfo : UAVBindInfoBase
+ {
+ TexUAVBindInfo( ShaderD3D11Impl *pShader, const String& _Name, UINT _BindPoint, D3D_SHADER_INPUT_TYPE _Type ) :
+ UAVBindInfoBase( pShader, _Name, _BindPoint, _Type )
+ {}
+
+ virtual void Set(IDeviceObject *pObject)override;
+ };
+
+ struct BuffUAVBindInfo : UAVBindInfoBase
+ {
+ BuffUAVBindInfo( ShaderD3D11Impl *pShader, const String& _Name, UINT _BindPoint, D3D_SHADER_INPUT_TYPE _Type ) :
+ UAVBindInfoBase( pShader, _Name, _BindPoint, _Type )
+ {}
+
+ virtual void Set(IDeviceObject *pObject)override;
+ };
+
+ struct BuffSRVBindInfo : D3D11ShaderVarBase
+ {
+ BuffSRVBindInfo( ShaderD3D11Impl *pShader, const String &_Name, UINT _BindPoint ) :
+ D3D11ShaderVarBase( pShader, _Name, _BindPoint)
+ {}
+
+ virtual void Set(IDeviceObject *pObject)override;
+ bool IsBound();
+ };
+
+ void LoadShaderResources();
+
+ friend class VertexDescD3D11Impl;
+ friend class DeviceContextD3D11Impl;
+ /// D3D11 shader
+ Diligent::CComPtr<ID3D11DeviceChild> m_pShader;
+ Diligent::CComPtr<ID3DBlob> m_pShaderByteCode;// Only stored for Vertex Shader
+
+ std::vector<ConstBuffBindInfo> m_ConstanBuffers;
+ std::vector<TexAndSamplerBindInfo> m_TexAndSamplers;
+ std::vector<TexUAVBindInfo> m_TexUAVs;
+ std::vector<BuffUAVBindInfo> m_BuffUAVs;
+ std::vector<BuffSRVBindInfo> m_BuffSRVs;
+
+
+ /// An array of bound constant buffers. The data always starts at
+ /// slot 0 even when no resource is actually bound to the slot.
+ std::vector<BoundCB> m_BoundCBs;
+
+ /// An array of bound samplers. The data always starts at
+ /// slot 0 even when no sampler is actually bound to the slot.
+ std::vector<BoundSampler> m_BoundSamplers;
+
+ /// An array of bound SRVs. The data always starts at
+ /// slot 0 even when no resource is actually bound to the slot.
+ std::vector<BoundSRV> m_BoundSRVs;
+
+ /// An array of bound UAVs. The data always starts at
+ /// slot 0 even when no resource is actually bound to the slot.
+ std::vector<BoundUAV> m_BoundUAVs;
+
+ /// Hash map to look up shader variables by name.
+ std::unordered_map<Diligent::HashMapStringKey, IShaderVariable* > m_VariableHash;
+};
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/include/SwapChainD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/SwapChainD3D11Impl.h
new file mode 100644
index 00000000..32cef19f
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/include/SwapChainD3D11Impl.h
@@ -0,0 +1,66 @@
+/* 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
+/// Declaration of Diligent::SwapChainD3D11Impl class
+
+#include "SwapChainD3D11.h"
+#include "SwapChainBase.h"
+
+namespace Diligent
+{
+
+/// Implementation of the Diligent::ISwapChainD3D11 interface
+class SwapChainD3D11Impl : public SwapChainBase<ISwapChainD3D11>
+{
+public:
+ typedef SwapChainBase<ISwapChainD3D11> TSwapChainBase;
+ SwapChainD3D11Impl(const SwapChainDesc& SwapChainDesc,
+ class RenderDeviceD3D11Impl* pRenderDeviceD3D11,
+ class DeviceContextD3D11Impl* pDeviceContextD3D11,
+ void* pNativeWndHandle);
+ ~SwapChainD3D11Impl();
+
+ virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface );
+
+ virtual void Present();
+ virtual void Resize( Uint32 NewWidth, Uint32 NewHeight );
+
+ virtual IDXGISwapChain *GetDXGISwapChain(){ return m_pSwapChain; }
+
+ ID3D11RenderTargetView* GetRTV(){ return m_pRenderTargetView; }
+ ID3D11DepthStencilView* GetDSV(){ return m_pDepthStencilView; }
+
+private:
+ void CreateRTVandDSV();
+ /// D3D11 swap chain
+ Diligent::CComPtr<IDXGISwapChain> m_pSwapChain;
+ /// Back buffer render target view
+ Diligent::CComPtr<ID3D11RenderTargetView> m_pRenderTargetView;
+ /// Back buffer depth-stencil view
+ Diligent::CComPtr<ID3D11DepthStencilView> m_pDepthStencilView;
+};
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/include/Texture1D_D3D11.h b/Graphics/GraphicsEngineD3D11/include/Texture1D_D3D11.h
new file mode 100644
index 00000000..e1cdcb2f
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/include/Texture1D_D3D11.h
@@ -0,0 +1,47 @@
+/* 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
+/// Declaration of Diligent::Texture1D_D3D11 class
+
+#include "TextureBaseD3D11.h"
+
+namespace Diligent
+{
+
+class Texture1D_D3D11 : public TextureBaseD3D11
+{
+public:
+ Texture1D_D3D11(class RenderDeviceD3D11Impl *pDeviceD3D11, const TextureDesc& TexDesc, const TextureData &InitData = TextureData());
+ ~Texture1D_D3D11();
+
+protected:
+ virtual void CreateSRV( TextureViewDesc &SRVDesc, ID3D11ShaderResourceView **ppD3D11SRV );
+ virtual void CreateRTV( TextureViewDesc &RTVDesc, ID3D11RenderTargetView **ppD3D11RTV );
+ virtual void CreateDSV( TextureViewDesc &DSVDesc, ID3D11DepthStencilView **ppD3D11DSV );
+ virtual void CreateUAV( TextureViewDesc &UAVDesc, ID3D11UnorderedAccessView **ppD3D11UAV );
+};
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/include/Texture2D_D3D11.h b/Graphics/GraphicsEngineD3D11/include/Texture2D_D3D11.h
new file mode 100644
index 00000000..e098bce1
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/include/Texture2D_D3D11.h
@@ -0,0 +1,47 @@
+/* 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
+/// Declaration of Diligent::Texture2D_D3D11 class
+
+#include "TextureBaseD3D11.h"
+
+namespace Diligent
+{
+
+class Texture2D_D3D11 : public TextureBaseD3D11
+{
+public:
+ Texture2D_D3D11(class RenderDeviceD3D11Impl *pDeviceD3D11, const TextureDesc& TexDesc, const TextureData &InitData = TextureData());
+ ~Texture2D_D3D11();
+
+protected:
+ virtual void CreateSRV( TextureViewDesc &SRVDesc, ID3D11ShaderResourceView **ppD3D11SRV );
+ virtual void CreateRTV( TextureViewDesc &RTVDesc, ID3D11RenderTargetView **ppD3D11RTV );
+ virtual void CreateDSV( TextureViewDesc &DSVDesc, ID3D11DepthStencilView **ppD3D11DSV );
+ virtual void CreateUAV( TextureViewDesc &UAVDesc, ID3D11UnorderedAccessView **ppD3D11UAV );
+};
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/include/Texture3D_D3D11.h b/Graphics/GraphicsEngineD3D11/include/Texture3D_D3D11.h
new file mode 100644
index 00000000..d5e11c8a
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/include/Texture3D_D3D11.h
@@ -0,0 +1,47 @@
+/* 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
+/// Declaration of Diligent::Texture3D_D3D11 class
+
+#include "TextureBaseD3D11.h"
+
+namespace Diligent
+{
+
+class Texture3D_D3D11 : public TextureBaseD3D11
+{
+public:
+ Texture3D_D3D11(class RenderDeviceD3D11Impl *pDeviceD3D11, const TextureDesc& TexDesc, const TextureData &InitData = TextureData());
+ ~Texture3D_D3D11();
+
+protected:
+ virtual void CreateSRV( TextureViewDesc &SRVDesc, ID3D11ShaderResourceView **ppD3D11SRV );
+ virtual void CreateRTV( TextureViewDesc &RTVDesc, ID3D11RenderTargetView **ppD3D11RTV );
+ virtual void CreateDSV( TextureViewDesc &DSVDesc, ID3D11DepthStencilView **ppD3D11DSV );
+ virtual void CreateUAV( TextureViewDesc &UAVDesc, ID3D11UnorderedAccessView **ppD3D11UAV );
+};
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/include/TextureBaseD3D11.h b/Graphics/GraphicsEngineD3D11/include/TextureBaseD3D11.h
new file mode 100644
index 00000000..e787f238
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/include/TextureBaseD3D11.h
@@ -0,0 +1,81 @@
+/* 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
+/// Declaration of Diligent::TextureBaseD3D11 class
+
+#include "TextureD3D11.h"
+#include "RenderDeviceD3D11.h"
+#include "TextureBase.h"
+#include "TextureViewD3D11Impl.h"
+
+namespace Diligent
+{
+
+/// Base implementation of the Diligent::ITextureD3D11 interface
+class TextureBaseD3D11 : public TextureBase<ITextureD3D11, TextureViewD3D11Impl>
+{
+public:
+ typedef TextureBase<ITextureD3D11, TextureViewD3D11Impl> TTextureBase;
+
+ TextureBaseD3D11(class RenderDeviceD3D11Impl *pDeviceD3D11, const TextureDesc& TexDesc, const TextureData &InitData = TextureData());
+ ~TextureBaseD3D11();
+
+ virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )override;
+
+ virtual void UpdateData( IDeviceContext *pContext, Uint32 MipLevel, Uint32 Slice, const Box &DstBox, const TextureSubResData &SubresData )override;
+
+ //virtual void CopyData(CTexture *pSrcTexture, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size);
+ virtual void Map( IDeviceContext *pContext, MAP_TYPE MapType, Uint32 MapFlags, PVoid &pMappedData )override;
+ virtual void Unmap( IDeviceContext *pContext )override;
+
+ virtual ID3D11Resource* GetD3D11Texture(){ return m_pd3d11Texture; }
+
+ void CopyData(IDeviceContext *pContext,
+ ITexture *pSrcTexture,
+ Uint32 SrcMipLevel,
+ Uint32 SrcSlice,
+ const Box *pSrcBox,
+ Uint32 DstMipLevel,
+ Uint32 DstSlice,
+ Uint32 DstX,
+ Uint32 DstY,
+ Uint32 DstZ);
+
+protected:
+ void CreateViewInternal( const struct TextureViewDesc &ViewDesc, ITextureView **ppView, bool bIsDefaultView )override;
+ void PrepareD3D11InitData(const TextureData &InitData, Uint32 NumSubresources, std::vector<D3D11_SUBRESOURCE_DATA> &D3D11InitData);
+
+ virtual void CreateSRV( TextureViewDesc &SRVDesc, ID3D11ShaderResourceView **ppD3D11SRV ) = 0;
+ virtual void CreateRTV( TextureViewDesc &RTVDesc, ID3D11RenderTargetView **ppD3D11RTV ) = 0;
+ virtual void CreateDSV( TextureViewDesc &DSVDesc, ID3D11DepthStencilView **ppD3D11DSV ) = 0;
+ virtual void CreateUAV( TextureViewDesc &UAVDesc, ID3D11UnorderedAccessView **ppD3D11UAV ) = 0;
+
+ friend class RenderDeviceD3D11Impl;
+ /// D3D11 texture
+ Diligent::CComPtr<ID3D11Resource> m_pd3d11Texture;
+};
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/include/TextureViewD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/TextureViewD3D11Impl.h
new file mode 100644
index 00000000..6e138b41
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/include/TextureViewD3D11Impl.h
@@ -0,0 +1,59 @@
+/* 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
+/// Declaration of Diligent::TextureViewD3D11Impl class
+
+#include "TextureViewD3D11.h"
+#include "RenderDeviceD3D11.h"
+#include "TextureViewBase.h"
+
+namespace Diligent
+{
+
+/// Implementation of the Diligent::ITextureViewD3D11 interface
+class TextureViewD3D11Impl : public TextureViewBase<ITextureViewD3D11>
+{
+public:
+ typedef TextureViewBase<ITextureViewD3D11> TTextureViewBase;
+
+ TextureViewD3D11Impl( IRenderDevice *pDevice,
+ const TextureViewDesc& ViewDesc,
+ class ITexture *pTexture,
+ ID3D11View* pD3D11View,
+ bool bIsDefaultView);
+
+ virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )override;
+
+ virtual ID3D11View* GetD3D11View()override;
+
+ void GenerateMips( IDeviceContext *pContext )override;
+
+protected:
+ /// D3D11 view
+ Diligent::CComPtr<ID3D11View> m_pD3D11View;
+};
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/include/VertexDescD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/VertexDescD3D11Impl.h
new file mode 100644
index 00000000..84b9ea78
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/include/VertexDescD3D11Impl.h
@@ -0,0 +1,55 @@
+/* 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
+/// Declaration of Diligent::VertexDescD3D11Impl class
+
+#include "VertexDescriptionD3D11.h"
+#include "RenderDeviceD3D11.h"
+#include "VertexDescriptionBase.h"
+
+namespace Diligent
+{
+
+/// Implementation of the Diligent::IVertexDescriptionD3D11 interface
+class VertexDescD3D11Impl : public VertexDescriptionBase<IVertexDescriptionD3D11>
+{
+public:
+ typedef VertexDescriptionBase<IVertexDescriptionD3D11> TVertexDescriptionBase;
+
+ VertexDescD3D11Impl( class RenderDeviceD3D11Impl *pRenderDeviceD3D11, const LayoutDesc &LayoutDesc, IShader *pVertexShader );
+ ~VertexDescD3D11Impl();
+
+ virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface );
+
+ virtual ID3D11InputLayout* GetD3D11InputLayout(){ return m_pd3d11InputLayout; }
+
+private:
+ friend class DeviceContextD3D11Impl;
+ /// D3D11 input layout
+ Diligent::CComPtr<ID3D11InputLayout> m_pd3d11InputLayout;
+};
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/include/pch.h b/Graphics/GraphicsEngineD3D11/include/pch.h
new file mode 100644
index 00000000..d948fd48
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/include/pch.h
@@ -0,0 +1,55 @@
+/* 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.
+ */
+
+// stdafx.h : include file for standard system include files,
+// or project specific include files that are used frequently, but
+// are changed infrequently
+//
+
+#pragma once
+
+#include "targetver.h"
+
+#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
+#define NOMINMAX
+
+#include "PlatformDefinitions.h"
+
+#include <vector>
+#include <exception>
+#include <algorithm>
+#if defined(PLATFORM_WINDOWS)
+ #include <d3d11.h>
+#elif defined(PLATFORM_WINDOWS_STORE)
+ #include <d3d11_2.h>
+#endif
+
+#include "PlatformDefinitions.h"
+#include "Errors.h"
+#include "RefCntAutoPtr.h"
+#include "DebugUtilities.h"
+#include "D3DErrors.h"
+#include "RenderDeviceBase.h"
+#include "D3D11TypeConversions.h"
+#include "ValidatedCast.h"
+#include "ComPtr.h" \ No newline at end of file
diff --git a/Graphics/GraphicsEngineD3D11/include/targetver.h b/Graphics/GraphicsEngineD3D11/include/targetver.h
new file mode 100644
index 00000000..e76fe941
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/include/targetver.h
@@ -0,0 +1,31 @@
+/* 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
+
+// Including SDKDDKVer.h defines the highest available Windows platform.
+
+// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
+// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
+
+#include <SDKDDKVer.h>
diff --git a/Graphics/GraphicsEngineD3D11/interface/BlendStateD3D11.h b/Graphics/GraphicsEngineD3D11/interface/BlendStateD3D11.h
new file mode 100644
index 00000000..8fe1c302
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/interface/BlendStateD3D11.h
@@ -0,0 +1,50 @@
+/* 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
+/// Definition of the Diligent::IBlendStateD3D11 interface
+
+#include "BlendState.h"
+
+namespace Diligent
+{
+
+// {18FEA836-1DD6-4100-9C83-CEF71F8EC8F1}
+static const Diligent::INTERFACE_ID IID_BlendStateD3D11 =
+{ 0x18fea836, 0x1dd6, 0x4100, { 0x9c, 0x83, 0xce, 0xf7, 0x1f, 0x8e, 0xc8, 0xf1 } };
+
+/// Interface to the blend state object implemented in D3D11
+class IBlendStateD3D11 : public Diligent::IBlendState
+{
+public:
+
+ /// Returns a pointer to the ID3D11BlendState interface of the internal Direct3D11 object.
+
+ /// The method does *NOT* call AddRef() on the returned interface,
+ /// so Release() must not be called.
+ virtual ID3D11BlendState *GetD3D11BlendState() = 0;
+};
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/interface/BufferD3D11.h b/Graphics/GraphicsEngineD3D11/interface/BufferD3D11.h
new file mode 100644
index 00000000..46195298
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/interface/BufferD3D11.h
@@ -0,0 +1,50 @@
+/* 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
+/// Definition of the Diligent::IBufferD3D11 interface
+
+#include "Buffer.h"
+
+namespace Diligent
+{
+
+// {4A696D2E-44BB-4C4B-9DE2-3AF7C94DCFC0}
+static const Diligent::INTERFACE_ID IID_BufferD3D11 =
+{ 0x4a696d2e, 0x44bb, 0x4c4b, { 0x9d, 0xe2, 0x3a, 0xf7, 0xc9, 0x4d, 0xcf, 0xc0 } };
+
+/// Interface to the buffer object implemented in D3D11
+class IBufferD3D11 : public Diligent::IBuffer
+{
+public:
+
+ /// Returns a pointer to the ID3D11Buffer interface of the internal Direct3D11 object.
+
+ /// The method does *NOT* call AddRef() on the returned interface,
+ /// so Release() must not be called.
+ virtual ID3D11Buffer *GetD3D11Buffer() = 0;
+};
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/interface/BufferViewD3D11.h b/Graphics/GraphicsEngineD3D11/interface/BufferViewD3D11.h
new file mode 100644
index 00000000..32a75461
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/interface/BufferViewD3D11.h
@@ -0,0 +1,50 @@
+/* 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
+/// Definition of the Diligent::IBufferViewD3D11 interface
+
+#include "BufferView.h"
+
+namespace Diligent
+{
+
+// {6ABA95FC-CD7D-4C03-8CAE-AFC45F9696B7}
+static const Diligent::INTERFACE_ID IID_BufferViewD3D11 =
+{ 0x6aba95fc, 0xcd7d, 0x4c03, { 0x8c, 0xae, 0xaf, 0xc4, 0x5f, 0x96, 0x96, 0xb7 } };
+
+/// Interface to the buffer view object implemented in D3D11
+class IBufferViewD3D11 : public Diligent::IBufferView
+{
+public:
+
+ /// Returns a pointer to the ID3D11View interface of the internal Direct3D11 object.
+
+ /// The method does *NOT* call AddRef() on the returned interface,
+ /// so Release() must not be called.
+ virtual ID3D11View* GetD3D11View() = 0;
+};
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/interface/DepthStencilStateD3D11.h b/Graphics/GraphicsEngineD3D11/interface/DepthStencilStateD3D11.h
new file mode 100644
index 00000000..7e8bd567
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/interface/DepthStencilStateD3D11.h
@@ -0,0 +1,50 @@
+/* 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
+/// Definition of the Diligent::IDepthStencilStateD3D11 interface
+
+#include "DepthStencilState.h"
+
+namespace Diligent
+{
+
+// {77EA665B-4D63-4D5F-AD8F-791FE79FC305}
+static const Diligent::INTERFACE_ID IID_DepthStencilStateD3D11 =
+{ 0x77ea665b, 0x4d63, 0x4d5f, { 0xad, 0x8f, 0x79, 0x1f, 0xe7, 0x9f, 0xc3, 0x5 } };
+
+/// Interface to the depth stencil state object implemented in D3D11
+class IDepthStencilStateD3D11 : public Diligent::IDepthStencilState
+{
+public:
+
+ /// Returns a pointer to the ID3D11DepthStencilState interface of the internal Direct3D11 object.
+
+ /// The method does *NOT* call AddRef() on the returned interface,
+ /// so Release() must not be called.
+ virtual ID3D11DepthStencilState *GetD3D11DepthStencilState() = 0;
+};
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/interface/DeviceContextD3D11.h b/Graphics/GraphicsEngineD3D11/interface/DeviceContextD3D11.h
new file mode 100644
index 00000000..972249b4
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/interface/DeviceContextD3D11.h
@@ -0,0 +1,50 @@
+/* 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
+/// Definition of the Diligent::IDeviceContextD3D11 interface
+
+#include "DeviceContext.h"
+
+namespace Diligent
+{
+
+// {F0EE0335-C8AB-4EC1-BB15-B8EE5F003B99}
+static const Diligent::INTERFACE_ID IID_DeviceContextD3D11 =
+{ 0xf0ee0335, 0xc8ab, 0x4ec1, { 0xbb, 0x15, 0xb8, 0xee, 0x5f, 0x0, 0x3b, 0x99 } };
+
+/// Interface to the device context object implemented in D3D11
+class IDeviceContextD3D11 : public Diligent::IDeviceContext
+{
+public:
+
+ /// Returns a pointer to the ID3D11DeviceContext interface of the internal Direct3D11 object.
+
+ /// The method does *NOT* call AddRef() on the returned interface,
+ /// so Release() must not be called.
+ virtual ID3D11DeviceContext* GetD3D11DeviceContext() = 0;
+};
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/interface/RasterizerStateD3D11.h b/Graphics/GraphicsEngineD3D11/interface/RasterizerStateD3D11.h
new file mode 100644
index 00000000..7ebb7bf0
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/interface/RasterizerStateD3D11.h
@@ -0,0 +1,50 @@
+/* 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
+/// Definition of the Diligent::IRasterizerStateD3D11 interface
+
+#include "RasterizerState.h"
+
+namespace Diligent
+{
+
+// {10E96D54-1A17-4AB4-8A87-CD39211B348D}
+static const Diligent::INTERFACE_ID IID_RasterizerStateD3D11 =
+{ 0x10e96d54, 0x1a17, 0x4ab4, { 0x8a, 0x87, 0xcd, 0x39, 0x21, 0x1b, 0x34, 0x8d } };
+
+/// Interface to the rasterizer state object implemented in D3D11
+class IRasterizerStateD3D11 : public Diligent::IRasterizerState
+{
+public:
+
+ /// Returns a pointer to the ID3D11RasterizerState interface of the internal Direct3D11 object.
+
+ /// The method does *NOT* call AddRef() on the returned interface,
+ /// so Release() must not be called.
+ virtual ID3D11RasterizerState *GetD3D11RasterizerState() = 0;
+};
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/interface/RenderDeviceD3D11.h b/Graphics/GraphicsEngineD3D11/interface/RenderDeviceD3D11.h
new file mode 100644
index 00000000..2baaa564
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/interface/RenderDeviceD3D11.h
@@ -0,0 +1,50 @@
+/* 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
+/// Definition of the Diligent::IRenderDeviceD3D11 interface
+
+#include "RenderDevice.h"
+
+namespace Diligent
+{
+
+// {05B1CBB8-FCAD-49EE-BADA-7801223EC3FE}
+static const Diligent::INTERFACE_ID IID_RenderDeviceD3D11 =
+{ 0x5b1cbb8, 0xfcad, 0x49ee, { 0xba, 0xda, 0x78, 0x1, 0x22, 0x3e, 0xc3, 0xfe } };
+
+/// Interface to the render device object implemented in D3D11
+class IRenderDeviceD3D11 : public Diligent::IRenderDevice
+{
+public:
+
+ /// Returns a pointer to the ID3D11Device interface of the internal Direct3D11 object.
+
+ /// The method does *NOT* call AddRef() on the returned interface,
+ /// so Release() must not be called.
+ virtual ID3D11Device* GetD3D11Device() = 0;
+};
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/interface/RenderDeviceFactoryD3D11.h b/Graphics/GraphicsEngineD3D11/interface/RenderDeviceFactoryD3D11.h
new file mode 100644
index 00000000..d289fb65
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/interface/RenderDeviceFactoryD3D11.h
@@ -0,0 +1,95 @@
+/* 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
+
+#include "Errors.h"
+
+extern "C"
+{
+#ifdef ENGINE_DLL
+ typedef void (*CreateDeviceAndImmediateContextD3D11Type)(
+ const Diligent::EngineCreationAttribs& CreationAttribs,
+ Diligent::IRenderDevice **ppDevice,
+ Diligent::IDeviceContext **ppContext );
+
+ typedef void (*CreateSwapChainD3D11Type)(
+ Diligent::IRenderDevice *pDevice,
+ Diligent::IDeviceContext *pImmediateContext,
+ const Diligent::SwapChainDesc& SwapChainDesc,
+ void* pNativeWndHandle,
+ Diligent::ISwapChain **ppSwapChain );
+
+ static void LoadGraphicsEngineD3D11(CreateDeviceAndImmediateContextD3D11Type &CreateDeviceFunc, CreateSwapChainD3D11Type &CreateSwapChainFunc)
+ {
+ CreateDeviceFunc = nullptr;
+ CreateSwapChainFunc = nullptr;
+ std::string LibName = "GraphicsEngineD3D11_";
+
+#if _WIN64
+ LibName += "64";
+#else
+ LibName += "32";
+#endif
+
+#ifdef _DEBUG
+ LibName += "d";
+#else
+ LibName += "r";
+#endif
+
+ LibName += ".dll";
+ auto hModule = LoadLibraryA( LibName.c_str() );
+ if( hModule == NULL )
+ {
+ LOG_ERROR_MESSAGE( "Failed to load ", LibName, " library." );
+ return;
+ }
+
+ CreateDeviceFunc = reinterpret_cast<CreateDeviceAndImmediateContextD3D11Type>( GetProcAddress(hModule, "CreateDeviceAndImmediateContextD3D11") );
+ if( CreateDeviceFunc == NULL )
+ {
+ LOG_ERROR_MESSAGE( "Failed to load CreateDeviceAndImmediateContextD3D11() from ", LibName, " library." );
+ FreeLibrary( hModule );
+ return;
+ }
+
+ CreateSwapChainFunc = reinterpret_cast<CreateSwapChainD3D11Type>( GetProcAddress(hModule, "CreateSwapChainD3D11") );
+ if( CreateSwapChainFunc == NULL )
+ {
+ LOG_ERROR_MESSAGE( "Failed to load CreateSwapChainD3D11() from ", LibName, " library." );
+ FreeLibrary( hModule );
+ return;
+ }
+ }
+#else
+ void CreateDeviceAndImmediateContextD3D11( const Diligent::EngineCreationAttribs& CreationAttribs,
+ Diligent::IRenderDevice **ppDevice,
+ Diligent::IDeviceContext **ppContext );
+ void CreateSwapChainD3D11( Diligent::IRenderDevice *pDevice,
+ Diligent::IDeviceContext *pImmediateContext,
+ const Diligent::SwapChainDesc& SwapChainDesc,
+ void* pNativeWndHandle,
+ Diligent::ISwapChain **ppSwapChain );
+#endif
+} \ No newline at end of file
diff --git a/Graphics/GraphicsEngineD3D11/interface/SamplerD3D11.h b/Graphics/GraphicsEngineD3D11/interface/SamplerD3D11.h
new file mode 100644
index 00000000..4266f89b
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/interface/SamplerD3D11.h
@@ -0,0 +1,50 @@
+/* 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
+/// Definition of the Diligent::ISamplerD3D11 interface
+
+#include "Sampler.h"
+
+namespace Diligent
+{
+
+// {31A3BFAF-738E-4D8C-AD18-B021C5D948DD}
+static const Diligent::INTERFACE_ID IID_SamplerD3D11 =
+{ 0x31a3bfaf, 0x738e, 0x4d8c, { 0xad, 0x18, 0xb0, 0x21, 0xc5, 0xd9, 0x48, 0xdd } };
+
+/// Interface to the sampler object implemented in D3D11
+class ISamplerD3D11 : public Diligent::ISampler
+{
+public:
+
+ /// Returns a pointer to the ID3D11SamplerState interface of the internal Direct3D11 object.
+
+ /// The method does *NOT* call AddRef() on the returned interface,
+ /// so Release() must not be called.
+ virtual ID3D11SamplerState* GetD3D11SamplerState() = 0;
+};
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/interface/ShaderD3D11.h b/Graphics/GraphicsEngineD3D11/interface/ShaderD3D11.h
new file mode 100644
index 00000000..c05cf13f
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/interface/ShaderD3D11.h
@@ -0,0 +1,50 @@
+/* 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
+/// Definition of the Diligent::IShaderD3D11 interface
+
+#include "Shader.h"
+
+namespace Diligent
+{
+
+// {C513E83E-B037-405B-8B49-BF8F5C220DEE}
+static const Diligent::INTERFACE_ID IID_ShaderD3D11 =
+{ 0xc513e83e, 0xb037, 0x405b, { 0x8b, 0x49, 0xbf, 0x8f, 0x5c, 0x22, 0xd, 0xee } };
+
+/// Interface to the shader object implemented in D3D11
+class IShaderD3D11 : public Diligent::IShader
+{
+public:
+
+ /// Returns a pointer to the ID3D11DeviceChild interface of the internal Direct3D11 object.
+
+ /// The method does *NOT* call AddRef() on the returned interface,
+ /// so Release() must not be called.
+ virtual ID3D11DeviceChild* GetD3D11Shader() = 0;
+};
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/interface/SwapChainD3D11.h b/Graphics/GraphicsEngineD3D11/interface/SwapChainD3D11.h
new file mode 100644
index 00000000..2419a8ec
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/interface/SwapChainD3D11.h
@@ -0,0 +1,50 @@
+/* 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
+/// Definition of the Diligent::ISwapChainD3D11 interface
+
+#include "SwapChain.h"
+
+namespace Diligent
+{
+
+// {4DAF2E76-9204-4DC4-A53A-B00097412D3A}
+static const Diligent::INTERFACE_ID IID_SwapChainD3D11 =
+{ 0x4daf2e76, 0x9204, 0x4dc4, { 0xa5, 0x3a, 0xb0, 0x0, 0x97, 0x41, 0x2d, 0x3a } };
+
+/// Interface to the swap chain object implemented in D3D11
+class ISwapChainD3D11 : public Diligent::ISwapChain
+{
+public:
+
+ /// Returns a pointer to the IDXGISwapChain interface of the internal DXGI object.
+
+ /// The method does *NOT* call AddRef() on the returned interface,
+ /// so Release() must not be called.
+ virtual IDXGISwapChain *GetDXGISwapChain() = 0;
+};
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/interface/TextureD3D11.h b/Graphics/GraphicsEngineD3D11/interface/TextureD3D11.h
new file mode 100644
index 00000000..a08ff236
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/interface/TextureD3D11.h
@@ -0,0 +1,50 @@
+/* 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
+/// Definition of the Diligent::ITextureD3D11 interface
+
+#include "Texture.h"
+
+namespace Diligent
+{
+
+// {F3A84CC2-E485-4E72-A08A-437D7FFBA3AB}
+static const Diligent::INTERFACE_ID IID_TextureD3D11 =
+{ 0xf3a84cc2, 0xe485, 0x4e72, { 0xa0, 0x8a, 0x43, 0x7d, 0x7f, 0xfb, 0xa3, 0xab } };
+
+/// Interface to the texture object implemented in D3D11
+class ITextureD3D11 : public Diligent::ITexture
+{
+public:
+
+ /// Returns a pointer to the ID3D11Resource interface of the internal Direct3D11 object.
+
+ /// The method does *NOT* call AddRef() on the returned interface,
+ /// so Release() must not be called.
+ virtual ID3D11Resource* GetD3D11Texture() = 0;
+};
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/interface/TextureViewD3D11.h b/Graphics/GraphicsEngineD3D11/interface/TextureViewD3D11.h
new file mode 100644
index 00000000..7b44ca0b
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/interface/TextureViewD3D11.h
@@ -0,0 +1,50 @@
+/* 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
+/// Definition of the Diligent::ITextureViewD3D11 interface
+
+#include "TextureView.h"
+
+namespace Diligent
+{
+
+// {0767EBE4-AD47-4E70-9B65-38C6B9CAC37D}
+static const Diligent::INTERFACE_ID IID_TextureViewD3D11 =
+{ 0x767ebe4, 0xad47, 0x4e70, { 0x9b, 0x65, 0x38, 0xc6, 0xb9, 0xca, 0xc3, 0x7d } };
+
+/// Interface to the texture view object implemented in D3D11
+class ITextureViewD3D11 : public Diligent::ITextureView
+{
+public:
+
+ /// Returns a pointer to the ID3D11View interface of the internal Direct3D11 object.
+
+ /// The method does *NOT* call AddRef() on the returned interface,
+ /// so Release() must not be called.
+ virtual ID3D11View* GetD3D11View() = 0;
+};
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/interface/VertexDescriptionD3D11.h b/Graphics/GraphicsEngineD3D11/interface/VertexDescriptionD3D11.h
new file mode 100644
index 00000000..ab75bfba
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/interface/VertexDescriptionD3D11.h
@@ -0,0 +1,50 @@
+/* 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
+/// Definition of the Diligent::IVertexDescriptionD3D11 interface
+
+#include "VertexDescription.h"
+
+namespace Diligent
+{
+
+// {7BCB2412-60EB-451C-9167-F31B869484C1}
+static const Diligent::INTERFACE_ID IID_VertexDescriptionD3D11 =
+{ 0x7bcb2412, 0x60eb, 0x451c, { 0x91, 0x67, 0xf3, 0x1b, 0x86, 0x94, 0x84, 0xc1 } };
+
+/// Interface to the vertex description object implemented in D3D11
+class IVertexDescriptionD3D11 : public Diligent::IVertexDescription
+{
+public:
+
+ /// Returns a pointer to the ID3D11InputLayout interface of the internal Direct3D11 object.
+
+ /// The method does *NOT* call AddRef() on the returned interface,
+ /// so Release() must not be called.
+ virtual ID3D11InputLayout* GetD3D11InputLayout() = 0;
+};
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/src/BlendStateD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/BlendStateD3D11Impl.cpp
new file mode 100644
index 00000000..eb336523
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/src/BlendStateD3D11Impl.cpp
@@ -0,0 +1,144 @@
+/* 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.
+ */
+
+#include "pch.h"
+#include "BlendStateD3D11Impl.h"
+#include "RenderDeviceD3D11Impl.h"
+
+namespace Diligent
+{
+
+D3D11_BLEND BlendFactorToD3D11Blend( BLEND_FACTOR bf )
+{
+ // Note that this code is safe for multithreaded environments since
+ // bIsInit is set to true only AFTER the entire map is initialized.
+ static bool bIsInit = false;
+ static D3D11_BLEND D3D11Blend[BLEND_FACTOR_NUM_FACTORS] = {};
+ if( !bIsInit )
+ {
+ // In a multithreaded environment, several threads can potentially enter
+ // this block. This is not a problem since they will just initialize the
+ // memory with the same values more than once
+ D3D11Blend[ BLEND_FACTOR_ZERO ] = D3D11_BLEND_ZERO;
+ D3D11Blend[ BLEND_FACTOR_ONE ] = D3D11_BLEND_ONE;
+ D3D11Blend[ BLEND_FACTOR_SRC_COLOR ] = D3D11_BLEND_SRC_COLOR;
+ D3D11Blend[ BLEND_FACTOR_INV_SRC_COLOR ] = D3D11_BLEND_INV_SRC_COLOR;
+ D3D11Blend[ BLEND_FACTOR_SRC_ALPHA ] = D3D11_BLEND_SRC_ALPHA;
+ D3D11Blend[ BLEND_FACTOR_INV_SRC_ALPHA ] = D3D11_BLEND_INV_SRC_ALPHA;
+ D3D11Blend[ BLEND_FACTOR_DEST_ALPHA ] = D3D11_BLEND_DEST_ALPHA;
+ D3D11Blend[ BLEND_FACTOR_INV_DEST_ALPHA ] = D3D11_BLEND_INV_DEST_ALPHA;
+ D3D11Blend[ BLEND_FACTOR_DEST_COLOR ] = D3D11_BLEND_DEST_COLOR;
+ D3D11Blend[ BLEND_FACTOR_INV_DEST_COLOR ] = D3D11_BLEND_INV_DEST_COLOR;
+ D3D11Blend[ BLEND_FACTOR_SRC_ALPHA_SAT ] = D3D11_BLEND_SRC_ALPHA_SAT;
+ D3D11Blend[ BLEND_FACTOR_BLEND_FACTOR ] = D3D11_BLEND_BLEND_FACTOR;
+ D3D11Blend[ BLEND_FACTOR_INV_BLEND_FACTOR ] = D3D11_BLEND_INV_BLEND_FACTOR;
+ D3D11Blend[ BLEND_FACTOR_SRC1_COLOR ] = D3D11_BLEND_SRC1_COLOR;
+ D3D11Blend[ BLEND_FACTOR_INV_SRC1_COLOR ] = D3D11_BLEND_INV_SRC1_COLOR;
+ D3D11Blend[ BLEND_FACTOR_SRC1_ALPHA ] = D3D11_BLEND_SRC1_ALPHA;
+ D3D11Blend[ BLEND_FACTOR_INV_SRC1_ALPHA ] = D3D11_BLEND_INV_SRC1_ALPHA;
+
+ bIsInit = true;
+ }
+ if( bf > BLEND_FACTOR_UNDEFINED && bf < BLEND_FACTOR_NUM_FACTORS )
+ {
+ auto d3dbf = D3D11Blend[bf];
+ VERIFY( d3dbf != 0, "Incorrect blend factor" );
+ return d3dbf;
+ }
+ else
+ {
+ UNEXPECTED("Incorrect blend factor (", bf, ")" )
+ return static_cast<D3D11_BLEND>( 0 );
+ }
+}
+
+D3D11_BLEND_OP BlendOperation2D3D11BlendOp( BLEND_OPERATION BlendOp )
+{
+ static bool bIsInit = false;
+ static D3D11_BLEND_OP D3D11BlendOp[BLEND_OPERATION_NUM_OPERATIONS] = {};
+ if( !bIsInit )
+ {
+ D3D11BlendOp[ BLEND_OPERATION_ADD ] = D3D11_BLEND_OP_ADD;
+ D3D11BlendOp[ BLEND_OPERATION_SUBTRACT ] = D3D11_BLEND_OP_SUBTRACT;
+ D3D11BlendOp[ BLEND_OPERATION_REV_SUBTRACT ] = D3D11_BLEND_OP_REV_SUBTRACT;
+ D3D11BlendOp[ BLEND_OPERATION_MIN ] = D3D11_BLEND_OP_MIN;
+ D3D11BlendOp[ BLEND_OPERATION_MAX ] = D3D11_BLEND_OP_MAX;
+
+ bIsInit = true;
+ }
+
+ if( BlendOp > BLEND_OPERATION_UNDEFINED && BlendOp < BLEND_OPERATION_NUM_OPERATIONS )
+ {
+ auto d3dbop = D3D11BlendOp[BlendOp];
+ VERIFY( d3dbop != 0, "Incorrect blend operation" );
+ return d3dbop;
+ }
+ else
+ {
+ UNEXPECTED( "Incorrect blend operation (", BlendOp, ")" )
+ return static_cast<D3D11_BLEND_OP>(0);
+ }
+}
+
+BlendStateD3D11Impl::BlendStateD3D11Impl(class RenderDeviceD3D11Impl *pRenderDeviceD3D11,
+ const BlendStateDesc& BlendStateDesc) :
+ TBlendStateBase(pRenderDeviceD3D11, BlendStateDesc)
+{
+ D3D11_BLEND_DESC D3D11BSDesc;
+ D3D11BSDesc.AlphaToCoverageEnable = BlendStateDesc.AlphaToCoverageEnable ? TRUE : FALSE;
+ D3D11BSDesc.IndependentBlendEnable = BlendStateDesc.IndependentBlendEnable ? TRUE : FALSE;
+ VERIFY( BlendStateDesc.MaxRenderTargets >= 8, "Number of render targets is expected to be at least 8" );
+ for( int i = 0; i < 8; ++i )
+ {
+ const auto& SrcRTDesc = BlendStateDesc.RenderTargets[i];
+ auto &DstRTDesc = D3D11BSDesc.RenderTarget[i];
+ DstRTDesc.BlendEnable = SrcRTDesc.BlendEnable ? TRUE : FALSE;
+
+ DstRTDesc.SrcBlend = BlendFactorToD3D11Blend(SrcRTDesc.SrcBlend);
+ DstRTDesc.DestBlend = BlendFactorToD3D11Blend(SrcRTDesc.DestBlend);
+ DstRTDesc.BlendOp = BlendOperation2D3D11BlendOp(SrcRTDesc.BlendOp);
+
+ DstRTDesc.SrcBlendAlpha = BlendFactorToD3D11Blend(SrcRTDesc.SrcBlendAlpha);
+ DstRTDesc.DestBlendAlpha = BlendFactorToD3D11Blend(SrcRTDesc.DestBlendAlpha);
+ DstRTDesc.BlendOpAlpha = BlendOperation2D3D11BlendOp(SrcRTDesc.BlendOpAlpha);
+
+ DstRTDesc.RenderTargetWriteMask =
+ ((SrcRTDesc.RenderTargetWriteMask & COLOR_MASK_RED) ? D3D11_COLOR_WRITE_ENABLE_RED : 0) |
+ ((SrcRTDesc.RenderTargetWriteMask & COLOR_MASK_GREEN) ? D3D11_COLOR_WRITE_ENABLE_GREEN : 0) |
+ ((SrcRTDesc.RenderTargetWriteMask & COLOR_MASK_BLUE) ? D3D11_COLOR_WRITE_ENABLE_BLUE : 0) |
+ ((SrcRTDesc.RenderTargetWriteMask & COLOR_MASK_ALPHA) ? D3D11_COLOR_WRITE_ENABLE_ALPHA : 0);
+ }
+
+ auto *pDeviceD3D11 = pRenderDeviceD3D11->GetD3D11Device();
+ CHECK_D3D_RESULT_THROW( pDeviceD3D11->CreateBlendState( &D3D11BSDesc, &m_pd3d11BlendState ),
+ "Failed to create D3D11 blend state object" );
+}
+
+BlendStateD3D11Impl::~BlendStateD3D11Impl()
+{
+
+}
+
+IMPLEMENT_QUERY_INTERFACE( BlendStateD3D11Impl, IID_BlendStateD3D11, TBlendStateBase )
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/src/BufferD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/BufferD3D11Impl.cpp
new file mode 100644
index 00000000..97905e47
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/src/BufferD3D11Impl.cpp
@@ -0,0 +1,237 @@
+/* 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.
+ */
+
+#include "pch.h"
+#include "BufferD3D11Impl.h"
+#include "RenderDeviceD3D11Impl.h"
+#include "DeviceContextD3D11Impl.h"
+#include "D3D11TypeConversions.h"
+#include "BufferViewD3D11Impl.h"
+#include "GraphicsUtilities.h"
+
+using namespace Diligent;
+
+namespace Diligent
+{
+
+BufferD3D11Impl :: BufferD3D11Impl(RenderDeviceD3D11Impl *pRenderDeviceD3D11, const BufferDesc& BuffDesc, const BufferData &BuffData /*= BufferData()*/) :
+ TBufferBase(pRenderDeviceD3D11, BuffDesc)
+{
+#define LOG_BUFFER_ERROR_AND_THROW(...) LOG_ERROR_AND_THROW("Buffer \"", BuffDesc.Name ? BuffDesc.Name : "", "\": ", ##__VA_ARGS__);
+
+ if( BuffDesc.Usage == USAGE_STATIC && BuffData.pData == nullptr )
+ LOG_BUFFER_ERROR_AND_THROW("Static buffer must be initialized with data at creation time");
+ D3D11_BUFFER_DESC D3D11BuffDesc;
+ D3D11BuffDesc.BindFlags = BindFlagsToD3D11BindFlags(BuffDesc.BindFlags);
+ D3D11BuffDesc.ByteWidth = BuffDesc.uiSizeInBytes;
+ D3D11BuffDesc.MiscFlags = 0;
+ if( BuffDesc.BindFlags & BIND_INDIRECT_DRAW_ARGS )
+ {
+ D3D11BuffDesc.MiscFlags |= D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS;
+ }
+ D3D11BuffDesc.Usage = UsageToD3D11Usage(BuffDesc.Usage);
+
+ D3D11BuffDesc.StructureByteStride = 0;
+ if( (BuffDesc.BindFlags & BIND_UNORDERED_ACCESS) )
+ {
+ if( BuffDesc.Mode == BUFFER_MODE_STRUCTURED )
+ {
+ D3D11BuffDesc.MiscFlags |= D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
+ D3D11BuffDesc.StructureByteStride = BuffDesc.ElementByteStride;
+ }
+ else if( BuffDesc.Mode == BUFFER_MODE_FORMATED )
+ {
+ auto ElementStride = GetValueSize( BuffDesc.Format.ValueType ) * BuffDesc.Format.NumComponents;
+ VERIFY( m_Desc.ElementByteStride == 0 || m_Desc.ElementByteStride == ElementStride, "Element byte stride does not match buffer format" );
+ m_Desc.ElementByteStride = ElementStride;
+ if( BuffDesc.Format.ValueType == VT_FLOAT32 || BuffDesc.Format.ValueType == VT_FLOAT16 )
+ m_Desc.Format.IsNormalized = false;
+ }
+ else
+ {
+ UNEXPECTED( "Buffer UAV type is not correct" );
+ }
+ }
+
+ D3D11BuffDesc.CPUAccessFlags = CPUAccessFlagsToD3D11CPUAccessFlags( BuffDesc.CPUAccessFlags );
+
+ D3D11_SUBRESOURCE_DATA InitData;
+ InitData.pSysMem = BuffData.pData;
+ InitData.SysMemPitch = BuffData.DataSize;
+ InitData.SysMemSlicePitch = 0;
+
+ auto *pDeviceD3D11 = pRenderDeviceD3D11->GetD3D11Device();
+ CHECK_D3D_RESULT_THROW( pDeviceD3D11->CreateBuffer(&D3D11BuffDesc, InitData.pSysMem ? &InitData : nullptr, &m_pd3d11Buffer),
+ "Failed to create the Direct3D11 buffer" );
+}
+
+BufferD3D11Impl :: ~BufferD3D11Impl()
+{
+}
+
+IMPLEMENT_QUERY_INTERFACE( BufferD3D11Impl, IID_BufferD3D11, TBufferBase )
+
+void BufferD3D11Impl::UpdateData( IDeviceContext *pContext, Uint32 Offset, Uint32 Size, const PVoid pData )
+{
+ TBufferBase::UpdateData( pContext, Offset, Size, pData );
+
+ auto *pd3d11DeviceContext = static_cast<DeviceContextD3D11Impl*>(pContext)->GetD3D11DeviceContext();
+
+ D3D11_BOX DstBox;
+ DstBox.left = Offset;
+ DstBox.right = Offset + Size;
+ DstBox.top = 0;
+ DstBox.bottom = 1;
+ DstBox.front = 0;
+ DstBox.back = 1;
+ auto *pDstBox = (Offset == 0 && Size == m_Desc.uiSizeInBytes) ? nullptr : &DstBox;
+ pd3d11DeviceContext->UpdateSubresource(m_pd3d11Buffer, 0, pDstBox, pData, 0, 0);
+}
+
+void BufferD3D11Impl :: CopyData(IDeviceContext *pContext, IBuffer *pSrcBuffer, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size)
+{
+ TBufferBase::CopyData( pContext, pSrcBuffer, SrcOffset, DstOffset, Size );
+
+ auto *pd3d11DeviceContext = static_cast<DeviceContextD3D11Impl*>(pContext)->GetD3D11DeviceContext();
+ auto *pSrBufferD3D11Impl = static_cast<BufferD3D11Impl*>( pSrcBuffer );
+
+ D3D11_BOX SrcBox;
+ SrcBox.left = SrcOffset;
+ SrcBox.right = SrcOffset + Size;
+ SrcBox.top = 0;
+ SrcBox.bottom = 1;
+ SrcBox.front = 0;
+ SrcBox.back = 1;
+ pd3d11DeviceContext->CopySubresourceRegion(m_pd3d11Buffer, 0, DstOffset, 0, 0, pSrBufferD3D11Impl->m_pd3d11Buffer, 0, &SrcBox);
+}
+
+void BufferD3D11Impl :: Map(IDeviceContext *pContext, MAP_TYPE MapType, Uint32 MapFlags, PVoid &pMappedData)
+{
+ TBufferBase::Map( pContext, MapType, MapFlags, pMappedData );
+
+ auto *pd3d11DeviceContext = static_cast<DeviceContextD3D11Impl*>(pContext)->GetD3D11DeviceContext();
+ auto d3d11MapType = MapTypeToD3D11MapType(MapType);
+ auto d3d11MapFlags = MapFlagsToD3D11MapFlags(MapFlags);
+
+ D3D11_MAPPED_SUBRESOURCE MappedBuff;
+ HRESULT hr = pd3d11DeviceContext->Map(m_pd3d11Buffer, 0, d3d11MapType, d3d11MapFlags, &MappedBuff);
+
+ pMappedData = SUCCEEDED(hr) ? MappedBuff.pData : nullptr;
+
+ VERIFY( pMappedData || (MapFlags & MAP_FLAG_DO_NOT_WAIT) && (hr == DXGI_ERROR_WAS_STILL_DRAWING), "Map failed" );
+}
+
+void BufferD3D11Impl::Unmap( IDeviceContext *pContext )
+{
+ TBufferBase::Unmap( pContext );
+
+ auto *pd3d11DeviceContext = static_cast<DeviceContextD3D11Impl*>(pContext)->GetD3D11DeviceContext();
+ pd3d11DeviceContext->Unmap(m_pd3d11Buffer, 0);
+}
+
+void BufferD3D11Impl::CreateViewInternal( const BufferViewDesc &OrigViewDesc, IBufferView **ppView, bool bIsDefaultView )
+{
+ VERIFY( ppView != nullptr, "Null pointer provided" );
+ if( !ppView )return;
+ VERIFY( *ppView == nullptr, "Overwriting reference to existing object may cause memory leaks" );
+
+ *ppView = nullptr;
+
+ try
+ {
+ BufferViewDesc ViewDesc = OrigViewDesc;
+ if( ViewDesc.ViewType == BUFFER_VIEW_UNORDERED_ACCESS )
+ {
+ CComPtr<ID3D11UnorderedAccessView> pUAV;
+ CreateUAV( ViewDesc, &pUAV );
+ *ppView = new BufferViewD3D11Impl( GetDevice(), ViewDesc, this, pUAV, bIsDefaultView );
+ }
+ else if( ViewDesc.ViewType == BUFFER_VIEW_SHADER_RESOURCE )
+ {
+ CComPtr<ID3D11ShaderResourceView> pSRV;
+ CreateSRV( ViewDesc, &pSRV );
+ *ppView = new BufferViewD3D11Impl( GetDevice(), ViewDesc, this, pSRV, bIsDefaultView );
+ }
+
+ if( !bIsDefaultView && *ppView )
+ (*ppView)->AddRef();
+ }
+ catch( const std::runtime_error & )
+ {
+ const auto *ViewTypeName = GetBufferViewTypeLiteralName(OrigViewDesc.ViewType);
+ LOG_ERROR("Failed to create view \"", OrigViewDesc.Name ? OrigViewDesc.Name : "", "\" (", ViewTypeName, ") for buffer \"", m_Desc.Name, "\"" )
+ }
+}
+
+void BufferD3D11Impl::CreateUAV( BufferViewDesc &UAVDesc, ID3D11UnorderedAccessView **ppD3D11UAV )
+{
+ D3D11_UNORDERED_ACCESS_VIEW_DESC D3D11_UAVDesc;
+ memset( &D3D11_UAVDesc, 0, sizeof(D3D11_UAVDesc) );
+ const auto &BuffFmt = m_Desc.Format;
+ if( m_Desc.Mode == BUFFER_MODE_FORMATED )
+ D3D11_UAVDesc.Format = TypeToDXGI_Format( BuffFmt.ValueType, BuffFmt.NumComponents, BuffFmt.IsNormalized );
+
+ CorrectBufferViewDesc( UAVDesc );
+ if( UAVDesc.ByteOffset != 0 )
+ {
+ VERIFY( m_Desc.Mode == BUFFER_MODE_STRUCTURED, "Non-zero byte offset is only supported for structured buffers" );
+ }
+ VERIFY( UAVDesc.ViewType == BUFFER_VIEW_UNORDERED_ACCESS, "Incorrect view type: unordered access is expected" );
+ VERIFY( (UAVDesc.ByteOffset % m_Desc.ElementByteStride) == 0, "Byte offest is not multiple of element byte stride" );
+ VERIFY( (UAVDesc.ByteWidth % m_Desc.ElementByteStride) == 0, "Byte width is not multiple of element byte stride" );
+ D3D11_UAVDesc.Buffer.FirstElement = UAVDesc.ByteOffset / m_Desc.ElementByteStride;
+ D3D11_UAVDesc.Buffer.NumElements = UAVDesc.ByteWidth / m_Desc.ElementByteStride;
+ D3D11_UAVDesc.Buffer.Flags = 0; // D3D11_BUFFER_UAV_FLAG_RAW, D3D11_BUFFER_UAV_FLAG_APPEND, D3D11_BUFFER_UAV_FLAG_COUNTER
+ D3D11_UAVDesc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
+
+ auto *pDeviceD3D11 = static_cast<RenderDeviceD3D11Impl*>(GetDevice())->GetD3D11Device();
+ CHECK_D3D_RESULT_THROW( pDeviceD3D11->CreateUnorderedAccessView( m_pd3d11Buffer, &D3D11_UAVDesc, ppD3D11UAV ),
+ "Failed to create D3D11 unordered access view" );
+}
+
+void BufferD3D11Impl::CreateSRV( struct BufferViewDesc &SRVDesc, ID3D11ShaderResourceView **ppD3D11SRV )
+{
+ D3D11_SHADER_RESOURCE_VIEW_DESC D3D11_SRVDesc;
+ memset( &D3D11_SRVDesc, 0, sizeof( D3D11_SRVDesc ) );
+ const auto &BuffFmt = m_Desc.Format;
+ if( m_Desc.Mode == BUFFER_MODE_FORMATED )
+ D3D11_SRVDesc.Format = TypeToDXGI_Format( BuffFmt.ValueType, BuffFmt.NumComponents, BuffFmt.IsNormalized );
+
+ CorrectBufferViewDesc( SRVDesc );
+ if( SRVDesc.ByteOffset != 0 )
+ {
+ VERIFY( m_Desc.Mode == BUFFER_MODE_STRUCTURED, "Non-zero byte offset is only supported for structured buffers" );
+ }
+ VERIFY( SRVDesc.ViewType == BUFFER_VIEW_SHADER_RESOURCE, "Incorrect view type: shader resource is expected" );
+ VERIFY( (SRVDesc.ByteOffset % m_Desc.ElementByteStride) == 0, "Byte offest is not multiple of element byte stride" );
+ VERIFY( (SRVDesc.ByteWidth % m_Desc.ElementByteStride) == 0, "Byte width is not multiple of element byte stride" );
+ D3D11_SRVDesc.Buffer.FirstElement = SRVDesc.ByteOffset / m_Desc.ElementByteStride;
+ D3D11_SRVDesc.Buffer.NumElements = SRVDesc.ByteWidth / m_Desc.ElementByteStride;
+ D3D11_SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
+
+ auto *pDeviceD3D11 = static_cast<RenderDeviceD3D11Impl*>(GetDevice())->GetD3D11Device();
+ CHECK_D3D_RESULT_THROW( pDeviceD3D11->CreateShaderResourceView( m_pd3d11Buffer, &D3D11_SRVDesc, ppD3D11SRV ),
+ "Failed to create D3D11 shader resource view" );
+}
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/src/BufferViewD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/BufferViewD3D11Impl.cpp
new file mode 100644
index 00000000..6f8239d8
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/src/BufferViewD3D11Impl.cpp
@@ -0,0 +1,47 @@
+/* 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.
+ */
+
+#include "pch.h"
+#include "BufferViewD3D11Impl.h"
+
+namespace Diligent
+{
+
+BufferViewD3D11Impl::BufferViewD3D11Impl( IRenderDevice *pDevice,
+ const BufferViewDesc& ViewDesc,
+ IBuffer *pBuffer,
+ ID3D11View* pD3D11View,
+ bool bIsDefaultView ) :
+ TBufferViewBase( pDevice, ViewDesc, pBuffer, bIsDefaultView ),
+ m_pD3D11View( pD3D11View )
+{
+}
+
+ID3D11View* BufferViewD3D11Impl::GetD3D11View()
+{
+ return m_pD3D11View;
+}
+
+IMPLEMENT_QUERY_INTERFACE( BufferViewD3D11Impl, IID_BufferViewD3D11, TBufferViewBase )
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/src/D3D11DebugUtilities.cpp b/Graphics/GraphicsEngineD3D11/src/D3D11DebugUtilities.cpp
new file mode 100644
index 00000000..686df365
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/src/D3D11DebugUtilities.cpp
@@ -0,0 +1,198 @@
+/* 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.
+ */
+
+#include "pch.h"
+#include "D3D11DebugUtilities.h"
+#include "TextureViewD3D11.h"
+#include "BufferViewD3D11.h"
+#include "BufferD3D11.h"
+#include "SamplerD3D11.h"
+#include "GraphicsUtilities.h"
+
+namespace Diligent
+{
+
+#ifdef VERIFY_RESOURCE_ARRAYS
+
+template<typename TResourceArr, typename TD3D11ResourceArr, typename TTestProc>
+void dbgVerifyResourceArraysInternal( TResourceArr &Resources, TD3D11ResourceArr& d3d11Resources, TTestProc TestProc )
+{
+ VERIFY( Resources.size() == d3d11Resources.size(), "Inconsistent resource array sizes (", Resources.size(), ",", d3d11Resources.size(), ")" );
+ auto NumSlots = std::min(Resources.size(), d3d11Resources.size());
+ for( Uint32 Slot = 0; Slot < NumSlots; ++Slot )
+ {
+ auto &Res = Resources.at(Slot);
+ const auto &d3d11Res = d3d11Resources.at( Slot );
+ TestProc( Slot, Res, d3d11Res );
+ }
+}
+
+static const Char* GetD3D11ResName( const ID3D11ShaderResourceView* ){ return "SRV"; }
+static const Char* GetD3D11ResName( const ID3D11UnorderedAccessView* ){ return "UAV"; }
+static const Char* GetD3D11ResName( const ID3D11Buffer* ){ return "constant buffer"; }
+static const Char* GetD3D11ResName( const ID3D11SamplerState* ){ return "sampler"; }
+
+template<typename TBoundResourceType, typename TD3D11ResourceType>
+class dbgVerifyResourceViewArrays
+{
+public:
+ dbgVerifyResourceViewArrays( TEXTURE_VIEW_TYPE TVT, BUFFER_VIEW_TYPE BVT, IShader *pShader ) :
+ TexViewType( TVT ),
+ BuffViewType( BVT ),
+ ShaderTypeName(GetShaderTypeLiteralName(pShader->GetDesc().ShaderType)),
+ ShaderName(pShader->GetDesc().Name)
+ {}
+
+ void operator()( int Slot, const TBoundResourceType& BoundRes, const TD3D11ResourceType* d3d11View )
+ {
+ TD3D11ResourceType *pD3D11ResTypeMarker = nullptr;
+#define VERFIY_RESOURCE_BINDING(Exp, Intro, Res, ...) \
+ VERIFY(Exp, Intro, " \"", Res->GetDesc().Name, "\" bound as ", GetD3D11ResName(pD3D11ResTypeMarker)," to shader \"", ShaderName, "\" (", ShaderTypeName, ") at slot ", Slot, ' ', __VA_ARGS__)
+
+ if( !d3d11View )
+ {
+ VERFIY_RESOURCE_BINDING( !BoundRes.pResource, "Unexpected non-null resource", BoundRes.pResource )
+ VERFIY_RESOURCE_BINDING( !BoundRes.pView, "Unexpected non-null resource view", BoundRes.pView )
+ }
+
+ if( BoundRes.pView )
+ {
+ auto ncView = const_cast<IDeviceObject*>(BoundRes.pView.RawPtr());
+ RefCntAutoPtr<ITextureViewD3D11> pTexView;
+ ncView->QueryInterface( IID_TextureViewD3D11, reinterpret_cast<IObject**>(static_cast<ITextureViewD3D11**>(&pTexView)) );
+ RefCntAutoPtr<IBufferViewD3D11> pBuffView;
+ ncView->QueryInterface( IID_BufferViewD3D11, reinterpret_cast<IObject**>(static_cast<IBufferViewD3D11**>(&pBuffView)) );
+ VERFIY_RESOURCE_BINDING( pTexView || pBuffView, "Resource", ncView, "is expected to be a texture view or a buffer view" );
+ if( pTexView )
+ {
+ auto ViewType = pTexView->GetDesc().ViewType;
+ VERFIY_RESOURCE_BINDING( ViewType == TexViewType, "Texture view", ncView, "has incorrect type: ", GetTexViewTypeLiteralName( TexViewType ), " is expected, while ", GetTexViewTypeLiteralName( ViewType ), " provided" );
+ auto *d3d11RefView = pTexView->GetD3D11View();
+ VERFIY_RESOURCE_BINDING( d3d11RefView == d3d11View && BoundRes.pd3d11View.RawPtr() == d3d11RefView, "Texture view", ncView, "does not match D3D11 resoruce" );
+ auto *pTex = pTexView->GetTexture();
+ VERFIY_RESOURCE_BINDING( pTex == BoundRes.pResource, "Texture view", ncView, "is not the view of resource \"", BoundRes.pResource->GetDesc().Name, "\"" );
+ }
+
+ if( pBuffView )
+ {
+ auto ViewType = pBuffView->GetDesc().ViewType;
+ VERFIY_RESOURCE_BINDING( ViewType == BuffViewType, "Buffer view", ncView, "has incorrect type: ", GetBufferViewTypeLiteralName( BuffViewType ), " is expected, while ", GetBufferViewTypeLiteralName( ViewType ), " provided" );
+ auto *d3d11RefView = pBuffView->GetD3D11View();
+ VERFIY_RESOURCE_BINDING( d3d11RefView == d3d11View && BoundRes.pd3d11View.RawPtr() == d3d11RefView, "Buffer view", ncView, "does not match D3D11 resource" );
+ auto *pBuf = pBuffView->GetBuffer();
+ VERFIY_RESOURCE_BINDING( pBuf == BoundRes.pResource, "Buffer view", ncView, "is not the view of resource \"", BoundRes.pResource->GetDesc().Name, "\"" );
+ }
+ }
+ else
+ {
+ VERIFY( !BoundRes.pResource, "Unexpected non-null resource bound to shader \"", ShaderName, "\" (", ShaderTypeName, ") at slot ", Slot);
+ VERIFY( !BoundRes.pd3d11View, "Unexpected non-null D3D11 resource view bound to shader \"", ShaderName, "\" (", ShaderTypeName, ") at slot ", Slot);
+ }
+ }
+private:
+ TEXTURE_VIEW_TYPE TexViewType;
+ BUFFER_VIEW_TYPE BuffViewType;
+ const Char* ShaderTypeName;
+ const char* ShaderName;
+};
+
+void dbgVerifyResourceArrays( const std::vector< ShaderD3D11Impl::BoundSRV >&SRVs, const std::vector<ID3D11ShaderResourceView*> d3d11SRVs, IShader *pShader )
+{
+ dbgVerifyResourceArraysInternal(SRVs, d3d11SRVs, dbgVerifyResourceViewArrays<ShaderD3D11Impl::BoundSRV, ID3D11ShaderResourceView>(TEXTURE_VIEW_SHADER_RESOURCE, BUFFER_VIEW_SHADER_RESOURCE, pShader));
+}
+
+void dbgVerifyResourceArrays( const std::vector< ShaderD3D11Impl::BoundUAV >&UAVs, const std::vector<ID3D11UnorderedAccessView*> d3d11UAVs, IShader *pShader )
+{
+ dbgVerifyResourceArraysInternal(UAVs, d3d11UAVs, dbgVerifyResourceViewArrays<ShaderD3D11Impl::BoundUAV, ID3D11UnorderedAccessView>(TEXTURE_VIEW_UNORDERED_ACCESS, BUFFER_VIEW_UNORDERED_ACCESS, pShader));
+}
+
+void dbgVerifyResourceArrays( const std::vector< ShaderD3D11Impl::BoundCB >&CBs, const std::vector<ID3D11Buffer*> d3d11CBs, IShader *pShader )
+{
+ const auto* ShaderTypeName = GetShaderTypeLiteralName( pShader->GetDesc().ShaderType );
+ const auto &ShaderName = pShader->GetDesc().Name;
+ ID3D11Buffer *pD3D11ResTypeMarker = nullptr;
+
+ dbgVerifyResourceArraysInternal( CBs, d3d11CBs,
+ [&]( int Slot, const ShaderD3D11Impl::BoundCB& CB, const ID3D11Buffer* d3d11CB )
+ {
+ if( !d3d11CB )
+ {
+ VERFIY_RESOURCE_BINDING( !CB.pBuff, "Unexpected non-null resource", CB.pBuff )
+ }
+
+ if( CB.pBuff )
+ {
+ auto ncCB = const_cast<IDeviceObject*>(CB.pBuff.RawPtr());
+ RefCntAutoPtr<IBufferD3D11> pBuff;
+ ncCB->QueryInterface( IID_BufferD3D11, reinterpret_cast<IObject**>(static_cast<IBufferD3D11**>(&pBuff)) );
+ VERFIY_RESOURCE_BINDING( pBuff, "Resource", ncCB, "is expected to be a buffer" );
+ if( pBuff )
+ {
+ auto *d3d11RefBuff = pBuff->GetD3D11Buffer();
+ VERFIY_RESOURCE_BINDING( d3d11RefBuff == d3d11CB && d3d11RefBuff == CB.pd3d11Buff, "Constant buffer", ncCB, "does not match D3D11 buffer" );
+ }
+ }
+ else
+ {
+ VERIFY( !d3d11CB, "Unexpected non-null D3D11 buffer bound to shader \"", ShaderName, "\" (", ShaderTypeName, ") at slot ", Slot);
+ }
+ }
+ );
+}
+
+void dbgVerifyResourceArrays( const std::vector< ShaderD3D11Impl::BoundSampler >&Samplers, const std::vector<ID3D11SamplerState*> d3d11Samplers, IShader *pShader )
+{
+ const auto* ShaderTypeName = GetShaderTypeLiteralName( pShader->GetDesc().ShaderType );
+ const auto &ShaderName = pShader->GetDesc().Name;
+ ID3D11SamplerState *pD3D11ResTypeMarker = nullptr;
+
+ dbgVerifyResourceArraysInternal( Samplers, d3d11Samplers,
+ [&]( int Slot, const ShaderD3D11Impl::BoundSampler& Sampler, const ID3D11SamplerState* d3d11Sampler )
+ {
+ if( !d3d11Sampler )
+ {
+ VERFIY_RESOURCE_BINDING( !Sampler.pSampler, "Unexpected non-null resource", Sampler.pSampler )
+ }
+ if( Sampler.pSampler )
+ {
+ auto ncSampler = const_cast<IDeviceObject*>(Sampler.pSampler.RawPtr());
+ RefCntAutoPtr<ISamplerD3D11> pSamplerD3D11;
+ ncSampler->QueryInterface( IID_SamplerD3D11, reinterpret_cast<IObject**>(static_cast<ISamplerD3D11**>(&pSamplerD3D11)) );
+ VERFIY_RESOURCE_BINDING( pSamplerD3D11, "Resource", ncSampler, "is expected to be a sampler" );
+ if( pSamplerD3D11 )
+ {
+ auto *d3d11RefSampler = pSamplerD3D11->GetD3D11SamplerState();
+ VERFIY_RESOURCE_BINDING( d3d11RefSampler == d3d11Sampler && d3d11RefSampler == Sampler.pd3d11Sampler, "Sampler", ncSampler, "does not match D3D11 sampler" );
+ }
+ }
+ else
+ {
+ VERIFY( !d3d11Sampler, "Unexpected non-null D3D11 sampler bound to shader \"", ShaderName, "\" (", ShaderTypeName, ") at slot ", Slot );
+ }
+ }
+ );
+}
+
+#endif
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/src/D3D11TypeConversions.cpp b/Graphics/GraphicsEngineD3D11/src/D3D11TypeConversions.cpp
new file mode 100644
index 00000000..ac6265f2
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/src/D3D11TypeConversions.cpp
@@ -0,0 +1,504 @@
+/* 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.
+ */
+
+#include "pch.h"
+#include "D3D11TypeConversions.h"
+
+namespace Diligent
+{
+
+DXGI_FORMAT TypeToDXGI_Format(VALUE_TYPE ValType, Uint32 NumComponents, Bool bIsNormalized)
+{
+ switch(ValType)
+ {
+ case VT_FLOAT16:
+ {
+ VERIFY( !bIsNormalized, "Floating point formats cannot be normalized" );
+ switch(NumComponents)
+ {
+ case 1: return DXGI_FORMAT_R16_FLOAT;
+ case 2: return DXGI_FORMAT_R16G16_FLOAT;
+ case 4: return DXGI_FORMAT_R16G16B16A16_FLOAT;
+ default: UNEXPECTED("Unusupported number of components" ); return DXGI_FORMAT_UNKNOWN;
+ }
+ }
+
+ case VT_FLOAT32:
+ {
+ VERIFY( !bIsNormalized, "Floating point formats cannot be normalized" );
+ switch(NumComponents)
+ {
+ case 1: return DXGI_FORMAT_R32_FLOAT;
+ case 2: return DXGI_FORMAT_R32G32_FLOAT;
+ case 3: return DXGI_FORMAT_R32G32B32_FLOAT;
+ case 4: return DXGI_FORMAT_R32G32B32A32_FLOAT;
+ default: UNEXPECTED( "Unusupported number of components" ); return DXGI_FORMAT_UNKNOWN;
+ }
+ }
+
+ case VT_INT32:
+ {
+ VERIFY( !bIsNormalized, "32-bit UNORM formats are not supported. Use R32_FLOAT instead" );
+ switch(NumComponents)
+ {
+ case 1: return DXGI_FORMAT_R32_SINT;
+ case 2: return DXGI_FORMAT_R32G32_SINT;
+ case 3: return DXGI_FORMAT_R32G32B32_SINT;
+ case 4: return DXGI_FORMAT_R32G32B32A32_SINT;
+ default: UNEXPECTED("Unusupported number of components" ); return DXGI_FORMAT_UNKNOWN;
+ }
+ }
+
+ case VT_UINT32:
+ {
+ VERIFY( !bIsNormalized, "32-bit UNORM formats are not supported. Use R32_FLOAT instead" );
+ switch(NumComponents)
+ {
+ case 1: return DXGI_FORMAT_R32_UINT;
+ case 2: return DXGI_FORMAT_R32G32_UINT;
+ case 3: return DXGI_FORMAT_R32G32B32_UINT;
+ case 4: return DXGI_FORMAT_R32G32B32A32_UINT;
+ default: UNEXPECTED( "Unusupported number of components" ); return DXGI_FORMAT_UNKNOWN;
+ }
+ }
+
+ case VT_INT16:
+ {
+ if( bIsNormalized )
+ {
+ switch(NumComponents)
+ {
+ case 1: return DXGI_FORMAT_R16_SNORM;
+ case 2: return DXGI_FORMAT_R16G16_SNORM;
+ case 4: return DXGI_FORMAT_R16G16B16A16_SNORM;
+ default: UNEXPECTED( "Unusupported number of components" ); return DXGI_FORMAT_UNKNOWN;
+ }
+ }
+ else
+ {
+ switch(NumComponents)
+ {
+ case 1: return DXGI_FORMAT_R16_SINT;
+ case 2: return DXGI_FORMAT_R16G16_SINT;
+ case 4: return DXGI_FORMAT_R16G16B16A16_SINT;
+ default: UNEXPECTED( "Unusupported number of components" ); return DXGI_FORMAT_UNKNOWN;
+ }
+ }
+ }
+
+ case VT_UINT16:
+ {
+ if( bIsNormalized )
+ {
+ switch(NumComponents)
+ {
+ case 1: return DXGI_FORMAT_R16_UNORM;
+ case 2: return DXGI_FORMAT_R16G16_UNORM;
+ case 4: return DXGI_FORMAT_R16G16B16A16_UNORM;
+ default: UNEXPECTED( "Unusupported number of components" ); return DXGI_FORMAT_UNKNOWN;
+ }
+ }
+ else
+ {
+ switch(NumComponents)
+ {
+ case 1: return DXGI_FORMAT_R16_UINT;
+ case 2: return DXGI_FORMAT_R16G16_UINT;
+ case 4: return DXGI_FORMAT_R16G16B16A16_UINT;
+ default: UNEXPECTED( "Unusupported number of components" ); return DXGI_FORMAT_UNKNOWN;
+ }
+ }
+ }
+
+ case VT_INT8:
+ {
+ if( bIsNormalized )
+ {
+ switch(NumComponents)
+ {
+ case 1: return DXGI_FORMAT_R8_SNORM;
+ case 2: return DXGI_FORMAT_R8G8_SNORM;
+ case 4: return DXGI_FORMAT_R8G8B8A8_SNORM;
+ default: UNEXPECTED( "Unusupported number of components" ); return DXGI_FORMAT_UNKNOWN;
+ }
+ }
+ else
+ {
+ switch(NumComponents)
+ {
+ case 1: return DXGI_FORMAT_R8_SINT;
+ case 2: return DXGI_FORMAT_R8G8_SINT;
+ case 4: return DXGI_FORMAT_R8G8B8A8_SINT;
+ default: UNEXPECTED( "Unusupported number of components" ); return DXGI_FORMAT_UNKNOWN;
+ }
+ }
+ }
+
+ case VT_UINT8:
+ {
+ if( bIsNormalized )
+ {
+ switch(NumComponents)
+ {
+ case 1: return DXGI_FORMAT_R8_UNORM;
+ case 2: return DXGI_FORMAT_R8G8_UNORM;
+ case 4: return DXGI_FORMAT_R8G8B8A8_UNORM;
+ default: UNEXPECTED( "Unusupported number of components" ); return DXGI_FORMAT_UNKNOWN;
+ }
+ }
+ else
+ {
+ switch(NumComponents)
+ {
+ case 1: return DXGI_FORMAT_R8_UINT;
+ case 2: return DXGI_FORMAT_R8G8_UINT;
+ case 4: return DXGI_FORMAT_R8G8B8A8_UINT;
+ default: UNEXPECTED( "Unusupported number of components" ); return DXGI_FORMAT_UNKNOWN;
+ }
+ }
+ }
+
+ default: UNEXPECTED( "Unusupported format" ); return DXGI_FORMAT_UNKNOWN;
+ }
+}
+
+DXGI_FORMAT CorrectDXGIFormat( DXGI_FORMAT DXGIFormat, Uint32 BindFlags )
+{
+ if( (BindFlags & BIND_DEPTH_STENCIL) && (BindFlags != BIND_DEPTH_STENCIL) )
+ {
+ switch( DXGIFormat )
+ {
+ case DXGI_FORMAT_R32_FLOAT:
+ case DXGI_FORMAT_D32_FLOAT:
+ DXGIFormat = DXGI_FORMAT_R32_TYPELESS;
+ break;
+
+ case DXGI_FORMAT_R16_UNORM:
+ case DXGI_FORMAT_D16_UNORM:
+ DXGIFormat = DXGI_FORMAT_R16_TYPELESS;
+ break;
+
+ default:
+ UNEXPECTED( "Unsupported format" );
+ break;
+ }
+ }
+
+ if( BindFlags == BIND_DEPTH_STENCIL )
+ {
+ switch( DXGIFormat )
+ {
+ case DXGI_FORMAT_R32_FLOAT:
+ DXGIFormat = DXGI_FORMAT_D32_FLOAT;
+ break;
+
+ case DXGI_FORMAT_R16_UNORM:
+ DXGIFormat = DXGI_FORMAT_D16_UNORM;
+ break;
+ }
+ }
+
+ if( BindFlags == BIND_SHADER_RESOURCE || BindFlags == BIND_UNORDERED_ACCESS )
+ {
+ switch( DXGIFormat )
+ {
+ case DXGI_FORMAT_D32_FLOAT:
+ DXGIFormat = DXGI_FORMAT_R32_FLOAT;
+ break;
+
+ case DXGI_FORMAT_D16_UNORM:
+ DXGIFormat = DXGI_FORMAT_R16_UNORM;
+ break;
+ }
+ }
+
+ return DXGIFormat;
+}
+
+DXGI_FORMAT TexFormatToDXGI_Format(TEXTURE_FORMAT TexFormat, Uint32 BindFlags)
+{
+ static Bool bFormatMapIntialized = false;
+ static DXGI_FORMAT FmtToDXGIFmtMap[TEX_FORMAT_NUM_FORMATS] = {DXGI_FORMAT_UNKNOWN};
+ if( !bFormatMapIntialized )
+ {
+ FmtToDXGIFmtMap[ TEX_FORMAT_UNKNOWN ] = DXGI_FORMAT_UNKNOWN;
+
+ FmtToDXGIFmtMap[ TEX_FORMAT_RGBA32_TYPELESS ] = DXGI_FORMAT_R32G32B32A32_TYPELESS;
+ FmtToDXGIFmtMap[ TEX_FORMAT_RGBA32_FLOAT ] = DXGI_FORMAT_R32G32B32A32_FLOAT;
+ FmtToDXGIFmtMap[ TEX_FORMAT_RGBA32_UINT ] = DXGI_FORMAT_R32G32B32A32_UINT;
+ FmtToDXGIFmtMap[ TEX_FORMAT_RGBA32_SINT ] = DXGI_FORMAT_R32G32B32A32_SINT;
+
+ FmtToDXGIFmtMap[ TEX_FORMAT_RGB32_TYPELESS ] = DXGI_FORMAT_R32G32B32_TYPELESS;
+ FmtToDXGIFmtMap[ TEX_FORMAT_RGB32_FLOAT ] = DXGI_FORMAT_R32G32B32_FLOAT;
+ FmtToDXGIFmtMap[ TEX_FORMAT_RGB32_UINT ] = DXGI_FORMAT_R32G32B32_UINT;
+ FmtToDXGIFmtMap[ TEX_FORMAT_RGB32_SINT ] = DXGI_FORMAT_R32G32B32_SINT;
+
+ FmtToDXGIFmtMap[ TEX_FORMAT_RGBA16_TYPELESS ] = DXGI_FORMAT_R16G16B16A16_TYPELESS;
+ FmtToDXGIFmtMap[ TEX_FORMAT_RGBA16_FLOAT ] = DXGI_FORMAT_R16G16B16A16_FLOAT;
+ FmtToDXGIFmtMap[ TEX_FORMAT_RGBA16_UNORM ] = DXGI_FORMAT_R16G16B16A16_UNORM;
+ FmtToDXGIFmtMap[ TEX_FORMAT_RGBA16_UINT ] = DXGI_FORMAT_R16G16B16A16_UINT;
+ FmtToDXGIFmtMap[ TEX_FORMAT_RGBA16_SNORM ] = DXGI_FORMAT_R16G16B16A16_SNORM;
+ FmtToDXGIFmtMap[ TEX_FORMAT_RGBA16_SINT ] = DXGI_FORMAT_R16G16B16A16_SINT;
+
+ FmtToDXGIFmtMap[ TEX_FORMAT_RG32_TYPELESS ] = DXGI_FORMAT_R32G32_TYPELESS;
+ FmtToDXGIFmtMap[ TEX_FORMAT_RG32_FLOAT ] = DXGI_FORMAT_R32G32_FLOAT;
+ FmtToDXGIFmtMap[ TEX_FORMAT_RG32_UINT ] = DXGI_FORMAT_R32G32_UINT;
+ FmtToDXGIFmtMap[ TEX_FORMAT_RG32_SINT ] = DXGI_FORMAT_R32G32_SINT;
+
+ FmtToDXGIFmtMap[ TEX_FORMAT_R32G8X24_TYPELESS ] = DXGI_FORMAT_R32G8X24_TYPELESS;
+ FmtToDXGIFmtMap[ TEX_FORMAT_D32_FLOAT_S8X24_UINT ] = DXGI_FORMAT_D32_FLOAT_S8X24_UINT;
+ FmtToDXGIFmtMap[ TEX_FORMAT_R32_FLOAT_X8X24_TYPELESS ]= DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS;
+ FmtToDXGIFmtMap[ TEX_FORMAT_X32_TYPELESS_G8X24_UINT ]= DXGI_FORMAT_X32_TYPELESS_G8X24_UINT;
+
+ FmtToDXGIFmtMap[ TEX_FORMAT_RGB10A2_TYPELESS ] = DXGI_FORMAT_R10G10B10A2_TYPELESS;
+ FmtToDXGIFmtMap[ TEX_FORMAT_RGB10A2_UNORM ] = DXGI_FORMAT_R10G10B10A2_UNORM;
+ FmtToDXGIFmtMap[ TEX_FORMAT_RGB10A2_UINT ] = DXGI_FORMAT_R10G10B10A2_UINT;
+
+ FmtToDXGIFmtMap[ TEX_FORMAT_R11G11B10_FLOAT ] = DXGI_FORMAT_R11G11B10_FLOAT;
+
+ FmtToDXGIFmtMap[ TEX_FORMAT_RGBA8_TYPELESS ] = DXGI_FORMAT_R8G8B8A8_TYPELESS;
+ FmtToDXGIFmtMap[ TEX_FORMAT_RGBA8_UNORM ] = DXGI_FORMAT_R8G8B8A8_UNORM;
+ FmtToDXGIFmtMap[ TEX_FORMAT_RGBA8_UNORM_SRGB ] = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
+ FmtToDXGIFmtMap[ TEX_FORMAT_RGBA8_UINT ] = DXGI_FORMAT_R8G8B8A8_UINT;
+ FmtToDXGIFmtMap[ TEX_FORMAT_RGBA8_SNORM ] = DXGI_FORMAT_R8G8B8A8_SNORM;
+ FmtToDXGIFmtMap[ TEX_FORMAT_RGBA8_SINT ] = DXGI_FORMAT_R8G8B8A8_SINT;
+
+ FmtToDXGIFmtMap[ TEX_FORMAT_RG16_TYPELESS ] = DXGI_FORMAT_R16G16_TYPELESS;
+ FmtToDXGIFmtMap[ TEX_FORMAT_RG16_FLOAT ] = DXGI_FORMAT_R16G16_FLOAT;
+ FmtToDXGIFmtMap[ TEX_FORMAT_RG16_UNORM ] = DXGI_FORMAT_R16G16_UNORM;
+ FmtToDXGIFmtMap[ TEX_FORMAT_RG16_UINT ] = DXGI_FORMAT_R16G16_UINT;
+ FmtToDXGIFmtMap[ TEX_FORMAT_RG16_SNORM ] = DXGI_FORMAT_R16G16_SNORM;
+ FmtToDXGIFmtMap[ TEX_FORMAT_RG16_SINT ] = DXGI_FORMAT_R16G16_SINT;
+
+ FmtToDXGIFmtMap[ TEX_FORMAT_R32_TYPELESS ] = DXGI_FORMAT_R32_TYPELESS;
+ FmtToDXGIFmtMap[ TEX_FORMAT_D32_FLOAT ] = DXGI_FORMAT_D32_FLOAT;
+ FmtToDXGIFmtMap[ TEX_FORMAT_R32_FLOAT ] = DXGI_FORMAT_R32_FLOAT;
+ FmtToDXGIFmtMap[ TEX_FORMAT_R32_UINT ] = DXGI_FORMAT_R32_UINT;
+ FmtToDXGIFmtMap[ TEX_FORMAT_R32_SINT ] = DXGI_FORMAT_R32_SINT;
+
+ FmtToDXGIFmtMap[ TEX_FORMAT_R24G8_TYPELESS ] = DXGI_FORMAT_R24G8_TYPELESS;
+ FmtToDXGIFmtMap[ TEX_FORMAT_D24_UNORM_S8_UINT ] = DXGI_FORMAT_D24_UNORM_S8_UINT;
+ FmtToDXGIFmtMap[ TEX_FORMAT_R24_UNORM_X8_TYPELESS ] = DXGI_FORMAT_R24_UNORM_X8_TYPELESS;
+ FmtToDXGIFmtMap[ TEX_FORMAT_X24_TYPELESS_G8_UINT ] = DXGI_FORMAT_X24_TYPELESS_G8_UINT;
+
+ FmtToDXGIFmtMap[ TEX_FORMAT_RG8_TYPELESS ] = DXGI_FORMAT_R8G8_TYPELESS;
+ FmtToDXGIFmtMap[ TEX_FORMAT_RG8_UNORM ] = DXGI_FORMAT_R8G8_UNORM;
+ FmtToDXGIFmtMap[ TEX_FORMAT_RG8_UINT ] = DXGI_FORMAT_R8G8_UINT;
+ FmtToDXGIFmtMap[ TEX_FORMAT_RG8_SNORM ] = DXGI_FORMAT_R8G8_SNORM;
+ FmtToDXGIFmtMap[ TEX_FORMAT_RG8_SINT ] = DXGI_FORMAT_R8G8_SINT;
+
+ FmtToDXGIFmtMap[ TEX_FORMAT_R16_TYPELESS ] = DXGI_FORMAT_R16_TYPELESS;
+ FmtToDXGIFmtMap[ TEX_FORMAT_R16_FLOAT ] = DXGI_FORMAT_R16_FLOAT;
+ FmtToDXGIFmtMap[ TEX_FORMAT_D16_UNORM ] = DXGI_FORMAT_D16_UNORM;
+ FmtToDXGIFmtMap[ TEX_FORMAT_R16_UNORM ] = DXGI_FORMAT_R16_UNORM;
+ FmtToDXGIFmtMap[ TEX_FORMAT_R16_UINT ] = DXGI_FORMAT_R16_UINT;
+ FmtToDXGIFmtMap[ TEX_FORMAT_R16_SNORM ] = DXGI_FORMAT_R16_SNORM;
+ FmtToDXGIFmtMap[ TEX_FORMAT_R16_SINT ] = DXGI_FORMAT_R16_SINT;
+
+ FmtToDXGIFmtMap[ TEX_FORMAT_R8_TYPELESS ] = DXGI_FORMAT_R8_TYPELESS;
+ FmtToDXGIFmtMap[ TEX_FORMAT_R8_UNORM ] = DXGI_FORMAT_R8_UNORM;
+ FmtToDXGIFmtMap[ TEX_FORMAT_R8_UINT ] = DXGI_FORMAT_R8_UINT;
+ FmtToDXGIFmtMap[ TEX_FORMAT_R8_SNORM ] = DXGI_FORMAT_R8_SNORM;
+ FmtToDXGIFmtMap[ TEX_FORMAT_R8_SINT ] = DXGI_FORMAT_R8_SINT;
+ FmtToDXGIFmtMap[ TEX_FORMAT_A8_UNORM ] = DXGI_FORMAT_A8_UNORM;
+
+ FmtToDXGIFmtMap[ TEX_FORMAT_R1_UNORM ] = DXGI_FORMAT_R1_UNORM ;
+ FmtToDXGIFmtMap[ TEX_FORMAT_RGB9E5_SHAREDEXP ] = DXGI_FORMAT_R9G9B9E5_SHAREDEXP;
+ FmtToDXGIFmtMap[ TEX_FORMAT_RG8_B8G8_UNORM ] = DXGI_FORMAT_R8G8_B8G8_UNORM;
+ FmtToDXGIFmtMap[ TEX_FORMAT_G8R8_G8B8_UNORM ] = DXGI_FORMAT_G8R8_G8B8_UNORM;
+
+ FmtToDXGIFmtMap[ TEX_FORMAT_BC1_TYPELESS ] = DXGI_FORMAT_BC1_TYPELESS;
+ FmtToDXGIFmtMap[ TEX_FORMAT_BC1_UNORM ] = DXGI_FORMAT_BC1_UNORM;
+ FmtToDXGIFmtMap[ TEX_FORMAT_BC1_UNORM_SRGB ] = DXGI_FORMAT_BC1_UNORM_SRGB;
+ FmtToDXGIFmtMap[ TEX_FORMAT_BC2_TYPELESS ] = DXGI_FORMAT_BC2_TYPELESS;
+ FmtToDXGIFmtMap[ TEX_FORMAT_BC2_UNORM ] = DXGI_FORMAT_BC2_UNORM;
+ FmtToDXGIFmtMap[ TEX_FORMAT_BC2_UNORM_SRGB ] = DXGI_FORMAT_BC2_UNORM_SRGB;
+ FmtToDXGIFmtMap[ TEX_FORMAT_BC3_TYPELESS ] = DXGI_FORMAT_BC3_TYPELESS;
+ FmtToDXGIFmtMap[ TEX_FORMAT_BC3_UNORM ] = DXGI_FORMAT_BC3_UNORM;
+ FmtToDXGIFmtMap[ TEX_FORMAT_BC3_UNORM_SRGB ] = DXGI_FORMAT_BC3_UNORM_SRGB;
+ FmtToDXGIFmtMap[ TEX_FORMAT_BC4_TYPELESS ] = DXGI_FORMAT_BC4_TYPELESS;
+ FmtToDXGIFmtMap[ TEX_FORMAT_BC4_UNORM ] = DXGI_FORMAT_BC4_UNORM;
+ FmtToDXGIFmtMap[ TEX_FORMAT_BC4_SNORM ] = DXGI_FORMAT_BC4_SNORM;
+ FmtToDXGIFmtMap[ TEX_FORMAT_BC5_TYPELESS ] = DXGI_FORMAT_BC5_TYPELESS;
+ FmtToDXGIFmtMap[ TEX_FORMAT_BC5_UNORM ] = DXGI_FORMAT_BC5_UNORM;
+ FmtToDXGIFmtMap[ TEX_FORMAT_BC5_SNORM ] = DXGI_FORMAT_BC5_SNORM;
+
+ FmtToDXGIFmtMap[ TEX_FORMAT_B5G6R5_UNORM ] = DXGI_FORMAT_B5G6R5_UNORM;
+ FmtToDXGIFmtMap[ TEX_FORMAT_B5G5R5A1_UNORM ] = DXGI_FORMAT_B5G5R5A1_UNORM;
+ FmtToDXGIFmtMap[ TEX_FORMAT_BGRA8_UNORM ] = DXGI_FORMAT_B8G8R8A8_UNORM;
+ FmtToDXGIFmtMap[ TEX_FORMAT_BGRX8_UNORM ] = DXGI_FORMAT_B8G8R8X8_UNORM;
+
+ FmtToDXGIFmtMap[ TEX_FORMAT_R10G10B10_XR_BIAS_A2_UNORM ]= DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM;
+
+ FmtToDXGIFmtMap[ TEX_FORMAT_BGRA8_TYPELESS ] = DXGI_FORMAT_B8G8R8A8_TYPELESS;
+ FmtToDXGIFmtMap[ TEX_FORMAT_BGRA8_UNORM_SRGB ] = DXGI_FORMAT_B8G8R8A8_UNORM_SRGB;
+ FmtToDXGIFmtMap[ TEX_FORMAT_BGRX8_TYPELESS ] = DXGI_FORMAT_B8G8R8X8_TYPELESS;
+ FmtToDXGIFmtMap[ TEX_FORMAT_BGRX8_UNORM_SRGB ] = DXGI_FORMAT_B8G8R8X8_UNORM_SRGB;
+
+ FmtToDXGIFmtMap[ TEX_FORMAT_BC6H_TYPELESS ] = DXGI_FORMAT_BC6H_TYPELESS;
+ FmtToDXGIFmtMap[ TEX_FORMAT_BC6H_UF16 ] = DXGI_FORMAT_BC6H_UF16;
+ FmtToDXGIFmtMap[ TEX_FORMAT_BC6H_SF16 ] = DXGI_FORMAT_BC6H_SF16;
+ FmtToDXGIFmtMap[ TEX_FORMAT_BC7_TYPELESS ] = DXGI_FORMAT_BC7_TYPELESS ;
+ FmtToDXGIFmtMap[ TEX_FORMAT_BC7_UNORM ] = DXGI_FORMAT_BC7_UNORM;
+ FmtToDXGIFmtMap[ TEX_FORMAT_BC7_UNORM_SRGB ] = DXGI_FORMAT_BC7_UNORM_SRGB;
+
+ bFormatMapIntialized = true;
+ }
+
+ if( TexFormat >= TEX_FORMAT_UNKNOWN && TexFormat < TEX_FORMAT_NUM_FORMATS )
+ {
+ auto DXGIFormat = FmtToDXGIFmtMap[TexFormat];
+ VERIFY( TexFormat == TEX_FORMAT_UNKNOWN || DXGIFormat != DXGI_FORMAT_UNKNOWN, "Unsupported texture format" );
+ if( BindFlags != 0 )
+ DXGIFormat = CorrectDXGIFormat( DXGIFormat, BindFlags );
+ return DXGIFormat;
+ }
+ else
+ {
+ UNEXPECTED( "Texture format (", TexFormat, ") is out of allowed range [0, ", TEX_FORMAT_NUM_FORMATS-1, "]" );
+ return DXGI_FORMAT_UNKNOWN;
+ }
+}
+
+D3D11_FILTER FilterTypeToD3D11Filter(FILTER_TYPE MinFilter, FILTER_TYPE MagFilter, FILTER_TYPE MipFilter)
+{
+ switch( MinFilter )
+ {
+ case FILTER_TYPE_POINT:
+ if( MagFilter == FILTER_TYPE_POINT )
+ {
+ if( MipFilter == FILTER_TYPE_POINT )
+ return D3D11_FILTER_MIN_MAG_MIP_POINT;
+ else if( MipFilter == FILTER_TYPE_LINEAR )
+ return D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR;
+ }
+ else if( MagFilter == FILTER_TYPE_LINEAR )
+ {
+ if( MipFilter == FILTER_TYPE_POINT )
+ return D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT;
+ else if( MipFilter == FILTER_TYPE_LINEAR )
+ return D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR;
+ }
+ break;
+
+ case FILTER_TYPE_LINEAR:
+ if( MagFilter == FILTER_TYPE_POINT )
+ {
+ if( MipFilter == FILTER_TYPE_POINT )
+ return D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT;
+ else if( MipFilter == FILTER_TYPE_LINEAR )
+ return D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR;
+ }
+ else if( MagFilter == FILTER_TYPE_LINEAR )
+ {
+ if( MipFilter == FILTER_TYPE_POINT )
+ return D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT;
+ else if( MipFilter == FILTER_TYPE_LINEAR )
+ return D3D11_FILTER_MIN_MAG_MIP_LINEAR;
+ }
+ break;
+
+ case FILTER_TYPE_ANISOTROPIC:
+ VERIFY( MagFilter == FILTER_TYPE_ANISOTROPIC && MipFilter == FILTER_TYPE_ANISOTROPIC,
+ "For anistropic filtering, all filters must be anisotropic" );
+ return D3D11_FILTER_ANISOTROPIC;
+ break;
+
+ case FILTER_TYPE_COMPARISON_POINT:
+ if( MagFilter == FILTER_TYPE_COMPARISON_POINT )
+ {
+ if( MipFilter == FILTER_TYPE_COMPARISON_POINT )
+ return D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT;
+ else if( MipFilter == FILTER_TYPE_COMPARISON_LINEAR )
+ return D3D11_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR;
+ }
+ else if( MagFilter == FILTER_TYPE_COMPARISON_LINEAR )
+ {
+ if( MipFilter == FILTER_TYPE_COMPARISON_POINT )
+ return D3D11_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT;
+ else if( MipFilter == FILTER_TYPE_COMPARISON_LINEAR )
+ return D3D11_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR;
+ }
+ break;
+
+ case FILTER_TYPE_COMPARISON_LINEAR:
+ if( MagFilter == FILTER_TYPE_COMPARISON_POINT )
+ {
+ if( MipFilter == FILTER_TYPE_COMPARISON_POINT )
+ return D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT;
+ else if( MipFilter == FILTER_TYPE_COMPARISON_LINEAR )
+ return D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR;
+ }
+ else if( MagFilter == FILTER_TYPE_COMPARISON_LINEAR )
+ {
+ if( MipFilter == FILTER_TYPE_COMPARISON_POINT )
+ return D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT;
+ else if( MipFilter == FILTER_TYPE_COMPARISON_LINEAR )
+ return D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR;
+ }
+ break;
+
+ case FILTER_TYPE_COMPARISON_ANISOTROPIC:
+ VERIFY( MagFilter == FILTER_TYPE_COMPARISON_ANISOTROPIC && MipFilter == FILTER_TYPE_COMPARISON_ANISOTROPIC,
+ "For comparison anistropic filtering, all filters must be anisotropic" );
+ return D3D11_FILTER_COMPARISON_ANISOTROPIC;
+ break;
+ }
+
+ UNEXPECTED( "Unsupported filter combination" );
+ return D3D11_FILTER_MIN_MAG_MIP_POINT;
+}
+
+D3D11_STENCIL_OP StencilOpToD3D11StencilOp( STENCIL_OP StencilOp )
+{
+ static bool bIsInit = false;
+ static D3D11_STENCIL_OP StOp2D3D11StOpMap[STENCIL_OP_NUM_OPS] = {};
+ if( !bIsInit )
+ {
+ StOp2D3D11StOpMap[ STENCIL_OP_KEEP ] = D3D11_STENCIL_OP_KEEP;
+ StOp2D3D11StOpMap[ STENCIL_OP_ZERO ] = D3D11_STENCIL_OP_ZERO;
+ StOp2D3D11StOpMap[ STENCIL_OP_REPLACE ] = D3D11_STENCIL_OP_REPLACE;
+ StOp2D3D11StOpMap[ STENCIL_OP_INCR_SAT ] = D3D11_STENCIL_OP_INCR_SAT;
+ StOp2D3D11StOpMap[ STENCIL_OP_DECR_SAT ] = D3D11_STENCIL_OP_DECR_SAT;
+ StOp2D3D11StOpMap[ STENCIL_OP_INVERT ] = D3D11_STENCIL_OP_INVERT;
+ StOp2D3D11StOpMap[ STENCIL_OP_INCR_WRAP] = D3D11_STENCIL_OP_INCR;
+ StOp2D3D11StOpMap[ STENCIL_OP_DECR_WRAP] = D3D11_STENCIL_OP_DECR;
+
+ bIsInit = true;
+ }
+
+ if( StencilOp > STENCIL_OP_UNDEFINED && StencilOp < STENCIL_OP_NUM_OPS )
+ {
+ auto D3D11StencilOp = StOp2D3D11StOpMap[StencilOp];
+ VERIFY( D3D11StencilOp != 0, "Unexpected stencil op" );
+ return D3D11StencilOp;
+ }
+ else
+ {
+ UNEXPECTED( "Stencil operation (", StencilOp, ") is out of allowed range [1, ", STENCIL_OP_NUM_OPS - 1, "]" )
+ return static_cast<D3D11_STENCIL_OP>(0);
+ }
+}
+
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/src/DLLMain.cpp b/Graphics/GraphicsEngineD3D11/src/DLLMain.cpp
new file mode 100644
index 00000000..373d1570
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/src/DLLMain.cpp
@@ -0,0 +1,49 @@
+/* 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.
+ */
+
+#include "pch.h"
+
+BOOL APIENTRY DllMain(HANDLE hModule,
+ DWORD ul_reason_for_call,
+ LPVOID lpReserved)
+{
+ switch( ul_reason_for_call )
+ {
+ case DLL_PROCESS_ATTACH:
+ #if defined(_DEBUG) || defined(DEBUG)
+ _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
+ #endif
+ break;
+
+ case DLL_THREAD_ATTACH:
+ break;
+
+ case DLL_THREAD_DETACH:
+ break;
+
+ case DLL_PROCESS_DETACH:
+ break;
+ }
+
+ return TRUE;
+} \ No newline at end of file
diff --git a/Graphics/GraphicsEngineD3D11/src/DSStateD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/DSStateD3D11Impl.cpp
new file mode 100644
index 00000000..218664c1
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/src/DSStateD3D11Impl.cpp
@@ -0,0 +1,66 @@
+/* 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.
+ */
+
+#include "pch.h"
+#include "DSStateD3D11Impl.h"
+#include "RenderDeviceD3D11Impl.h"
+
+namespace Diligent
+{
+
+D3D11_DEPTH_STENCILOP_DESC StencilOpDesc2D3D11StencilOpDesc(const StencilOpDesc &StOpDesc)
+{
+ D3D11_DEPTH_STENCILOP_DESC D3D11StOpDesc;
+ D3D11StOpDesc.StencilFailOp = StencilOpToD3D11StencilOp( StOpDesc.StencilFailOp );
+ D3D11StOpDesc.StencilDepthFailOp = StencilOpToD3D11StencilOp( StOpDesc.StencilDepthFailOp );
+ D3D11StOpDesc.StencilPassOp = StencilOpToD3D11StencilOp( StOpDesc.StencilPassOp );
+ D3D11StOpDesc.StencilFunc = ComparisonFuncToD3D11ComparisonFunc( StOpDesc.StencilFunc );
+ return D3D11StOpDesc;
+}
+
+DSStateD3D11Impl::DSStateD3D11Impl(class RenderDeviceD3D11Impl *pRenderDeviceD3D11, const DepthStencilStateDesc& DepthStencilStateDesc) :
+ TDepthStencilStateBase(pRenderDeviceD3D11, DepthStencilStateDesc)
+{
+ D3D11_DEPTH_STENCIL_DESC D3D11DSSDesc;
+ D3D11DSSDesc.DepthEnable = DepthStencilStateDesc.DepthEnable ? TRUE : FALSE;
+ D3D11DSSDesc.DepthWriteMask = DepthStencilStateDesc.DepthWriteEnable ? D3D11_DEPTH_WRITE_MASK_ALL : D3D11_DEPTH_WRITE_MASK_ZERO;
+ D3D11DSSDesc.DepthFunc = ComparisonFuncToD3D11ComparisonFunc( DepthStencilStateDesc.DepthFunc );
+ D3D11DSSDesc.StencilEnable = DepthStencilStateDesc.StencilEnable ? TRUE : FALSE;
+ D3D11DSSDesc.StencilReadMask = DepthStencilStateDesc.StencilReadMask;
+ D3D11DSSDesc.StencilWriteMask = DepthStencilStateDesc.StencilWriteMask;
+ D3D11DSSDesc.FrontFace = StencilOpDesc2D3D11StencilOpDesc( DepthStencilStateDesc.FrontFace );
+ D3D11DSSDesc.BackFace = StencilOpDesc2D3D11StencilOpDesc( DepthStencilStateDesc.BackFace );
+
+ auto *pDeviceD3D11 = pRenderDeviceD3D11->GetD3D11Device();
+ CHECK_D3D_RESULT_THROW( pDeviceD3D11->CreateDepthStencilState( &D3D11DSSDesc, &m_pd3d11DepthStencilState ),
+ "Failed to create D3D11 depth stencil state" );
+}
+
+DSStateD3D11Impl::~DSStateD3D11Impl()
+{
+
+}
+
+IMPLEMENT_QUERY_INTERFACE( DSStateD3D11Impl, IID_DepthStencilStateD3D11, TDepthStencilStateBase )
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp
new file mode 100644
index 00000000..a6e14dd5
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp
@@ -0,0 +1,1308 @@
+/* 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.
+ */
+
+#include "pch.h"
+#include "DeviceContextD3D11Impl.h"
+#include "BufferD3D11Impl.h"
+#include "VertexDescD3D11Impl.h"
+#include "ShaderD3D11Impl.h"
+#include "Texture1D_D3D11.h"
+#include "Texture2D_D3D11.h"
+#include "Texture3D_D3D11.h"
+#include "SamplerD3D11Impl.h"
+#include "D3D11TypeConversions.h"
+#include "TextureViewD3D11Impl.h"
+#include "DSStateD3D11Impl.h"
+#include "RasterizerStateD3D11Impl.h"
+#include "BlendStateD3D11Impl.h"
+#include "DSStateD3D11Impl.h"
+#include "SwapChainD3D11Impl.h"
+#include "D3D11DebugUtilities.h"
+
+using namespace Diligent;
+
+namespace Diligent
+{
+
+ DeviceContextD3D11Impl::DeviceContextD3D11Impl( IRenderDevice *pDevice, ID3D11DeviceContext *pd3d11DeviceContext ) :
+ TDeviceContextBase(pDevice),
+ m_pd3d11DeviceContext( pd3d11DeviceContext ),
+ m_BoundD3D11IndexFmt(DXGI_FORMAT_UNKNOWN),
+ m_BoundD3D11IndexDataStartOffset(0)
+ {
+ for( int ShaderType = 0; ShaderType < NumShaderTypes; ++ShaderType )
+ {
+ m_BoundCBs [ShaderType].reserve( D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT ); // 14
+ m_BoundD3D11CBs[ShaderType].reserve( D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT ); // 14
+
+ m_BoundSamplers [ShaderType].reserve( D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT );// 16
+ m_BoundD3D11Samplers[ShaderType].reserve( D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT );// 16
+
+ m_BoundSRVs [ShaderType].reserve( D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT );// 128
+ m_BoundD3D11SRVs[ShaderType].reserve( D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT );// 128
+
+ m_BoundUAVs [ShaderType].reserve( D3D11_PS_CS_UAV_REGISTER_COUNT );// 8
+ m_BoundD3D11UAVs[ShaderType].reserve( D3D11_PS_CS_UAV_REGISTER_COUNT );// 8
+ }
+ }
+
+ IMPLEMENT_QUERY_INTERFACE( DeviceContextD3D11Impl, IID_DeviceContextD3D11, TDeviceContextBase )
+
+ void DeviceContextD3D11Impl::SetShaders( IShader **ppShaders, Uint32 NumShadersToSet )
+ {
+ TDeviceContextBase::SetShaders( ppShaders, NumShadersToSet );
+ }
+
+ void DeviceContextD3D11Impl::BindShaderResources( IResourceMapping *pResourceMapping, Uint32 Flags )
+ {
+ TDeviceContextBase::BindShaderResources( pResourceMapping, Flags );
+ for( auto it = m_pBoundShaders.begin(); it != m_pBoundShaders.end(); ++it )
+ {
+ (*it)->BindResources( pResourceMapping, Flags );
+ }
+ }
+
+
+ SHADER_TYPE GetShaderTypeFromIndex( Int32 Index )
+ {
+ return static_cast<SHADER_TYPE>(1 << Index);
+ }
+
+ Int32 GetShaderTypeIndex( SHADER_TYPE Type )
+ {
+ auto ShaderIndex = 0;
+ switch( Type )
+ {
+ case SHADER_TYPE_UNKNOWN: ShaderIndex = -1; break;
+ case SHADER_TYPE_VERTEX: ShaderIndex = 0; break;
+ case SHADER_TYPE_PIXEL: ShaderIndex = 1; break;
+ case SHADER_TYPE_GEOMETRY:ShaderIndex = 2; break;
+ case SHADER_TYPE_HULL: ShaderIndex = 3; break;
+ case SHADER_TYPE_DOMAIN: ShaderIndex = 4; break;
+ case SHADER_TYPE_COMPUTE: ShaderIndex = 5; break;
+ default: UNEXPECTED( "Unexpected shader type (", Type, ")" ); ShaderIndex = -1;
+ }
+ VERIFY( Type == GetShaderTypeFromIndex(ShaderIndex), "Incorrect shader type index" );
+ return ShaderIndex;
+ }
+
+ const ID3D11Buffer* GetD3D11Resource( const ShaderD3D11Impl::BoundCB &CB ) { return CB.pd3d11Buff; }
+ const ID3D11SamplerState* GetD3D11Resource( const ShaderD3D11Impl::BoundSampler &Sampler ){ return Sampler.pd3d11Sampler; }
+ const ID3D11ShaderResourceView* GetD3D11Resource( const ShaderD3D11Impl::BoundSRV &SRV ) { return SRV.pd3d11View; }
+ const ID3D11UnorderedAccessView* GetD3D11Resource( const ShaderD3D11Impl::BoundUAV &UAV ) { return UAV.pd3d11View; }
+
+ /// This helper template function facilitates binding different D3D11 resources to the device context
+
+ /// \tparam TD3D11ResourceType - Type of D3D11 resource being bound (ID3D11ShaderResourceView,
+ /// ID3D11UnorderedAccessView, ID3D11Buffer or ID3D11SamplerState).
+ /// \tparam TBoundResourceType - Type of the struct describing resources associated with the
+ /// bound entity (ShaderD3D11Impl::BoundCB, ShaderD3D11Impl::BoundSRV, etc.)
+ /// \tparam TGetResourcesMethod - Type of the method that is used to get the bound resources array from
+ /// the shader (such as &ShaderD3D11Impl::GetBoundCBs).
+ /// \tparam TUnbindProc - Type of the procedure that unbinds the resource from the context
+ /// (for instance, if resource is set as SRV, it must be unbound from UAV slots)
+ /// \tparam TD3D11ResourceSetMethod - Type of the method that bounds the new resources to the D3D11
+ /// device context
+ /// \param pShader - Pointer to the shader whose resources are to be bound
+ /// \param BoundResourcesArr - Pointer to the array of structures describing currently bound
+ /// shader resources, for each shader stage
+ /// \param BoundD3D11ResourcesArr - Pointer to the array of currently bound D3D11
+ /// shader resources, for each shader stage
+ /// \param GetResources - Pointer to the method to get array of bound shader resources from the shader
+ /// \param UnbindProc - Function to perform required unbind steps
+ /// \param D3D11ResourceSetMethod - Function to set the new D3D11 resources to the D3D11 device context
+ template<typename TD3D11ResourceType,
+ typename TBoundResourceType,
+ typename TGetResourcesMethod,
+ typename TUnbindProc,
+ typename TD3D11ResourceSetMethod>
+ void UpdateBoundResources(ShaderD3D11Impl *pShader,
+ std::vector<TBoundResourceType> BoundResourcesArr[],
+ std::vector<TD3D11ResourceType*> BoundD3D11ResourcesArr[],
+ TGetResourcesMethod GetResources,
+ TUnbindProc UnbindProc,
+ TD3D11ResourceSetMethod D3D11ResourceSetMethod)
+ {
+ const auto &NewResources = (pShader->*GetResources)();
+ auto NumNewResources = NewResources.size();
+ if( NumNewResources == 0 )
+ return;
+
+ auto ShaderType = pShader->GetDesc().ShaderType;
+ auto ShaderInd = GetShaderTypeIndex(ShaderType);
+ // Get currently bound resources for the shader type
+ auto &BoundResources = BoundResourcesArr [ShaderInd];
+ auto &BoundD3D11Resources = BoundD3D11ResourcesArr[ShaderInd];
+
+ VERIFY(BoundD3D11Resources.size() == BoundResources.size(), "Inconsistent array sizes")
+ if( NumNewResources > BoundD3D11Resources.size() )
+ BoundD3D11Resources.resize(NumNewResources);
+ if( NumNewResources > BoundResources.size() )
+ BoundResources.resize(NumNewResources);
+
+ // Compute the minimum and the maximum slot numbers of updated D3D11 resources
+ Int32 MinSlot = std::numeric_limits<Int32>::max();
+ Int32 MaxSlot = std::numeric_limits<Int32>::min();
+ for( Int32 iSlot = 0; iSlot < static_cast<Int32>(NumNewResources); ++iSlot )
+ {
+ const auto& pNewRes = NewResources [iSlot];
+ const auto& pNewD3D11Res = GetD3D11Resource(pNewRes);
+ if( pNewD3D11Res != nullptr && pNewD3D11Res != BoundD3D11Resources[iSlot] )
+ {
+ // Perform the required steps to unbind the resource
+ UnbindProc( pNewRes );
+
+ MinSlot = std::min( MinSlot, iSlot );
+ MaxSlot = std::max( MaxSlot, iSlot );
+ BoundD3D11Resources[iSlot] = const_cast<TD3D11ResourceType*>(pNewD3D11Res);
+ BoundResources[iSlot] = pNewRes;
+ }
+ }
+
+ if( MaxSlot >= MinSlot )
+ {
+ D3D11ResourceSetMethod(ShaderInd, MinSlot, MaxSlot - MinSlot + 1, &BoundD3D11Resources[MinSlot]);
+ }
+
+ // Verify that the resource array and the D3D11 resource array are consistent
+ dbgVerifyResourceArrays( BoundResources, BoundD3D11Resources, pShader );
+ }
+
+ /// Template function that facilitates binding D3D11 SRVs, CBs and samplers to the device context
+
+ /// \tparam TD3D11ResourceType - Type of D3D11 resource being bound (ID3D11ShaderResourceView,
+ /// ID3D11Buffer or ID3D11SamplerState).
+ /// \tparam TBoundResourceType - Type of the struct describing resources associated with the
+ /// bound entity (ShaderD3D11Impl::BoundCB, ShaderD3D11Impl::BoundSRV, etc.)
+ /// \tparam TGetResourcesMethod - Type of the method that is used to get the bound resources array from
+ /// the shader (such as &ShaderD3D11Impl::GetBoundCBs).
+ /// \tparam TUnbindProc - Type of the procedure that unbinds the resource from the context
+ /// (for instance, if resource is set as SRV, it must be unbound from UAV slots)
+ /// \tparam TSetD3D11Resource - Type of the D3D11 device context method used to set the
+ /// resource (such as &ID3D11DeviceContext::SetShaderResources)
+ /// \param pShader - Pointer to the shader whose resources are to be bound
+ /// \param BoundResourcesArr - Pointer to the array of structures describing currently bound
+ /// shader resources, for each shader stage
+ /// \param BoundD3D11ResourcesArr - Pointer to the array of currently bound D3D11
+ /// shader resources, for each shader stage
+ /// \param GetResources - Pointer to the method to get array of bound shader resources from the shader
+ /// \param UnbindProc - Function to perform required unbind steps
+ /// \param SetD3D11ResourcesArr - Pointer to the array of device context methods used
+ /// to set the resource, for every shader stage
+ /// \param pd3d11DeviceCtx - Device context
+ template<typename TD3D11ResourceType,
+ typename TBoundResourceType,
+ typename TGetResourcesMethod,
+ typename TUnbindProc,
+ typename TSetD3D11Resource>
+ void UpdateBoundResources(ShaderD3D11Impl *pShader,
+ std::vector<TBoundResourceType> BoundResourcesArr[],
+ std::vector<TD3D11ResourceType*> BoundD3D11ResourcesArr[],
+ TGetResourcesMethod GetResources,
+ TUnbindProc UnbindProc,
+ TSetD3D11Resource SetD3D11ResourcesArr[],
+ ID3D11DeviceContext *pd3d11DeviceCtx)
+ {
+ UpdateBoundResources(pShader, BoundResourcesArr, BoundD3D11ResourcesArr,
+ GetResources, UnbindProc,
+ [&](Int32 ShaderInd, UINT MinSlot, UINT NumSlots, TD3D11ResourceType** ppD3D11Resources)
+ {
+ auto SetD3D11Resources = SetD3D11ResourcesArr[ShaderInd];
+ VERIFY(SetD3D11Resources, "Set D3D11 resource function pointer is null.");
+ if( SetD3D11Resources )
+ {
+ (pd3d11DeviceCtx->*SetD3D11Resources)(MinSlot, NumSlots, ppD3D11Resources);
+ }
+ }
+ );
+ }
+
+/// Helper macro used to create an array of device context methods to
+/// set particular resource for every shader stage
+#define DEFINE_D3D11CTX_FUNC_POINTERS(ArrayName, FuncName) \
+ typedef decltype (&ID3D11DeviceContext::VS##FuncName) T##FuncName##Type; \
+ static const T##FuncName##Type ArrayName[] = \
+ { \
+ &ID3D11DeviceContext::VS##FuncName, \
+ &ID3D11DeviceContext::PS##FuncName, \
+ &ID3D11DeviceContext::GS##FuncName, \
+ &ID3D11DeviceContext::HS##FuncName, \
+ &ID3D11DeviceContext::DS##FuncName, \
+ &ID3D11DeviceContext::CS##FuncName \
+ };
+
+ DEFINE_D3D11CTX_FUNC_POINTERS(SetCBMethods, SetConstantBuffers)
+ DEFINE_D3D11CTX_FUNC_POINTERS(SetSRVMethods, SetShaderResources)
+ DEFINE_D3D11CTX_FUNC_POINTERS(SetSamplerMethods, SetSamplers)
+
+ typedef decltype (&ID3D11DeviceContext::CSSetUnorderedAccessViews) TSetUnorderedAccessViewsType;
+ static const TSetUnorderedAccessViewsType SetUAVMethods[] =
+ {
+ nullptr,
+ nullptr,
+ nullptr,
+ nullptr,
+ nullptr,
+ &ID3D11DeviceContext::CSSetUnorderedAccessViews
+ };
+
+ void DeviceContextD3D11Impl::SetD3DConstantBuffers( ShaderD3D11Impl *pShader )
+ {
+ UpdateBoundResources(pShader, m_BoundCBs, m_BoundD3D11CBs,
+ &ShaderD3D11Impl::GetBoundCBs,
+ [&](const ShaderD3D11Impl::BoundCB &BoundCB)
+ {
+ auto *pResource = const_cast<IDeviceObject *>(BoundCB.pBuff.RawPtr());
+ RefCntAutoPtr<IBuffer> pBuff;
+ pResource->QueryInterface( IID_Buffer, reinterpret_cast<IObject**>( static_cast<IBuffer**>(&pBuff) ) );
+ if( pBuff )
+ {
+ if( pBuff->GetDesc().BindFlags & BIND_UNORDERED_ACCESS )
+ UnbindResourceFromUAV( pBuff );
+ }
+ else
+ {
+ UNEXPECTED( "Resource \"", pResource->GetDesc().Name, "\" is expected to be a buffer" )
+ }
+ },
+ SetCBMethods,
+ m_pd3d11DeviceContext );
+ dbgVerifyContextCBs(pShader->GetDesc().ShaderType);
+ }
+
+ void DeviceContextD3D11Impl::SetD3DSRVs( ShaderD3D11Impl *pShader )
+ {
+ UpdateBoundResources(pShader, m_BoundSRVs, m_BoundD3D11SRVs,
+ &ShaderD3D11Impl::GetBoundSRVs,
+ [&](const ShaderD3D11Impl::BoundSRV &BoundSRV)
+ {
+ auto *pResource = const_cast<IDeviceObject *>(BoundSRV.pResource.RawPtr());
+ RefCntAutoPtr<ITexture> pTexture;
+ pResource->QueryInterface( IID_Texture, reinterpret_cast<IObject**>( static_cast<ITexture**>(&pTexture) ) );
+ if( pTexture )
+ {
+ auto BindFlags = pTexture->GetDesc().BindFlags;
+ if( BindFlags & BIND_UNORDERED_ACCESS )
+ UnbindResourceFromUAV(pTexture);
+ if( BindFlags & BIND_RENDER_TARGET )
+ UnbindTextureFromRenderTarget(pTexture);
+ if( BindFlags & BIND_DEPTH_STENCIL )
+ UnbindTextureFromDepthStencil(pTexture);
+ }
+ else
+ {
+ RefCntAutoPtr<IBuffer> pBuffer;
+ pResource->QueryInterface( IID_Buffer, reinterpret_cast<IObject**>(static_cast<IBuffer**>(&pBuffer)) );
+ if( pBuffer )
+ {
+ if( pBuffer->GetDesc().BindFlags & BIND_UNORDERED_ACCESS )
+ UnbindResourceFromUAV( pBuffer );
+ }
+ else
+ {
+ UNEXPECTED( "Resource \"", pResource->GetDesc().Name, "\" is expected to be a texture or a buffer." )
+ }
+ }
+ },
+ SetSRVMethods,
+ m_pd3d11DeviceContext );
+ dbgVerifyContextSRVs(pShader->GetDesc().ShaderType);
+ }
+
+ void DeviceContextD3D11Impl::SetD3DSamplers( ShaderD3D11Impl *pShader )
+ {
+ UpdateBoundResources(pShader, m_BoundSamplers, m_BoundD3D11Samplers,
+ &ShaderD3D11Impl::GetBoundSamplers,
+ [](const ShaderD3D11Impl::BoundSampler& ){}, // Do nothing
+ SetSamplerMethods,
+ m_pd3d11DeviceContext );
+ dbgVerifyContextSamplers(pShader->GetDesc().ShaderType);
+ }
+
+ void DeviceContextD3D11Impl::SetD3DUAVs( ShaderD3D11Impl *pShader )
+ {
+ UpdateBoundResources(pShader, m_BoundUAVs, m_BoundD3D11UAVs,
+ &ShaderD3D11Impl::GetBoundUAVs,
+ [&](const ShaderD3D11Impl::BoundUAV& BoundUAV)
+ {
+ auto *pResource = const_cast<IDeviceObject *>(BoundUAV.pResource.RawPtr());
+ RefCntAutoPtr<ITexture> pTexture;
+ pResource->QueryInterface( IID_Texture, reinterpret_cast<IObject**>( static_cast<ITexture**>(&pTexture) ) );
+ if( pTexture )
+ {
+ // It is unlikely the texture is not used for input, so do not
+ // check the bind flags
+ UnbindTextureFromInput( pTexture );
+ }
+ else
+ {
+ RefCntAutoPtr<IBuffer> pBuffer;
+ pResource->QueryInterface( IID_Buffer, reinterpret_cast<IObject**>(static_cast<IBuffer**>(&pBuffer)) );
+ if( pBuffer )
+ {
+ // It is unlikely the buffer is not used for input, so do not
+ // check the bind flags
+ UnbindBufferFromInput( pBuffer );
+ }
+ else
+ {
+ UNEXPECTED( "Resource \"", pResource->GetDesc().Name, "\" is expected to be a texture or a buffer." )
+ }
+ }
+ },
+ [&](Int32 ShaderInd, UINT MinUAVSlot, UINT NumUAVSlots, ID3D11UnorderedAccessView** ppUAVs)
+ {
+ switch( ShaderInd )
+ {
+ case 0: // SHADER_TYPE_PIXEL:
+ UNSUPPORTED( "UAVs are not currently implemented in pixel shader" );
+ /// \TODO: need to keep track of bound RTVs and provide the render targets here.
+ /// Also, we need to unbind UAVs appropriatelly.
+ /// Maybe deffer actual render target binding to the Draw call()?
+ m_pd3d11DeviceContext->OMSetRenderTargetsAndUnorderedAccessViews( 0, nullptr, nullptr, MinUAVSlot, NumUAVSlots, ppUAVs, nullptr );
+ break;
+
+ case 1: //SHADER_TYPE_VERTEX:
+ case 2: //SHADER_TYPE_GEOMETRY:
+ case 3: //SHADER_TYPE_DOMAIN:
+ case 4: //SHADER_TYPE_HULL:
+ UNSUPPORTED( "UAVs are not currently supported in this type of shader" );
+ break;
+
+ case 5: //SHADER_TYPE_COMPUTE:
+ m_pd3d11DeviceContext->CSSetUnorderedAccessViews( MinUAVSlot, NumUAVSlots, ppUAVs, nullptr );
+ break;
+
+ default: UNEXPECTED( "Unknown shader type" );
+ }
+ }
+ );
+ dbgVerifyContextUAVs(pShader->GetDesc().ShaderType);
+ }
+
+ template<typename TD3D11ShaderType, typename TBindShaderMethdType>
+ void DeviceContextD3D11Impl :: SetD3D11ShaderHelper(Uint32 BoundShaderFlags,
+ ShaderD3D11Impl* NewShaders[],
+ SHADER_TYPE ShaderType,
+ TBindShaderMethdType BindShaderMethod)
+ {
+ auto ShaderTypeInd = GetShaderTypeIndex( ShaderType );
+ auto &BoundD3D11Shader = m_BoundD3DShaders[ShaderTypeInd];
+ auto *pShaderD3D11 = NewShaders[ShaderTypeInd];
+ if( BoundShaderFlags & ShaderType )
+ {
+ VERIFY( pShaderD3D11 != nullptr, "Shader is null" );
+ VERIFY( pShaderD3D11->GetDesc().ShaderType == ShaderType, "Unexpected shader type" );
+ if( BoundD3D11Shader != pShaderD3D11->m_pShader )
+ {
+ BoundD3D11Shader = pShaderD3D11->m_pShader;
+ RefCntAutoPtr<TD3D11ShaderType> pd3d11Shader;
+ pShaderD3D11->m_pShader->QueryInterface(__uuidof(TD3D11ShaderType), reinterpret_cast<void**>( static_cast<TD3D11ShaderType**>(&pd3d11Shader) ) );
+ (m_pd3d11DeviceContext->*BindShaderMethod)(pd3d11Shader, nullptr, 0);
+ }
+ }
+ else
+ {
+ if( BoundD3D11Shader != nullptr )
+ {
+ BoundD3D11Shader = nullptr;
+ (m_pd3d11DeviceContext->*BindShaderMethod)(nullptr, nullptr, 0);
+ }
+ }
+ }
+
+ void DeviceContextD3D11Impl :: SetD3DShadersAndResources()
+ {
+ Uint32 BoundShaderFlags = 0;
+ // Set shaders
+ ShaderD3D11Impl* NewShaders[NumShaderTypes] = {};
+ for( auto it = m_pBoundShaders.begin(); it != m_pBoundShaders.end(); ++it )
+ {
+ auto *pCurrShader = it->RawPtr();
+ if( pCurrShader )
+ {
+ auto ShaderType = pCurrShader->GetDesc().ShaderType;
+ auto *pShaderD3D11 = static_cast<ShaderD3D11Impl*>(pCurrShader);
+ auto ShaderTypeInd = GetShaderTypeIndex(ShaderType);
+ NewShaders[ShaderTypeInd] = pShaderD3D11;
+
+ if( BoundShaderFlags & ShaderType )
+ LOG_ERROR_MESSAGE( "More than one shader of type ", GetShaderTypeLiteralName(ShaderType), " is bound to the context" )
+ BoundShaderFlags |= ShaderType;
+
+#ifdef VERIFY_SHADER_BINDINGS
+ pShaderD3D11->dbgVerifyBindings();
+#endif
+
+ // Set D3D11 shader resources
+ SetD3DConstantBuffers ( pShaderD3D11 );
+ SetD3DSRVs ( pShaderD3D11 );
+ SetD3DSamplers ( pShaderD3D11 );
+ SetD3DUAVs ( pShaderD3D11 );
+ }
+ }
+
+ // There is no need to unbind the compute shader from the context
+ //if( BoundShaderFlags & SHADER_TYPE_COMPUTE )
+ //{
+ // LOG_ERROR_MESSAGE( "Bound compute shader will be ignored by the draw command" )
+ // BoundShaderFlags &= ~SHADER_TYPE_COMPUTE;
+ //}
+
+#define SET_SHADER(NAME, Name, N) SetD3D11ShaderHelper<ID3D11##Name##Shader>(BoundShaderFlags, NewShaders, SHADER_TYPE_##NAME, &ID3D11DeviceContext::N##SSetShader )
+
+ // These shaders which are not set will be unbound from the D3D11 device context
+ SET_SHADER( VERTEX, Vertex, V );
+ SET_SHADER( PIXEL, Pixel, P );
+ SET_SHADER( GEOMETRY, Geometry, G );
+ SET_SHADER( DOMAIN, Domain, D );
+ SET_SHADER( HULL, Hull, H );
+ // There is no need to unbind the compute shader from the context
+ //SET_SHADER( COMPUTE, Compute, C );
+ }
+
+ void DeviceContextD3D11Impl::SetD3DIndexBuffer(VALUE_TYPE IndexType)
+ {
+ if( !m_pIndexBuffer )
+ {
+ LOG_ERROR_MESSAGE( "Index buffer is not set up for indexed draw command" );
+ return;
+ }
+ BufferD3D11Impl *pBuffD3D11 = static_cast<BufferD3D11Impl *>(m_pIndexBuffer.RawPtr());
+ DXGI_FORMAT D3D11IndexFmt = DXGI_FORMAT_UNKNOWN;
+ if( IndexType == VT_UINT32 )
+ D3D11IndexFmt = DXGI_FORMAT_R32_UINT;
+ else if( IndexType == VT_UINT16 )
+ D3D11IndexFmt = DXGI_FORMAT_R16_UINT;
+ else
+ {
+ LOG_ERROR_MESSAGE( "Unsupported index format. Only R16_UINT and R32_UINT are allowed." );
+ return;
+ }
+ if( m_pIndexBuffer->GetDesc().BindFlags & BIND_UNORDERED_ACCESS )
+ UnbindResourceFromUAV(m_pIndexBuffer);
+
+ if( m_BoundD3D11IndexBuffer != pBuffD3D11->m_pd3d11Buffer ||
+ m_BoundD3D11IndexFmt != D3D11IndexFmt ||
+ m_BoundD3D11IndexDataStartOffset != m_IndexDataStartOffset )
+ {
+ m_BoundD3D11IndexBuffer = pBuffD3D11->m_pd3d11Buffer;
+ m_BoundD3D11IndexFmt = D3D11IndexFmt;
+ m_BoundD3D11IndexDataStartOffset = m_IndexDataStartOffset;
+ m_pd3d11DeviceContext->IASetIndexBuffer( pBuffD3D11->m_pd3d11Buffer, D3D11IndexFmt, m_IndexDataStartOffset );
+ }
+ }
+
+ void DeviceContextD3D11Impl::SetD3DVertexBuffers()
+ {
+ auto &VertexDescSP = m_pVertexDesc;
+ if( !VertexDescSP )
+ {
+ // There might be no vertex description if, for instance, full screen quad
+ // is rendered
+ m_pd3d11DeviceContext->IASetInputLayout( nullptr );
+ return;
+ }
+ auto* pVertexDescD3D11 = static_cast<VertexDescD3D11Impl *>(VertexDescSP.RawPtr());
+ m_pd3d11DeviceContext->IASetInputLayout( pVertexDescD3D11->m_pd3d11InputLayout );
+
+ ID3D11Buffer *ppD3D11Buffers[MaxBufferSlots] = { nullptr };
+ UINT Strides[MaxBufferSlots] = { 0 };
+ UINT Offsets[MaxBufferSlots] = { 0 };
+ UINT NumBoundBuffers = static_cast<UINT>(m_VertexStreams.size());
+ VERIFY( NumBoundBuffers <= MaxBufferSlots, "Too many buffers are being set" );
+ NumBoundBuffers = std::min( NumBoundBuffers, static_cast<UINT>(MaxBufferSlots) );
+ const auto *TightStrides = VertexDescSP->GetTightStrides();
+ for( UINT Buff = 0; Buff < NumBoundBuffers; ++Buff )
+ {
+ auto &CurrStream = m_VertexStreams[Buff];
+ VERIFY( CurrStream.pBuffer, "Attempting to bind a null buffer for rendering" );
+ ppD3D11Buffers[Buff] = static_cast<BufferD3D11Impl*>(CurrStream.pBuffer.RawPtr())->m_pd3d11Buffer;
+ Strides[Buff] = CurrStream.Stride ? CurrStream.Stride : TightStrides[Buff];
+ Offsets[Buff] = CurrStream.Offset;
+ if(CurrStream.pBuffer->GetDesc().BindFlags & BIND_UNORDERED_ACCESS)
+ UnbindResourceFromUAV(CurrStream.pBuffer);
+ }
+
+ UINT NumBuffersToSet = NumBoundBuffers;
+ bool BindVBs = false;
+ if( NumBoundBuffers != m_BoundD3D11VertexBuffers.size() )
+ {
+ // If number of currently bound d3d11 buffers is larger than NumBuffersToSet, the
+ // unused buffers will be unbound
+ NumBuffersToSet = std::max(NumBuffersToSet, static_cast<UINT>(m_BoundD3D11VertexBuffers.size()) );
+ m_BoundD3D11VertexBuffers.resize(NumBoundBuffers);
+ m_BoundD3D11VBStrides.resize(NumBoundBuffers);
+ m_BoundD3D11VBOffsets.resize( NumBoundBuffers );
+ BindVBs = true;
+ }
+
+ for( UINT Slot = 0; Slot < NumBoundBuffers; ++Slot )
+ {
+ if( m_BoundD3D11VertexBuffers[Slot] != ppD3D11Buffers[Slot] ||
+ m_BoundD3D11VBStrides[Slot] != Strides[Slot] ||
+ m_BoundD3D11VBOffsets[Slot] != Offsets[Slot] )
+ {
+ BindVBs = true;
+
+ m_BoundD3D11VertexBuffers[Slot] = ppD3D11Buffers[Slot];
+ m_BoundD3D11VBStrides[Slot] = Strides[Slot];
+ m_BoundD3D11VBOffsets[Slot] = Offsets[Slot];
+ }
+ }
+
+ if( BindVBs )
+ {
+ m_pd3d11DeviceContext->IASetVertexBuffers( 0, NumBuffersToSet, ppD3D11Buffers, Strides, Offsets );
+ }
+ }
+
+ void DeviceContextD3D11Impl::Draw( DrawAttribs &DrawAttribs )
+ {
+ m_LastDrawAttribs = DrawAttribs;
+
+ SetD3DShadersAndResources();
+
+ SetD3DVertexBuffers();
+
+ if( DrawAttribs.IsIndexed )
+ {
+ SetD3DIndexBuffer(DrawAttribs.IndexType);
+ }
+
+ // Verify bindings after all resources are set
+ dbgVerifyContextSRVs();
+ dbgVerifyContextUAVs();
+ dbgVerifyContextSamplers();
+ dbgVerifyContextCBs();
+ dbgVerifyVertexBuffers();
+ dbgVerifyIndexBuffer();
+ dbgVerifyShaders();
+
+ auto D3D11Topology = TopologyToDX11Topology( DrawAttribs.Topology );
+ m_pd3d11DeviceContext->IASetPrimitiveTopology( D3D11Topology );
+
+ if( DrawAttribs.IsIndirect )
+ {
+ VERIFY( DrawAttribs.pIndirectDrawAttribs, "Indirect draw command attributes buffer is not set" );
+ auto *pBufferD3D11 = static_cast<BufferD3D11Impl*>(DrawAttribs.pIndirectDrawAttribs);
+ ID3D11Buffer *pd3d11ArgsBuff = pBufferD3D11 ? pBufferD3D11->m_pd3d11Buffer.RawPtr() : nullptr;
+ if( DrawAttribs.IsIndexed )
+ m_pd3d11DeviceContext->DrawIndexedInstancedIndirect( pd3d11ArgsBuff, DrawAttribs.IndirectDrawArgsOffset );
+ else
+ m_pd3d11DeviceContext->DrawInstancedIndirect( pd3d11ArgsBuff, DrawAttribs.IndirectDrawArgsOffset );
+ }
+ else
+ {
+ if( DrawAttribs.NumInstances > 1 )
+ {
+ if( DrawAttribs.IsIndexed )
+ m_pd3d11DeviceContext->DrawIndexedInstanced( DrawAttribs.NumIndices, DrawAttribs.NumInstances, DrawAttribs.FirstIndexLocation, DrawAttribs.BaseVertex, DrawAttribs.FirstInstanceLocation );
+ else
+ m_pd3d11DeviceContext->DrawInstanced( DrawAttribs.NumVertices, DrawAttribs.NumInstances, DrawAttribs.StartVertexLocation, DrawAttribs.FirstInstanceLocation );
+ }
+ else
+ {
+ if( DrawAttribs.IsIndexed )
+ m_pd3d11DeviceContext->DrawIndexed( DrawAttribs.NumIndices, DrawAttribs.FirstIndexLocation, DrawAttribs.BaseVertex );
+ else
+ m_pd3d11DeviceContext->Draw( DrawAttribs.NumVertices, DrawAttribs.StartVertexLocation );
+ }
+ }
+ }
+
+ void DeviceContextD3D11Impl::DispatchCompute( const DispatchComputeAttribs &DispatchAttrs )
+ {
+ bool bCSBound = false;
+ ShaderD3D11Impl* NewShaders[NumShaderTypes] = {};
+ for( auto it = m_pBoundShaders.begin(); it != m_pBoundShaders.end() && !bCSBound; ++it )
+ {
+ auto *pCurrShader = it->RawPtr();
+ if( pCurrShader && pCurrShader->GetDesc().ShaderType == SHADER_TYPE_COMPUTE )
+ {
+ bCSBound = true;
+ auto *pShaderD3D11 = ValidatedCast<ShaderD3D11Impl>(pCurrShader);
+ NewShaders[GetShaderTypeIndex(SHADER_TYPE_COMPUTE)] = pShaderD3D11;
+ SetD3D11ShaderHelper<ID3D11ComputeShader>( SHADER_TYPE_COMPUTE, NewShaders, SHADER_TYPE_COMPUTE, &ID3D11DeviceContext::CSSetShader );
+
+#ifdef VERIFY_SHADER_BINDINGS
+ pShaderD3D11->dbgVerifyBindings();
+#endif
+
+ // Set requried shader resources
+ SetD3DConstantBuffers ( pShaderD3D11 );
+ SetD3DSRVs ( pShaderD3D11 );
+ SetD3DSamplers ( pShaderD3D11 );
+ SetD3DUAVs ( pShaderD3D11 );
+
+ break;
+ }
+ }
+
+ if( !bCSBound )
+ {
+ LOG_ERROR_MESSAGE( "Compute shader is not bound to the pipeline" );
+ return;
+ }
+
+ // Verify bindings
+ dbgVerifyContextSRVs();
+ dbgVerifyContextUAVs();
+ dbgVerifyContextSamplers();
+ dbgVerifyContextCBs();
+ dbgVerifyShaders();
+
+ if( DispatchAttrs.pIndirectDispatchAttribs )
+ {
+ CHECK_DYNAMIC_TYPE( BufferD3D11Impl, DispatchAttrs.pIndirectDispatchAttribs );
+ auto *pd3d11Buff = static_cast<BufferD3D11Impl*>(DispatchAttrs.pIndirectDispatchAttribs)->GetD3D11Buffer();
+ m_pd3d11DeviceContext->DispatchIndirect( pd3d11Buff, DispatchAttrs.DispatchArgsByteOffset );
+ }
+ else
+ m_pd3d11DeviceContext->Dispatch( DispatchAttrs.ThreadGroupCountX, DispatchAttrs.ThreadGroupCountY, DispatchAttrs.ThreadGroupCountZ );
+ }
+
+ void DeviceContextD3D11Impl::ClearDepthStencil( ITextureView *pView, Uint32 ClearFlags, float fDepth, Uint8 Stencil )
+ {
+ ID3D11DepthStencilView *pd3d11DSV = nullptr;
+ if( pView != nullptr )
+ {
+ const auto& ViewDesc = pView->GetDesc();
+ VERIFY( ViewDesc.ViewType == TEXTURE_VIEW_DEPTH_STENCIL, "Incorrect view type: depth stencil is expected" );
+ CHECK_DYNAMIC_TYPE( TextureViewD3D11Impl, pView );
+ auto *pViewD3D11 = static_cast<TextureViewD3D11Impl*>(pView);
+ pd3d11DSV = static_cast<ID3D11DepthStencilView *>(pViewD3D11->GetD3D11View());
+ }
+ else
+ {
+ pd3d11DSV = ValidatedCast<SwapChainD3D11Impl>(m_pSwapChain.RawPtr())->GetDSV();
+ }
+ UINT32 d3d11ClearFlags = 0;
+ if( ClearFlags & CLEAR_DEPTH_FLAG ) d3d11ClearFlags |= D3D11_CLEAR_DEPTH;
+ if( ClearFlags & CLEAR_STENCIL_FLAG ) d3d11ClearFlags |= D3D11_CLEAR_STENCIL;
+ // The full extent of the resource view is always cleared.
+ // Viewport and scissor settings are not applied.
+ m_pd3d11DeviceContext->ClearDepthStencilView( pd3d11DSV, d3d11ClearFlags, fDepth, Stencil );
+ }
+
+ void DeviceContextD3D11Impl::ClearRenderTarget( ITextureView *pView, const float *RGBA )
+ {
+ ID3D11RenderTargetView *pd3d11RTV = nullptr;
+ if( pView != nullptr )
+ {
+ const auto& ViewDesc = pView->GetDesc();
+ VERIFY( ViewDesc.ViewType == TEXTURE_VIEW_RENDER_TARGET, "Incorrect view type: render target is expected" );
+ CHECK_DYNAMIC_TYPE( TextureViewD3D11Impl, pView );
+ auto *pViewD3D11 = static_cast<TextureViewD3D11Impl*>(pView);
+ pd3d11RTV = static_cast<ID3D11RenderTargetView*>(pViewD3D11->GetD3D11View());
+ }
+ else
+ {
+ pd3d11RTV = ValidatedCast<SwapChainD3D11Impl>(m_pSwapChain.RawPtr())->GetRTV();
+ }
+
+ static const float Zero[4] = { 0.f, 0.f, 0.f, 0.f };
+ if( RGBA == nullptr )
+ RGBA = Zero;
+
+ // The full extent of the resource view is always cleared.
+ // Viewport and scissor settings are not applied.
+ m_pd3d11DeviceContext->ClearRenderTargetView( pd3d11RTV, RGBA );
+ }
+
+ void DeviceContextD3D11Impl::Flush()
+ {
+ m_pd3d11DeviceContext->Flush();
+ }
+
+ void DeviceContextD3D11Impl::SetVertexBuffers( Uint32 StartSlot, Uint32 NumBuffersSet, IBuffer **ppBuffers, Uint32 *pStrides, Uint32 *pOffsets, Uint32 Flags )
+ {
+ TDeviceContextBase::SetVertexBuffers( StartSlot, NumBuffersSet, ppBuffers, pStrides, pOffsets, Flags );
+ }
+
+ void DeviceContextD3D11Impl::ClearState()
+ {
+ TDeviceContextBase::ClearState();
+
+ }
+
+ void DeviceContextD3D11Impl::SetVertexDescription( IVertexDescription *pVertexDesc )
+ {
+ TDeviceContextBase::SetVertexDescription( pVertexDesc );
+ }
+
+ void DeviceContextD3D11Impl::SetIndexBuffer( IBuffer *pIndexBuffer, Uint32 ByteOffset )
+ {
+ TDeviceContextBase::SetIndexBuffer( pIndexBuffer, ByteOffset );
+ }
+
+ void DeviceContextD3D11Impl::SetDepthStencilState( IDepthStencilState *pDepthStencilState, Uint32 StencilRef )
+ {
+ if( TDeviceContextBase::SetDepthStencilState( pDepthStencilState, StencilRef ) )
+ {
+ CHECK_DYNAMIC_TYPE( DSStateD3D11Impl, pDepthStencilState );
+ auto *pDSSD3D11 = static_cast<DSStateD3D11Impl*>(pDepthStencilState);
+ auto *pd3d11DSS = pDSSD3D11->GetD3D11DepthStencilState();
+ m_pd3d11DeviceContext->OMSetDepthStencilState( pd3d11DSS, StencilRef );
+ }
+ }
+
+ void DeviceContextD3D11Impl::SetRasterizerState( IRasterizerState *pRasterizerState )
+ {
+ if( TDeviceContextBase::SetRasterizerState( pRasterizerState ) )
+ {
+ CHECK_DYNAMIC_TYPE( RasterizerStateD3D11Impl, pRasterizerState );
+ auto *pRSD3D11 = static_cast<RasterizerStateD3D11Impl*>(pRasterizerState);
+ auto *pd3d11RS = pRSD3D11->GetD3D11RasterizerState();
+ m_pd3d11DeviceContext->RSSetState( pd3d11RS );
+ }
+ }
+
+ void DeviceContextD3D11Impl::SetBlendState( IBlendState *pBS, const float* pBlendFactors, Uint32 SampleMask )
+ {
+ if( TDeviceContextBase::SetBlendState( pBS, pBlendFactors, SampleMask ) )
+ {
+ CHECK_DYNAMIC_TYPE( BlendStateD3D11Impl, pBS );
+ auto *pBSD3D11 = static_cast<BlendStateD3D11Impl*>(pBS);
+ auto *pd3d11BS = pBSD3D11->GetD3D11BlendState();
+ m_pd3d11DeviceContext->OMSetBlendState( pd3d11BS, m_BlendFactors, SampleMask );
+ }
+ }
+
+ void DeviceContextD3D11Impl::SetViewports( Uint32 NumViewports, const Viewport *pViewports, Uint32 RTWidth, Uint32 RTHeight )
+ {
+ const Uint32 MaxViewports = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
+ VERIFY( NumViewports < MaxViewports, "Too many viewports are being set" );
+ NumViewports = std::min( NumViewports, MaxViewports );
+
+ TDeviceContextBase::SetViewports( NumViewports, pViewports, RTWidth, RTHeight );
+
+ D3D11_VIEWPORT d3d11Viewports[MaxViewports];
+ VERIFY( NumViewports == m_Viewports.size(), "Unexpected number of viewports" );
+ for( Uint32 vp = 0; vp < NumViewports; ++vp )
+ {
+ d3d11Viewports[vp].TopLeftX = m_Viewports[vp].TopLeftX;
+ d3d11Viewports[vp].TopLeftY = m_Viewports[vp].TopLeftY;
+ d3d11Viewports[vp].Width = m_Viewports[vp].Width;
+ d3d11Viewports[vp].Height = m_Viewports[vp].Height;
+ d3d11Viewports[vp].MinDepth = m_Viewports[vp].MinDepth;
+ d3d11Viewports[vp].MaxDepth = m_Viewports[vp].MaxDepth;
+ }
+ // All viewports must be set atomically as one operation.
+ // Any viewports not defined by the call are disabled.
+ m_pd3d11DeviceContext->RSSetViewports( NumViewports, d3d11Viewports );
+ }
+
+ void DeviceContextD3D11Impl::SetScissorRects( Uint32 NumRects, const Rect *pRects, Uint32 RTWidth, Uint32 RTHeight )
+ {
+ const Uint32 MaxScissorRects = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
+ VERIFY( NumRects < MaxScissorRects, "Too many scissor rects are being set" );
+ NumRects = std::min( NumRects, MaxScissorRects );
+
+ TDeviceContextBase::SetScissorRects(NumRects, pRects, RTWidth, RTHeight);
+
+ D3D11_RECT d3d11ScissorRects[MaxScissorRects];
+ VERIFY( NumRects == m_ScissorRects.size(), "Unexpected number of scissor rects" );
+ for( Uint32 sr = 0; sr < NumRects; ++sr )
+ {
+ d3d11ScissorRects[sr].left = m_ScissorRects[sr].left;
+ d3d11ScissorRects[sr].top = m_ScissorRects[sr].top;
+ d3d11ScissorRects[sr].right = m_ScissorRects[sr].right;
+ d3d11ScissorRects[sr].bottom = m_ScissorRects[sr].bottom;
+ }
+
+ // All scissor rects must be set atomically as one operation.
+ // Any scissor rects not defined by the call are disabled.
+ m_pd3d11DeviceContext->RSSetScissorRects( NumRects, d3d11ScissorRects );
+ }
+
+ void DeviceContextD3D11Impl::RebindRenderTargets()
+ {
+ const Uint32 MaxD3D11RTs = D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT;
+ Uint32 NumRenderTargets = static_cast<Uint32>( m_pBoundRenderTargets.size() );
+ VERIFY( NumRenderTargets <= MaxD3D11RTs, "D3D11 only allows 8 simultaneous render targets" );
+ NumRenderTargets = std::min( MaxD3D11RTs, NumRenderTargets );
+
+ ID3D11RenderTargetView *pd3d11RTs[MaxD3D11RTs] = {};
+ ID3D11DepthStencilView *pd3d11DSV = nullptr;
+
+ auto *pDepthStencil = m_pBoundDepthStencil.RawPtr();
+ if( NumRenderTargets == 0 && pDepthStencil == nullptr )
+ {
+ NumRenderTargets = 1;
+ auto *pSwapChainD3D11 = ValidatedCast<SwapChainD3D11Impl>( m_pSwapChain.RawPtr() );
+ pd3d11RTs[0] = pSwapChainD3D11->GetRTV();
+ pd3d11DSV = pSwapChainD3D11->GetDSV();
+ }
+ else
+ {
+ for( Uint32 rt = 0; rt < NumRenderTargets; ++rt )
+ {
+ auto *pView = m_pBoundRenderTargets[rt].RawPtr();
+ if( pView )
+ {
+ auto *pViewD3D11 = static_cast<TextureViewD3D11Impl*>(pView);
+ pd3d11RTs[rt] = static_cast<ID3D11RenderTargetView*>(pViewD3D11->GetD3D11View());
+ }
+ else
+ pd3d11RTs[rt] = nullptr;
+ }
+
+ if( pDepthStencil != nullptr )
+ {
+ auto *pViewD3D11 = static_cast<TextureViewD3D11Impl*>(pDepthStencil);
+ pd3d11DSV = static_cast<ID3D11DepthStencilView*>(pViewD3D11->GetD3D11View());
+ }
+ }
+
+ m_pd3d11DeviceContext->OMSetRenderTargets(NumRenderTargets, pd3d11RTs, pd3d11DSV);
+ }
+
+ void UnbindView( ID3D11DeviceContext *pContext, TSetShaderResourcesType SetSRVMethod, UINT Slot )
+ {
+ ID3D11ShaderResourceView *ppNullView[] = { nullptr };
+ (pContext->*SetSRVMethod)(Slot, 1, ppNullView);
+ }
+
+ void UnbindView( ID3D11DeviceContext *pContext, TSetUnorderedAccessViewsType SetUAVMethod, UINT Slot )
+ {
+ ID3D11UnorderedAccessView *ppNullView[] = { nullptr };
+ (pContext->*SetUAVMethod)(Slot, 1, ppNullView, nullptr);
+ }
+
+ /// \tparam TBoundResourceType - Type of the struct describing resources associated with the
+ /// bound entity (ShaderD3D11Impl::BoundCB, ShaderD3D11Impl::BoundSRV, etc.)
+ /// \tparam TD3D11ResourceType - Type of the D3D11 resource (ID3D11ShaderResourceView or ID3D11UnorderedAccessView)
+ /// \tparam TSetD3D11View - Type of the D3D11 device context method used to set the D3D11 view
+ /// \param BoundResourcesArr - Pointer to the array of strong references to currently bound
+ /// shader resources, for each shader stage
+ /// \param BoundD3D11ResourcesArr - Pointer to the array of currently bound D3D11
+ /// shader resources, for each shader stage
+ /// \param pResToUnbind - Resource to unbind
+ /// \param SetD3D11ViewMethods - Array of pointers to device context methods used to set the view,
+ /// for every shader stage
+ template<typename TBoundResourceType,
+ typename TD3D11ResourceType,
+ typename TSetD3D11View>
+ void DeviceContextD3D11Impl::UnbindResourceView(std::vector<TBoundResourceType> BoundResourcesArr[],
+ std::vector<TD3D11ResourceType> BoundD3D11ResourcesArr[],
+ IDeviceObject *pResToUnbind,
+ TSetD3D11View SetD3D11ViewMethods[])
+ {
+ for( Int32 ShaderTypeInd = 0; ShaderTypeInd < NumShaderTypes; ++ShaderTypeInd )
+ {
+ auto &BoundResources = BoundResourcesArr[ShaderTypeInd];
+ auto &BoundD3D11Views = BoundD3D11ResourcesArr[ShaderTypeInd];
+ VERIFY( BoundResources.size() == BoundD3D11Views.size(), "Inconsistent shader resource view array sizes" );
+ for( Uint32 Slot = 0; Slot < BoundResources.size(); ++Slot )
+ {
+ if( BoundResources[Slot].pResource == pResToUnbind )
+ {
+ BoundResources[Slot] = TBoundResourceType();
+ BoundD3D11Views[Slot] = nullptr;
+
+ auto SetViewMethod = SetD3D11ViewMethods[ShaderTypeInd];
+ UnbindView( m_pd3d11DeviceContext, SetViewMethod, Slot );
+ }
+ }
+
+ // Pop null resources from the end of arrays
+ while( BoundD3D11Views.size() > 0 && BoundD3D11Views.back() == nullptr )
+ {
+ BoundD3D11Views.pop_back();
+ VERIFY( BoundResources.back().pResource == nullptr, "Unexpected non-null resource detected" )
+ VERIFY( BoundResources.back().pView == nullptr, "Unexpected non-null resource view detected" )
+ VERIFY( BoundResources.back().pd3d11View == nullptr, "Unexpected non-null D3D11 resource view detected" )
+ BoundResources.pop_back();
+ }
+ VERIFY(BoundResources.size() == BoundD3D11Views.size(), "Inconsistent array size")
+ }
+ }
+
+ void DeviceContextD3D11Impl::UnbindTextureFromInput( ITexture *pTexture )
+ {
+ VERIFY( pTexture, "Null texture provided" )
+ if( !pTexture )return;
+
+ UnbindResourceView( m_BoundSRVs, m_BoundD3D11SRVs, pTexture, SetSRVMethods );
+ }
+
+ void DeviceContextD3D11Impl::UnbindBufferFromInput( IBuffer *pBuffer )
+ {
+ VERIFY( pBuffer, "Null buffer provided" )
+ if( !pBuffer )return;
+
+ UnbindResourceView( m_BoundSRVs, m_BoundD3D11SRVs, pBuffer, SetSRVMethods );
+
+ auto BuffBindFlags = pBuffer->GetDesc().BindFlags;
+
+ if( (BuffBindFlags & BIND_INDEX_BUFFER) && m_BoundD3D11IndexBuffer )
+ {
+ auto pd3d11IndBuffer = ValidatedCast<BufferD3D11Impl>( pBuffer )->GetD3D11Buffer();
+ if( pd3d11IndBuffer == m_BoundD3D11IndexBuffer )
+ {
+ // Only unbind D3D11 buffer from the context!
+ // m_pIndexBuffer.Release();
+ m_BoundD3D11IndexBuffer.Release();
+ m_BoundD3D11IndexFmt = DXGI_FORMAT_UNKNOWN;
+ m_BoundD3D11IndexDataStartOffset = 0;
+ m_pd3d11DeviceContext->IASetIndexBuffer( nullptr, m_BoundD3D11IndexFmt, m_BoundD3D11IndexDataStartOffset );
+ }
+ dbgVerifyIndexBuffer();
+ }
+
+ if( BuffBindFlags & BIND_VERTEX_BUFFER )
+ {
+ auto pd3d11VB = ValidatedCast<BufferD3D11Impl>( pBuffer )->GetD3D11Buffer();
+ for( Uint32 Slot = 0; Slot < m_BoundD3D11VertexBuffers.size(); ++Slot )
+ {
+ auto &BoundD3D11VB = m_BoundD3D11VertexBuffers[Slot];
+ if(BoundD3D11VB == pd3d11VB)
+ {
+ // Unbind only D3D11 buffer
+ //*VertStream = VertexStreamInfo();
+ ID3D11Buffer *ppNullBuffer[] = { nullptr };
+ const UINT Zero[] = { 0 };
+ m_BoundD3D11VertexBuffers[Slot].Release();
+ m_BoundD3D11VBStrides[Slot] = 0;
+ m_BoundD3D11VBOffsets[Slot] = 0;
+ m_pd3d11DeviceContext->IASetVertexBuffers( Slot, _countof( ppNullBuffer ), ppNullBuffer, Zero, Zero );
+ }
+ }
+ dbgVerifyVertexBuffers();
+ }
+
+ if( BuffBindFlags & BIND_UNIFORM_BUFFER )
+ {
+ for( Int32 ShaderTypeInd = 0; ShaderTypeInd < NumShaderTypes; ++ShaderTypeInd )
+ {
+ auto &BoundCBs = m_BoundCBs[ShaderTypeInd];
+ auto &BoundD3D11CBs = m_BoundD3D11CBs[ShaderTypeInd];
+ VERIFY( BoundCBs.size() == BoundD3D11CBs.size(), "Inconsistent constant buffer array sizes" );
+ auto NumSlots = std::min( BoundCBs.size(), BoundD3D11CBs.size() );
+ for( Uint32 Slot = 0; Slot < NumSlots; ++Slot )
+ {
+ if( BoundCBs[Slot].pBuff == pBuffer )
+ {
+ BoundCBs[Slot] = ShaderD3D11Impl::BoundCB();
+ BoundD3D11CBs[Slot] = nullptr;
+ auto SetCBMethod = SetCBMethods[ShaderTypeInd];
+ ID3D11Buffer *ppNullBuffer[] = { nullptr };
+ (m_pd3d11DeviceContext->*SetCBMethod)(Slot, 1, ppNullBuffer);
+ }
+ }
+ }
+
+ dbgVerifyContextCBs();
+ }
+ }
+
+ void DeviceContextD3D11Impl::UnbindResourceFromUAV( IDeviceObject *pResource )
+ {
+ VERIFY( pResource, "Null resource provided" )
+ if( !pResource )return;
+
+ UnbindResourceView( m_BoundUAVs, m_BoundD3D11UAVs, pResource, SetUAVMethods );
+ }
+
+ void DeviceContextD3D11Impl::UnbindTextureFromRenderTarget( IDeviceObject *pResource )
+ {
+ VERIFY( pResource, "Null resource provided" )
+ if( !pResource )return;
+ VERIFY(ValidatedCast<ITexture>( pResource ), "Resource is not a texture")
+
+ bool bRebindRenderTargets = false;
+ for( auto rt = m_pBoundRenderTargets.begin(); rt != m_pBoundRenderTargets.end(); ++rt )
+ {
+ if( auto pTexView = *rt )
+ {
+ if( pTexView->GetTexture() == pResource )
+ {
+ (*rt).Release();
+ bRebindRenderTargets = true;
+ }
+ }
+ }
+
+ if( bRebindRenderTargets )
+ RebindRenderTargets();
+ }
+
+ void DeviceContextD3D11Impl::UnbindTextureFromDepthStencil(IDeviceObject *pResource)
+ {
+ VERIFY( pResource, "Null resource provided" )
+ if( !pResource )return;
+ VERIFY(ValidatedCast<ITexture>( pResource ), "Resource is not a texture")
+
+ if( m_pBoundDepthStencil && m_pBoundDepthStencil->GetTexture() == pResource )
+ {
+ m_pBoundDepthStencil.Release();
+ RebindRenderTargets();
+ }
+ }
+
+ void DeviceContextD3D11Impl::SetRenderTargets( Uint32 NumRenderTargets, ITextureView *ppRenderTargets[], ITextureView *pDepthStencil )
+ {
+ if( TDeviceContextBase::SetRenderTargets( NumRenderTargets, ppRenderTargets, pDepthStencil ) )
+ {
+ for( Uint32 RT = 0; RT < NumRenderTargets; ++RT )
+ if( ppRenderTargets[RT] )
+ {
+ UnbindTextureFromInput( ppRenderTargets[RT]->GetTexture() );
+ }
+ if( pDepthStencil )
+ UnbindTextureFromInput( pDepthStencil->GetTexture() );
+
+ RebindRenderTargets();
+
+ // Set the viewport to match the render target size
+ SetViewports(1, nullptr, 0, 0);
+ }
+ }
+
+ template<typename TD3D11ResourceType, typename TSetD3D11ResMethodType>
+ void SetD3D11ResourcesHelper(ID3D11DeviceContext *pDeviceCtx,
+ TSetD3D11ResMethodType SetD3D11ResMethod,
+ UINT StartSlot, UINT NumSlots,
+ TD3D11ResourceType **ppResources)
+ {
+ (pDeviceCtx->*SetD3D11ResMethod)(StartSlot, NumSlots, ppResources);
+ }
+
+ template<>
+ void SetD3D11ResourcesHelper(ID3D11DeviceContext *pDeviceCtx,
+ TSetUnorderedAccessViewsType SetD3D11UAVMethod,
+ UINT StartSlot, UINT NumSlots,
+ ID3D11UnorderedAccessView **ppUAVs)
+ {
+ (pDeviceCtx->*SetD3D11UAVMethod)(StartSlot, NumSlots, ppUAVs, nullptr);
+ }
+
+ template<typename TD3D11ResourceType, typename TBoundResourceType, typename TSetD3D11ResMethodType>
+ void ClearStateCacheInternal(std::vector<TD3D11ResourceType*> &BoundD3D11Res,
+ std::vector<TBoundResourceType> &BoundRes,
+ TSetD3D11ResMethodType SetD3D11ResMethod,
+ ID3D11DeviceContext *pDeviceCtx)
+ {
+ if( BoundD3D11Res.size() )
+ {
+ memset( BoundD3D11Res.data(), 0, BoundD3D11Res.size() * sizeof( BoundD3D11Res[0] ) );
+ SetD3D11ResourcesHelper( pDeviceCtx, SetD3D11ResMethod, 0, static_cast<UINT>(BoundD3D11Res.size()), BoundD3D11Res.data() );
+ BoundD3D11Res.clear();
+ BoundRes.clear();
+ }
+ }
+
+ void DeviceContextD3D11Impl::ClearShaderStateCache()
+ {
+ for( int ShaderType = 0; ShaderType < NumShaderTypes; ++ShaderType )
+ {
+ ClearStateCacheInternal( m_BoundD3D11CBs [ShaderType], m_BoundCBs [ShaderType], SetCBMethods[ShaderType], m_pd3d11DeviceContext );
+ ClearStateCacheInternal( m_BoundD3D11SRVs [ShaderType], m_BoundSRVs [ShaderType], SetSRVMethods[ShaderType], m_pd3d11DeviceContext );
+ ClearStateCacheInternal( m_BoundD3D11Samplers[ShaderType], m_BoundSamplers[ShaderType], SetSamplerMethods[ShaderType], m_pd3d11DeviceContext );
+ ClearStateCacheInternal( m_BoundD3D11UAVs [ShaderType], m_BoundUAVs [ShaderType], SetUAVMethods[ShaderType], m_pd3d11DeviceContext );
+ }
+
+ dbgVerifyContextSRVs();
+ dbgVerifyContextUAVs();
+ dbgVerifyContextSamplers();
+ dbgVerifyContextCBs();
+
+ // We do not unbind vertex buffers and index buffer as this can explicitly
+ // be done by the user
+ }
+
+#ifdef VERIFY_CONTEXT_BINDINGS
+
+ DEFINE_D3D11CTX_FUNC_POINTERS(GetCBMethods, GetConstantBuffers)
+ DEFINE_D3D11CTX_FUNC_POINTERS(GetSRVMethods, GetShaderResources)
+ DEFINE_D3D11CTX_FUNC_POINTERS(GetSamplerMethods, GetSamplers)
+
+ typedef decltype (&ID3D11DeviceContext::CSGetUnorderedAccessViews) TGetUnorderedAccessViewsType;
+ static const TGetUnorderedAccessViewsType GetUAVMethods[] =
+ {
+ nullptr,
+ nullptr,
+ nullptr,
+ nullptr,
+ nullptr,
+ &ID3D11DeviceContext::CSGetUnorderedAccessViews
+ };
+
+ /// \tparam MaxResources - Maximum number of resources that can be bound to D3D11 context
+ /// \tparam TD3D11ResourceType - Type of D3D11 resource being checked (ID3D11ShaderResourceView,
+ /// ID3D11UnorderedAccessView, ID3D11Buffer or ID3D11SamplerState).
+ /// \tparam TGetD3D11ResourcesType - Type of the device context method used to get the bound
+ /// resources
+ /// \param BoundD3D11ResourcesArr - Pointer to the array of currently bound D3D11
+ /// resources, for each shader stage
+ /// \param GetD3D11ResMethods - Pointer to the array of device context methods to get the bound
+ /// resources, for each shader stage
+ /// \param ResourceName - Resource name
+ /// \param ShaderType - Shader type for which to check the resources. If Diligent::SHADER_TYPE_UNKNOWN
+ /// is provided, all shader stages will be checked
+ template<UINT MaxResources,
+ typename TD3D11ResourceType,
+ typename TGetD3D11ResourcesType>
+ void DeviceContextD3D11Impl::dbgVerifyContextResources(std::vector<TD3D11ResourceType> BoundD3D11ResourcesArr[],
+ TGetD3D11ResourcesType GetD3D11ResMethods[],
+ const Char *ResourceName,
+ SHADER_TYPE ShaderType)
+ {
+ int iStartInd = 0, iEndInd = NumShaderTypes;
+ if( ShaderType != SHADER_TYPE_UNKNOWN )
+ {
+ iStartInd = GetShaderTypeIndex(ShaderType);
+ iEndInd = iStartInd + 1;
+ }
+ for( int iShaderTypeInd = iStartInd; iShaderTypeInd < iEndInd; ++iShaderTypeInd )
+ {
+ const auto ShaderName = GetShaderTypeLiteralName( GetShaderTypeFromIndex(iShaderTypeInd) );
+ TD3D11ResourceType pctxResources[MaxResources] = {};
+ auto GetResMethod = GetD3D11ResMethods[iShaderTypeInd];
+ if( GetResMethod )
+ {
+ (m_pd3d11DeviceContext->*GetResMethod)(0, _countof( pctxResources ), pctxResources);
+ }
+ const auto& BoundResources = BoundD3D11ResourcesArr[iShaderTypeInd];
+ auto NumBoundResources = BoundResources.size();
+ for( Uint32 Slot = 0; Slot < _countof( pctxResources ); ++Slot )
+ {
+ if( Slot < NumBoundResources )
+ {
+ VERIFY( BoundResources[Slot] == pctxResources[Slot], ResourceName, " binding mismatch found for ", ShaderName, " shader type at slot ", Slot )
+ }
+ else
+ {
+ VERIFY( pctxResources[Slot] == nullptr, ResourceName, " binding mismatch found for ", ShaderName, " shader type at slot ", Slot )
+ }
+
+ if( pctxResources[Slot] )
+ pctxResources[Slot]->Release();
+ }
+ }
+ }
+
+ void DeviceContextD3D11Impl::dbgVerifyContextSRVs(SHADER_TYPE ShaderType)
+ {
+ dbgVerifyContextResources<D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT>( m_BoundD3D11SRVs, GetSRVMethods, "SRV", ShaderType );
+ }
+
+ void DeviceContextD3D11Impl::dbgVerifyContextUAVs(SHADER_TYPE ShaderType)
+ {
+ dbgVerifyContextResources<D3D11_PS_CS_UAV_REGISTER_COUNT>( m_BoundD3D11UAVs, GetUAVMethods, "UAV", ShaderType );
+ }
+
+ void DeviceContextD3D11Impl::dbgVerifyContextSamplers(SHADER_TYPE ShaderType)
+ {
+ dbgVerifyContextResources<D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT>( m_BoundD3D11Samplers, GetSamplerMethods, "Sampler", ShaderType );
+ }
+
+ void DeviceContextD3D11Impl::dbgVerifyContextCBs(SHADER_TYPE ShaderType)
+ {
+ dbgVerifyContextResources<D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT>( m_BoundD3D11CBs, GetCBMethods, "Constant buffer", ShaderType );
+ }
+
+ void DeviceContextD3D11Impl::dbgVerifyIndexBuffer()
+ {
+ RefCntAutoPtr<ID3D11Buffer> pctxIndexBuffer;
+ DXGI_FORMAT Fmt = DXGI_FORMAT_UNKNOWN;
+ UINT Offset = 0;
+ m_pd3d11DeviceContext->IAGetIndexBuffer( &pctxIndexBuffer, &Fmt, &Offset );
+ if( m_BoundD3D11IndexBuffer && !pctxIndexBuffer )
+ UNEXPECTED( "D3D11 index buffer is not bound to the context" );
+ if( !m_BoundD3D11IndexBuffer && pctxIndexBuffer )
+ UNEXPECTED( "Unexpected D3D11 index buffer is bound to the context" );
+
+ if( m_BoundD3D11IndexBuffer && pctxIndexBuffer )
+ {
+ VERIFY(m_BoundD3D11IndexBuffer == pctxIndexBuffer, "Index buffer binding mismatch detected");
+ VERIFY(m_BoundD3D11IndexFmt == Fmt, "Index buffer format mismatch detected");
+ VERIFY(m_BoundD3D11IndexDataStartOffset == Offset, "Index buffer offset mismatch detected");
+ }
+ }
+
+ void DeviceContextD3D11Impl::dbgVerifyVertexBuffers()
+ {
+ const Uint32 MaxVBs = D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT;
+ ID3D11Buffer *pVBs[MaxVBs];
+ UINT Strides[MaxVBs];
+ UINT Offsets[MaxVBs];
+ m_pd3d11DeviceContext->IAGetVertexBuffers( 0, MaxVBs, pVBs, Strides, Offsets );
+ auto NumBoundVBs = m_BoundD3D11VertexBuffers.size();
+ VERIFY(m_BoundD3D11VBStrides.size() == NumBoundVBs, "Unexpected bound D3D11 VB stride array size");
+ VERIFY(m_BoundD3D11VBOffsets.size() == NumBoundVBs, "Unexpected bound D3D11 VB offset array size");
+ for( Uint32 Slot = 0; Slot < MaxVBs; ++Slot )
+ {
+ if( Slot < NumBoundVBs )
+ {
+ const auto &BoundD3D11VB = m_BoundD3D11VertexBuffers[Slot];
+ auto BoundVBStride = m_BoundD3D11VBStrides[Slot];
+ auto BoundVBOffset = m_BoundD3D11VBOffsets[Slot];
+ if(BoundD3D11VB && !pVBs[Slot] )
+ VERIFY( pVBs[Slot] == nullptr, "Missing D3D11 buffer detected at slot ", Slot );
+ if(!BoundD3D11VB && pVBs[Slot] )
+ VERIFY( pVBs[Slot] == nullptr, "Unexpected D3D11 buffer detected at slot ", Slot );
+ if( BoundD3D11VB && pVBs[Slot] )
+ {
+ VERIFY( BoundD3D11VB == pVBs[Slot], "Vertex buffer mismatch detected at slot ", Slot );
+ VERIFY( BoundVBOffset == Offsets[Slot], "Offset mismatch detected at slot ", Slot );
+ VERIFY( BoundVBStride == Strides[Slot], "Stride mismatch detected at slot ", Slot );
+ }
+ }
+ else
+ {
+ VERIFY( pVBs[Slot] == nullptr, "Unexpected D3D11 buffer detected at slot ", Slot );
+ }
+
+ if( pVBs[Slot] )
+ pVBs[Slot]->Release();
+ }
+ }
+
+ template<typename TD3D11ShaderType, typename TGetShaderMethodType>
+ void dbgVerifyShadersHelper(SHADER_TYPE ShaderType,
+ const CComPtr<ID3D11DeviceChild> BoundD3DShaders[],
+ ID3D11DeviceContext *pCtx,
+ TGetShaderMethodType GetShaderMethod)
+ {
+ RefCntAutoPtr<TD3D11ShaderType> pctxShader;
+ (pCtx->*GetShaderMethod)(&pctxShader, nullptr, nullptr);
+ const auto &BoundShader = BoundD3DShaders[GetShaderTypeIndex( ShaderType )];
+ VERIFY( BoundShader == pctxShader, GetShaderTypeLiteralName(ShaderType), " binding mismatch detected" );
+ }
+ void DeviceContextD3D11Impl::dbgVerifyShaders()
+ {
+#define VERIFY_SHADER(NAME, Name, N) dbgVerifyShadersHelper<ID3D11##Name##Shader>(SHADER_TYPE_##NAME, m_BoundD3DShaders, m_pd3d11DeviceContext, &ID3D11DeviceContext::N##SGetShader )
+ // These shaders which are not set will be unbound from the D3D11 device context
+ VERIFY_SHADER( VERTEX, Vertex, V );
+ VERIFY_SHADER( PIXEL, Pixel, P );
+ VERIFY_SHADER( GEOMETRY, Geometry, G );
+ VERIFY_SHADER( DOMAIN, Domain, D );
+ VERIFY_SHADER( HULL, Hull, H );
+ VERIFY_SHADER( COMPUTE, Compute, C );
+ }
+
+#endif
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/src/GraphicsEngineD3D11.def b/Graphics/GraphicsEngineD3D11/src/GraphicsEngineD3D11.def
new file mode 100644
index 00000000..9414b724
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/src/GraphicsEngineD3D11.def
@@ -0,0 +1,3 @@
+EXPORTS
+ CreateDeviceAndImmediateContextD3D11
+ CreateSwapChainD3D11 \ No newline at end of file
diff --git a/Graphics/GraphicsEngineD3D11/src/RasterizerStateD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/RasterizerStateD3D11Impl.cpp
new file mode 100644
index 00000000..90bd9092
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/src/RasterizerStateD3D11Impl.cpp
@@ -0,0 +1,110 @@
+/* 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.
+ */
+
+#include "pch.h"
+#include "RasterizerStateD3D11Impl.h"
+#include "RenderDeviceD3D11Impl.h"
+
+namespace Diligent
+{
+
+D3D11_FILL_MODE FillMode2D3D11FillMode(FILL_MODE FillMode)
+{
+ static bool bIsInit = false;
+ static D3D11_FILL_MODE D3D11FillModes[FILL_MODE_NUM_MODES] = {};
+ if( !bIsInit )
+ {
+ D3D11FillModes[ FILL_MODE_WIREFRAME ] = D3D11_FILL_WIREFRAME;
+ D3D11FillModes[ FILL_MODE_SOLID ] = D3D11_FILL_SOLID;
+
+ bIsInit = true;
+ }
+ if( FILL_MODE_UNDEFINED < FillMode && FillMode < FILL_MODE_NUM_MODES )
+ {
+ auto D3D11FillMode = D3D11FillModes[FillMode];
+ VERIFY( D3D11FillMode != 0, "Incorrect fill mode" );
+ return D3D11FillModes[FillMode];
+ }
+ else
+ {
+ UNEXPECTED( "Incorrect fill mode (", FillMode, ")" )
+ return static_cast<D3D11_FILL_MODE>(0);
+ }
+}
+
+D3D11_CULL_MODE CullMode2D3D11CullMode( CULL_MODE CullMode )
+{
+ static bool bIsInit = false;
+ static D3D11_CULL_MODE D3D11CullModes[CULL_MODE_NUM_MODES] = {};
+ if( !bIsInit )
+ {
+ D3D11CullModes[ CULL_MODE_NONE ] = D3D11_CULL_NONE;
+ D3D11CullModes[ CULL_MODE_FRONT ] = D3D11_CULL_FRONT;
+ D3D11CullModes[ CULL_MODE_BACK ] = D3D11_CULL_BACK;
+
+ bIsInit = true;
+ }
+
+ if( CULL_MODE_UNDEFINED < CullMode && CullMode < CULL_MODE_NUM_MODES )
+ {
+ auto D3D11CullMode = D3D11CullModes[CullMode];
+ VERIFY( D3D11CullMode != 0, "Incorrect cull mode" );
+ return D3D11CullMode;
+ }
+ else
+ {
+ UNEXPECTED( "Incorrect cull mode (", CullMode, ")" )
+ return static_cast<D3D11_CULL_MODE>(0);
+ }
+}
+
+RasterizerStateD3D11Impl::RasterizerStateD3D11Impl(class RenderDeviceD3D11Impl *pRenderDeviceD3D11,
+ const RasterizerStateDesc& RasterizerStateDesc) :
+ TRasterizerStateBase(pRenderDeviceD3D11, RasterizerStateDesc)
+{
+ D3D11_RASTERIZER_DESC D3D11RSDesc;
+
+ D3D11RSDesc.FillMode = FillMode2D3D11FillMode(RasterizerStateDesc.FillMode);
+ D3D11RSDesc.CullMode = CullMode2D3D11CullMode(RasterizerStateDesc.CullMode);
+ D3D11RSDesc.FrontCounterClockwise = RasterizerStateDesc.FrontCounterClockwise ? TRUE : FALSE;
+ D3D11RSDesc.DepthBias = RasterizerStateDesc.DepthBias;
+ D3D11RSDesc.DepthBiasClamp = RasterizerStateDesc.DepthBiasClamp;
+ D3D11RSDesc.SlopeScaledDepthBias = RasterizerStateDesc.SlopeScaledDepthBias;
+ D3D11RSDesc.DepthClipEnable = RasterizerStateDesc.DepthClipEnable ? TRUE : FALSE;
+ D3D11RSDesc.ScissorEnable = RasterizerStateDesc.ScissorEnable ? TRUE : FALSE;
+ D3D11RSDesc.AntialiasedLineEnable = RasterizerStateDesc.AntialiasedLineEnable ? TRUE : FALSE;
+ D3D11RSDesc.MultisampleEnable = D3D11RSDesc.AntialiasedLineEnable;
+
+ auto *pDeviceD3D11 = pRenderDeviceD3D11->GetD3D11Device();
+ CHECK_D3D_RESULT_THROW( pDeviceD3D11->CreateRasterizerState( &D3D11RSDesc, &m_pd3d11RasterizerState ),
+ "Failed to create D3D11 rasterizer state" );
+}
+
+RasterizerStateD3D11Impl::~RasterizerStateD3D11Impl()
+{
+
+}
+
+IMPLEMENT_QUERY_INTERFACE( RasterizerStateD3D11Impl, IID_RasterizerStateD3D11, TRasterizerStateBase )
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/src/RenderDeviceD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/RenderDeviceD3D11Impl.cpp
new file mode 100644
index 00000000..c828493e
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/src/RenderDeviceD3D11Impl.cpp
@@ -0,0 +1,440 @@
+/* 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.
+ */
+
+#include "pch.h"
+#include "RenderDeviceD3D11Impl.h"
+#include "DeviceContextD3D11Impl.h"
+#include "BufferD3D11Impl.h"
+#include "VertexDescD3D11Impl.h"
+#include "ShaderD3D11Impl.h"
+#include "Texture1D_D3D11.h"
+#include "Texture2D_D3D11.h"
+#include "Texture3D_D3D11.h"
+#include "SamplerD3D11Impl.h"
+#include "D3D11TypeConversions.h"
+#include "TextureViewD3D11Impl.h"
+#include "DSStateD3D11Impl.h"
+#include "RasterizerStateD3D11Impl.h"
+#include "BlendStateD3D11Impl.h"
+
+namespace Diligent
+{
+
+RenderDeviceD3D11Impl :: RenderDeviceD3D11Impl(ID3D11Device *pd3d11Device) :
+ m_pd3d11Device(pd3d11Device)
+{
+ m_DeviceCaps.DevType = DeviceType::DirectX;
+ m_DeviceCaps.MajorVersion = 11;
+ m_DeviceCaps.MinorVersion = 0;
+ m_DeviceCaps.bSeparableProgramSupported = true;
+
+ FlagSupportedTexFormats();
+}
+
+void RenderDeviceD3D11Impl::FlagSupportedTexFormats()
+{
+#define FLAG_FORMAT(Fmt, IsSupported)\
+ m_TextureFormatsInfo[Fmt].Supported = IsSupported;
+
+ FLAG_FORMAT(TEX_FORMAT_RGBA32_TYPELESS, true);
+ FLAG_FORMAT(TEX_FORMAT_RGBA32_FLOAT, true);
+ FLAG_FORMAT(TEX_FORMAT_RGBA32_UINT, true);
+ FLAG_FORMAT(TEX_FORMAT_RGBA32_SINT, true);
+ FLAG_FORMAT(TEX_FORMAT_RGB32_TYPELESS, true);
+ FLAG_FORMAT(TEX_FORMAT_RGB32_FLOAT, true);
+ FLAG_FORMAT(TEX_FORMAT_RGB32_UINT, true);
+ FLAG_FORMAT(TEX_FORMAT_RGB32_SINT, true);
+ FLAG_FORMAT(TEX_FORMAT_RGBA16_TYPELESS, true);
+ FLAG_FORMAT(TEX_FORMAT_RGBA16_FLOAT, true);
+ FLAG_FORMAT(TEX_FORMAT_RGBA16_UNORM, true);
+ FLAG_FORMAT(TEX_FORMAT_RGBA16_UINT, true);
+ FLAG_FORMAT(TEX_FORMAT_RGBA16_SNORM, true);
+ FLAG_FORMAT(TEX_FORMAT_RGBA16_SINT, true);
+ FLAG_FORMAT(TEX_FORMAT_RG32_TYPELESS, true);
+ FLAG_FORMAT(TEX_FORMAT_RG32_FLOAT, true);
+ FLAG_FORMAT(TEX_FORMAT_RG32_UINT, true);
+ FLAG_FORMAT(TEX_FORMAT_RG32_SINT, true);
+ FLAG_FORMAT(TEX_FORMAT_R32G8X24_TYPELESS, true);
+ FLAG_FORMAT(TEX_FORMAT_D32_FLOAT_S8X24_UINT, true);
+ FLAG_FORMAT(TEX_FORMAT_R32_FLOAT_X8X24_TYPELESS, true);
+ FLAG_FORMAT(TEX_FORMAT_X32_TYPELESS_G8X24_UINT, true);
+ FLAG_FORMAT(TEX_FORMAT_RGB10A2_TYPELESS, true);
+ FLAG_FORMAT(TEX_FORMAT_RGB10A2_UNORM, true);
+ FLAG_FORMAT(TEX_FORMAT_RGB10A2_UINT, true);
+ FLAG_FORMAT(TEX_FORMAT_R11G11B10_FLOAT, true);
+ FLAG_FORMAT(TEX_FORMAT_RGBA8_TYPELESS, true);
+ FLAG_FORMAT(TEX_FORMAT_RGBA8_UNORM, true);
+ FLAG_FORMAT(TEX_FORMAT_RGBA8_UNORM_SRGB, true);
+ FLAG_FORMAT(TEX_FORMAT_RGBA8_UINT, true);
+ FLAG_FORMAT(TEX_FORMAT_RGBA8_SNORM, true);
+ FLAG_FORMAT(TEX_FORMAT_RGBA8_SINT, true);
+ FLAG_FORMAT(TEX_FORMAT_RG16_TYPELESS, true);
+ FLAG_FORMAT(TEX_FORMAT_RG16_FLOAT, true);
+ FLAG_FORMAT(TEX_FORMAT_RG16_UNORM, true);
+ FLAG_FORMAT(TEX_FORMAT_RG16_UINT, true);
+ FLAG_FORMAT(TEX_FORMAT_RG16_SNORM, true);
+ FLAG_FORMAT(TEX_FORMAT_RG16_SINT, true);
+ FLAG_FORMAT(TEX_FORMAT_R32_TYPELESS, true);
+ FLAG_FORMAT(TEX_FORMAT_D32_FLOAT, true);
+ FLAG_FORMAT(TEX_FORMAT_R32_FLOAT, true);
+ FLAG_FORMAT(TEX_FORMAT_R32_UINT, true);
+ FLAG_FORMAT(TEX_FORMAT_R32_SINT, true);
+ FLAG_FORMAT(TEX_FORMAT_R24G8_TYPELESS, true);
+ FLAG_FORMAT(TEX_FORMAT_D24_UNORM_S8_UINT, true);
+ FLAG_FORMAT(TEX_FORMAT_R24_UNORM_X8_TYPELESS, true);
+ FLAG_FORMAT(TEX_FORMAT_X24_TYPELESS_G8_UINT, true);
+ FLAG_FORMAT(TEX_FORMAT_RG8_TYPELESS, true);
+ FLAG_FORMAT(TEX_FORMAT_RG8_UNORM, true);
+ FLAG_FORMAT(TEX_FORMAT_RG8_UINT, true);
+ FLAG_FORMAT(TEX_FORMAT_RG8_SNORM, true);
+ FLAG_FORMAT(TEX_FORMAT_RG8_SINT, true);
+ FLAG_FORMAT(TEX_FORMAT_R16_TYPELESS, true);
+ FLAG_FORMAT(TEX_FORMAT_R16_FLOAT, true);
+ FLAG_FORMAT(TEX_FORMAT_D16_UNORM, true);
+ FLAG_FORMAT(TEX_FORMAT_R16_UNORM, true);
+ FLAG_FORMAT(TEX_FORMAT_R16_UINT, true);
+ FLAG_FORMAT(TEX_FORMAT_R16_SNORM, true);
+ FLAG_FORMAT(TEX_FORMAT_R16_SINT, true);
+ FLAG_FORMAT(TEX_FORMAT_R8_TYPELESS, true);
+ FLAG_FORMAT(TEX_FORMAT_R8_UNORM, true);
+ FLAG_FORMAT(TEX_FORMAT_R8_UINT, true);
+ FLAG_FORMAT(TEX_FORMAT_R8_SNORM, true);
+ FLAG_FORMAT(TEX_FORMAT_R8_SINT, true);
+ FLAG_FORMAT(TEX_FORMAT_A8_UNORM, true);
+ FLAG_FORMAT(TEX_FORMAT_R1_UNORM, true);
+ FLAG_FORMAT(TEX_FORMAT_RGB9E5_SHAREDEXP, true);
+ FLAG_FORMAT(TEX_FORMAT_RG8_B8G8_UNORM, true);
+ FLAG_FORMAT(TEX_FORMAT_G8R8_G8B8_UNORM, true);
+ FLAG_FORMAT(TEX_FORMAT_BC1_TYPELESS, true);
+ FLAG_FORMAT(TEX_FORMAT_BC1_UNORM, true);
+ FLAG_FORMAT(TEX_FORMAT_BC1_UNORM_SRGB, true);
+ FLAG_FORMAT(TEX_FORMAT_BC2_TYPELESS, true);
+ FLAG_FORMAT(TEX_FORMAT_BC2_UNORM, true);
+ FLAG_FORMAT(TEX_FORMAT_BC2_UNORM_SRGB, true);
+ FLAG_FORMAT(TEX_FORMAT_BC3_TYPELESS, true);
+ FLAG_FORMAT(TEX_FORMAT_BC3_UNORM, true);
+ FLAG_FORMAT(TEX_FORMAT_BC3_UNORM_SRGB, true);
+ FLAG_FORMAT(TEX_FORMAT_BC4_TYPELESS, true);
+ FLAG_FORMAT(TEX_FORMAT_BC4_UNORM, true);
+ FLAG_FORMAT(TEX_FORMAT_BC4_SNORM, true);
+ FLAG_FORMAT(TEX_FORMAT_BC5_TYPELESS, true);
+ FLAG_FORMAT(TEX_FORMAT_BC5_UNORM, true);
+ FLAG_FORMAT(TEX_FORMAT_BC5_SNORM, true);
+ FLAG_FORMAT(TEX_FORMAT_B5G6R5_UNORM, true);
+ FLAG_FORMAT(TEX_FORMAT_B5G5R5A1_UNORM, true);
+ FLAG_FORMAT(TEX_FORMAT_BGRA8_UNORM, true);
+ FLAG_FORMAT(TEX_FORMAT_BGRX8_UNORM, true);
+ FLAG_FORMAT(TEX_FORMAT_R10G10B10_XR_BIAS_A2_UNORM, true);
+ FLAG_FORMAT(TEX_FORMAT_BGRA8_TYPELESS, true);
+ FLAG_FORMAT(TEX_FORMAT_BGRA8_UNORM_SRGB, true);
+ FLAG_FORMAT(TEX_FORMAT_BGRX8_TYPELESS, true);
+ FLAG_FORMAT(TEX_FORMAT_BGRX8_UNORM_SRGB, true);
+ FLAG_FORMAT(TEX_FORMAT_BC6H_TYPELESS, true);
+ FLAG_FORMAT(TEX_FORMAT_BC6H_UF16, true);
+ FLAG_FORMAT(TEX_FORMAT_BC6H_SF16, true);
+ FLAG_FORMAT(TEX_FORMAT_BC7_TYPELESS, true);
+ FLAG_FORMAT(TEX_FORMAT_BC7_UNORM, true);
+ FLAG_FORMAT(TEX_FORMAT_BC7_UNORM_SRGB, true);
+}
+
+bool CreateTestTexture1D(ID3D11Device *pDevice, const D3D11_TEXTURE1D_DESC &TexDesc)
+{
+ // Set the texture pointer address to nullptr to validate input parameters
+ // without creating the texture
+ // https://msdn.microsoft.com/en-us/library/windows/desktop/ff476520(v=vs.85).aspx
+ HRESULT hr = pDevice->CreateTexture1D( &TexDesc, nullptr, nullptr );
+ return hr == S_FALSE; // S_FALSE means that input parameters passed validation
+}
+
+bool CreateTestTexture2D(ID3D11Device *pDevice, const D3D11_TEXTURE2D_DESC &TexDesc)
+{
+ // Set the texture pointer address to nullptr to validate input parameters
+ // without creating the texture
+ // https://msdn.microsoft.com/en-us/library/windows/desktop/ff476521(v=vs.85).aspx
+ HRESULT hr = pDevice->CreateTexture2D( &TexDesc, nullptr, nullptr );
+ return hr == S_FALSE; // S_FALSE means that input parameters passed validation
+}
+
+bool CreateTestTexture3D(ID3D11Device *pDevice, const D3D11_TEXTURE3D_DESC &TexDesc)
+{
+ // Set the texture pointer address to nullptr to validate input parameters
+ // without creating the texture
+ // https://msdn.microsoft.com/en-us/library/windows/desktop/ff476522(v=vs.85).aspx
+ HRESULT hr = pDevice->CreateTexture3D( &TexDesc, nullptr, nullptr );
+ return hr == S_FALSE; // S_FALSE means that input parameters passed validation
+}
+
+void RenderDeviceD3D11Impl::TestTextureFormat( TEXTURE_FORMAT TexFormat )
+{
+ auto &TexFormatInfo = m_TextureFormatsInfo[TexFormat];
+ VERIFY( TexFormatInfo.Supported, "Texture format is not supported" );
+
+ auto DXGIFormat = TexFormatToDXGI_Format(TexFormat);
+ UINT DefaultBind = 0;
+ if( TexFormatInfo.ComponentType == COMPONENT_TYPE_DEPTH ||
+ TexFormatInfo.ComponentType == COMPONENT_TYPE_DEPTH_STENCIL )
+ DefaultBind = D3D11_BIND_DEPTH_STENCIL;
+ else
+ DefaultBind = D3D11_BIND_SHADER_RESOURCE;
+
+ const int TestTextureDim = 32;
+ const int TestTextureDepth = 8;
+
+ // Create test texture 1D
+ TexFormatInfo.Tex1DFmt = false;
+ if( TexFormatInfo.ComponentType != COMPONENT_TYPE_COMPRESSED )
+ {
+ D3D11_TEXTURE1D_DESC Tex1DDesc =
+ {
+ TestTextureDim, // UINT Width;
+ 1, // UINT MipLevels;
+ 1, // UINT ArraySize;
+ DXGIFormat, // DXGI_FORMAT Format;
+ D3D11_USAGE_DEFAULT, // D3D11_USAGE Usage;
+ DefaultBind, // UINT BindFlags;
+ 0, // UINT CPUAccessFlags;
+ 0 // UINT MiscFlags;
+ };
+ TexFormatInfo.Tex1DFmt = CreateTestTexture1D(m_pd3d11Device, Tex1DDesc );
+ }
+
+ // Create test texture 2D
+ TexFormatInfo.Tex2DFmt = false;
+ TexFormatInfo.TexCubeFmt = false;
+ TexFormatInfo.ColorRenderable = false;
+ TexFormatInfo.DepthRenderable = false;
+ TexFormatInfo.SupportsMS = false;
+ {
+ D3D11_TEXTURE2D_DESC Tex2DDesc =
+ {
+ TestTextureDim, // UINT Width;
+ TestTextureDim, // UINT Height;
+ 1, // UINT MipLevels;
+ 1, // UINT ArraySize;
+ DXGIFormat, // DXGI_FORMAT Format;
+ { 1, 0 }, // DXGI_SAMPLE_DESC SampleDesc;
+ D3D11_USAGE_DEFAULT, // D3D11_USAGE Usage;
+ DefaultBind, // UINT BindFlags;
+ 0, // UINT CPUAccessFlags;
+ 0, // UINT MiscFlags;
+ };
+ TexFormatInfo.Tex2DFmt = CreateTestTexture2D( m_pd3d11Device, Tex2DDesc );
+
+ if( TexFormatInfo.Tex2DFmt )
+ {
+ {
+ D3D11_TEXTURE2D_DESC CubeTexDesc = Tex2DDesc;
+ CubeTexDesc.ArraySize = 6;
+ CubeTexDesc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;
+ TexFormatInfo.TexCubeFmt = CreateTestTexture2D( m_pd3d11Device, CubeTexDesc );
+ }
+
+ if( TexFormatInfo.ComponentType == COMPONENT_TYPE_DEPTH ||
+ TexFormatInfo.ComponentType == COMPONENT_TYPE_DEPTH_STENCIL )
+ {
+ Tex2DDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
+ TexFormatInfo.DepthRenderable = CreateTestTexture2D( m_pd3d11Device, Tex2DDesc );
+
+ if( TexFormatInfo.DepthRenderable )
+ {
+ Tex2DDesc.SampleDesc.Count = 4;
+ TexFormatInfo.SupportsMS = CreateTestTexture2D( m_pd3d11Device, Tex2DDesc );
+ }
+ }
+ else if( TexFormatInfo.ComponentType != COMPONENT_TYPE_COMPRESSED )
+ {
+ Tex2DDesc.BindFlags = D3D11_BIND_RENDER_TARGET;
+ TexFormatInfo.ColorRenderable = CreateTestTexture2D( m_pd3d11Device, Tex2DDesc );
+ if( TexFormatInfo.ColorRenderable )
+ {
+ Tex2DDesc.SampleDesc.Count = 4;
+ TexFormatInfo.SupportsMS = CreateTestTexture2D( m_pd3d11Device, Tex2DDesc );
+ }
+ }
+ }
+ }
+
+ // Create test texture 3D
+ TexFormatInfo.Tex3DFmt = false;
+ // 3D textures do not support depth formats
+ if( !(TexFormatInfo.ComponentType == COMPONENT_TYPE_DEPTH ||
+ TexFormatInfo.ComponentType == COMPONENT_TYPE_DEPTH_STENCIL) )
+ {
+ D3D11_TEXTURE3D_DESC Tex3DDesc =
+ {
+ TestTextureDim, // UINT Width;
+ TestTextureDim, // UINT Height;
+ TestTextureDepth, // UINT Depth;
+ 1, // UINT MipLevels;
+ DXGIFormat, // DXGI_FORMAT Format;
+ D3D11_USAGE_DEFAULT,// D3D11_USAGE Usage;
+ DefaultBind, // UINT BindFlags;
+ 0, // UINT CPUAccessFlags;
+ 0 // UINT MiscFlags;
+ };
+ TexFormatInfo.Tex3DFmt = CreateTestTexture3D( m_pd3d11Device, Tex3DDesc );
+ }
+}
+
+IMPLEMENT_QUERY_INTERFACE( RenderDeviceD3D11Impl, IID_RenderDeviceD3D11, TRenderDeviceBase )
+
+void RenderDeviceD3D11Impl :: CreateBuffer(const BufferDesc& BuffDesc, const BufferData &BuffData, IBuffer **ppBuffer)
+{
+ CreateDeviceObject("buffer", BuffDesc, ppBuffer,
+ [&]()
+ {
+ BufferD3D11Impl *pBufferD3D11( new BufferD3D11Impl( this, BuffDesc, BuffData ) );
+ pBufferD3D11->QueryInterface( IID_Buffer, reinterpret_cast<IObject**>(ppBuffer) );
+ pBufferD3D11->CreateDefaultViews();
+ OnCreateDeviceObject( pBufferD3D11 );
+ }
+ );
+}
+
+void RenderDeviceD3D11Impl :: CreateVertexDescription(const LayoutDesc& LayoutDesc, IShader *pVertexShader, IVertexDescription **ppVertexDesc)
+{
+ CreateDeviceObject( "vertex description", LayoutDesc, ppVertexDesc,
+ [&]()
+ {
+ VertexDescD3D11Impl *pDescD3D11( new VertexDescD3D11Impl( this, LayoutDesc, pVertexShader ) );
+ pDescD3D11->QueryInterface( IID_VertexDescription, reinterpret_cast<IObject**>(ppVertexDesc) );
+
+ OnCreateDeviceObject( pDescD3D11 );
+ }
+ );
+}
+
+void RenderDeviceD3D11Impl :: CreateShader(const ShaderCreationAttribs &ShaderCreationAttribs, IShader **ppShader)
+{
+ CreateDeviceObject( "shader", ShaderCreationAttribs.Desc, ppShader,
+ [&]()
+ {
+ ShaderD3D11Impl *pShaderD3D11( new ShaderD3D11Impl( this, ShaderCreationAttribs ) );
+ pShaderD3D11->QueryInterface( IID_Shader, reinterpret_cast<IObject**>(ppShader) );
+
+ OnCreateDeviceObject( pShaderD3D11 );
+ }
+ );
+}
+
+void RenderDeviceD3D11Impl :: CreateTexture(const TextureDesc& TexDesc, const TextureData &Data, ITexture **ppTexture)
+{
+ CreateDeviceObject( "texture", TexDesc, ppTexture,
+ [&]()
+ {
+ TextureBaseD3D11 *pTextureD3D11 = nullptr;
+ switch( TexDesc.Type )
+ {
+ case TEXTURE_TYPE_1D:
+ case TEXTURE_TYPE_1D_ARRAY:
+ pTextureD3D11 = new Texture1D_D3D11( this, TexDesc, Data );
+ break;
+
+ case TEXTURE_TYPE_2D:
+ case TEXTURE_TYPE_2D_ARRAY:
+ pTextureD3D11 = new Texture2D_D3D11( this, TexDesc, Data );
+ break;
+
+ case TEXTURE_TYPE_3D:
+ pTextureD3D11 = new Texture3D_D3D11( this, TexDesc, Data );
+ break;
+
+ default: LOG_ERROR_AND_THROW( "Unknown texture type. (Did you forget to initialize the Type member of TextureDesc structure?)" );
+ }
+ pTextureD3D11->QueryInterface( IID_Texture, reinterpret_cast<IObject**>(ppTexture) );
+ pTextureD3D11->CreateDefaultViews();
+ OnCreateDeviceObject( pTextureD3D11 );
+ }
+ );
+}
+
+void RenderDeviceD3D11Impl :: CreateSampler(const SamplerDesc& SamplerDesc, ISampler **ppSampler)
+{
+ CreateDeviceObject( "sampler", SamplerDesc, ppSampler,
+ [&]()
+ {
+ m_SamplersRegistry.Find( SamplerDesc, reinterpret_cast<IDeviceObject**>(ppSampler) );
+ if( *ppSampler == nullptr )
+ {
+ SamplerD3D11Impl *pSamplerD3D11( new SamplerD3D11Impl( this, SamplerDesc ) );
+ pSamplerD3D11->QueryInterface( IID_Sampler, reinterpret_cast<IObject**>(ppSampler) );
+ OnCreateDeviceObject( pSamplerD3D11 );
+ m_SamplersRegistry.Add( SamplerDesc, *ppSampler );
+ }
+ }
+ );
+}
+
+void RenderDeviceD3D11Impl::CreateDepthStencilState( const DepthStencilStateDesc &DSSDesc, IDepthStencilState **ppDepthStencilState )
+{
+ CreateDeviceObject( "depth-stencil state", DSSDesc, ppDepthStencilState,
+ [&]()
+ {
+ m_DSSRegistry.Find( DSSDesc, reinterpret_cast<IDeviceObject**>(ppDepthStencilState) );
+ if( *ppDepthStencilState == nullptr )
+ {
+ DSStateD3D11Impl *pDepthStencilStateD3D11( new DSStateD3D11Impl( this, DSSDesc ) );
+ pDepthStencilStateD3D11->QueryInterface( IID_DepthStencilState, reinterpret_cast<IObject**>(ppDepthStencilState) );
+ OnCreateDeviceObject( pDepthStencilStateD3D11 );
+ m_DSSRegistry.Add( DSSDesc, *ppDepthStencilState );
+ }
+ }
+ );
+}
+
+void RenderDeviceD3D11Impl::CreateRasterizerState( const RasterizerStateDesc &RSDesc, IRasterizerState **ppRasterizerState )
+{
+ CreateDeviceObject( "rasterizer state", RSDesc, ppRasterizerState,
+ [&]()
+ {
+ m_RSRegistry.Find( RSDesc, reinterpret_cast<IDeviceObject**>(ppRasterizerState) );
+ if( *ppRasterizerState == nullptr )
+ {
+ RasterizerStateD3D11Impl *pRasterizerStateD3D11( new RasterizerStateD3D11Impl( this, RSDesc ) );
+ pRasterizerStateD3D11->QueryInterface( IID_RasterizerState, reinterpret_cast<IObject**>(ppRasterizerState) );
+ OnCreateDeviceObject( pRasterizerStateD3D11 );
+ m_RSRegistry.Add( RSDesc, *ppRasterizerState );
+ }
+ }
+ );
+}
+
+
+void RenderDeviceD3D11Impl::CreateBlendState( const BlendStateDesc &BSDesc, IBlendState **ppBlendState )
+{
+ CreateDeviceObject( "blend state", BSDesc, ppBlendState,
+ [&]()
+ {
+ m_BSRegistry.Find( BSDesc, reinterpret_cast<IDeviceObject**>(ppBlendState) );
+ if( *ppBlendState == nullptr )
+ {
+ BlendStateD3D11Impl *pBlendStateD3D11( new BlendStateD3D11Impl( this, BSDesc ) );
+ pBlendStateD3D11->QueryInterface( IID_BlendState, reinterpret_cast<IObject**>(ppBlendState) );
+ OnCreateDeviceObject( pBlendStateD3D11 );
+ m_BSRegistry.Add( BSDesc, *ppBlendState );
+ }
+ }
+ );
+}
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/src/RenderDeviceFactoryD3D11.cpp b/Graphics/GraphicsEngineD3D11/src/RenderDeviceFactoryD3D11.cpp
new file mode 100644
index 00000000..ee040562
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/src/RenderDeviceFactoryD3D11.cpp
@@ -0,0 +1,198 @@
+/* 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.
+ */
+
+#include "pch.h"
+#include "RenderDeviceFactoryD3D11.h"
+#include "RenderDeviceD3D11Impl.h"
+#include "DeviceContextD3D11Impl.h"
+#include "SwapChainD3D11Impl.h"
+#include "D3D11TypeConversions.h"
+#include <Windows.h>
+
+using namespace Diligent;
+using namespace Diligent;
+
+extern "C"
+{
+
+#if defined(_DEBUG)
+// Check for SDK Layer support.
+inline bool SdkLayersAvailable()
+{
+ HRESULT hr = D3D11CreateDevice(
+ nullptr,
+ D3D_DRIVER_TYPE_NULL, // There is no need to create a real hardware device.
+ 0,
+ D3D11_CREATE_DEVICE_DEBUG, // Check for the SDK layers.
+ nullptr, // Any feature level will do.
+ 0,
+ D3D11_SDK_VERSION, // Always set this to D3D11_SDK_VERSION for Windows Store apps.
+ nullptr, // No need to keep the D3D device reference.
+ nullptr, // No need to know the feature level.
+ nullptr // No need to keep the D3D device context reference.
+ );
+
+ return SUCCEEDED(hr);
+}
+#endif
+
+void CreateDeviceAndImmediateContextD3D11( const EngineCreationAttribs& CreationAttribs, IRenderDevice **ppDevice, Diligent::IDeviceContext **ppContext )
+{
+ VERIFY( ppDevice && ppContext, "Null pointer is provided" );
+ if( !ppDevice || !ppContext )
+ return;
+
+ *ppDevice = nullptr;
+ *ppContext = nullptr;
+
+ try
+ {
+ // This flag adds support for surfaces with a different color channel ordering
+ // than the API default. It is required for compatibility with Direct2D.
+ // D3D11_CREATE_DEVICE_BGRA_SUPPORT;
+ UINT creationFlags = 0;
+
+ #if defined(_DEBUG)
+ if (SdkLayersAvailable())
+ {
+ // If the project is in a debug build, enable debugging via SDK Layers with this flag.
+ creationFlags |= D3D11_CREATE_DEVICE_DEBUG;
+ }
+ #endif
+
+ // This array defines the set of DirectX hardware feature levels this app will support.
+ // Note the ordering should be preserved.
+ // Don't forget to declare your application's minimum required feature level in its
+ // description. All applications are assumed to support 9.1 unless otherwise stated.
+ D3D_FEATURE_LEVEL featureLevels[] =
+ {
+#ifdef PLATFORM_WINDOWS_STORE
+ D3D_FEATURE_LEVEL_11_1,
+#endif
+ D3D_FEATURE_LEVEL_11_0,
+ D3D_FEATURE_LEVEL_10_1,
+ D3D_FEATURE_LEVEL_10_0,
+ D3D_FEATURE_LEVEL_9_3,
+ D3D_FEATURE_LEVEL_9_2,
+ D3D_FEATURE_LEVEL_9_1
+ };
+
+ // Create the Direct3D 11 API device object and a corresponding context.
+ RefCntAutoPtr<ID3D11Device> pd3d11Device;
+ RefCntAutoPtr<ID3D11DeviceContext> pd3d11Context;
+
+ D3D_FEATURE_LEVEL d3dFeatureLevel = D3D_FEATURE_LEVEL_11_0;
+ HRESULT hr = D3D11CreateDevice(
+ nullptr, // Specify nullptr to use the default adapter.
+ D3D_DRIVER_TYPE_HARDWARE, // Create a device using the hardware graphics driver.
+ 0, // Should be 0 unless the driver is D3D_DRIVER_TYPE_SOFTWARE.
+ creationFlags, // Set debug and Direct2D compatibility flags.
+ featureLevels, // List of feature levels this app can support.
+ ARRAYSIZE(featureLevels), // Size of the list above.
+ D3D11_SDK_VERSION, // Always set this to D3D11_SDK_VERSION for Windows Store apps.
+ &pd3d11Device, // Returns the Direct3D device created.
+ &d3dFeatureLevel, // Returns feature level of device created.
+ &pd3d11Context // Returns the device immediate context.
+ );
+
+ if (FAILED(hr))
+ {
+ // If the initialization fails, fall back to the WARP device.
+ // For more information on WARP, see:
+ // http://go.microsoft.com/fwlink/?LinkId=286690
+ hr = D3D11CreateDevice(
+ nullptr,
+ D3D_DRIVER_TYPE_WARP, // Create a WARP device instead of a hardware device.
+ 0,
+ creationFlags,
+ featureLevels,
+ ARRAYSIZE(featureLevels),
+ D3D11_SDK_VERSION,
+ &pd3d11Device,
+ &d3dFeatureLevel,
+ &pd3d11Context
+ );
+ CHECK_D3D_RESULT_THROW( hr, "Failed to create D3D11 Device and swap chain" );
+ }
+
+ RenderDeviceD3D11Impl *pRenderDeviceD3D11( new RenderDeviceD3D11Impl( pd3d11Device ) );
+ pRenderDeviceD3D11->QueryInterface(IID_RenderDevice, reinterpret_cast<IObject**>(ppDevice) );
+
+ RefCntAutoPtr<DeviceContextD3D11Impl> pDeviceContextD3D11( new DeviceContextD3D11Impl( pRenderDeviceD3D11, pd3d11Context) );
+ // We must call AddRef() (implicitly through QueryInterface()) because pRenderDeviceD3D11 will
+ // keep a weak reference to the context
+ pDeviceContextD3D11->QueryInterface(IID_DeviceContext, reinterpret_cast<IObject**>(ppContext) );
+ pRenderDeviceD3D11->SetImmediateContext(pDeviceContextD3D11);
+ pDeviceContextD3D11->CreateDefaultStates();
+ }
+ catch( const std::runtime_error & )
+ {
+ if( *ppDevice )
+ {
+ (*ppDevice)->Release();
+ *ppDevice = nullptr;
+ }
+ if( *ppContext )
+ {
+ (*ppContext)->Release();
+ *ppContext = nullptr;
+ }
+
+ LOG_ERROR( "Failed to create device and immediate context" );
+ }
+}
+
+void CreateSwapChainD3D11( IRenderDevice *pDevice, Diligent::IDeviceContext *pImmediateContext, const SwapChainDesc& SwapChainDesc, void* pNativeWndHandle, ISwapChain **ppSwapChain )
+{
+ VERIFY( ppSwapChain, "Null pointer is provided" );
+ if( !ppSwapChain )
+ return;
+
+ *ppSwapChain = nullptr;
+
+ try
+ {
+ auto *pDeviceD3D11 = ValidatedCast<RenderDeviceD3D11Impl>( pDevice );
+ auto *pDeviceContextD3D11 = ValidatedCast<DeviceContextD3D11Impl>(pImmediateContext);
+ auto *pSwapChainD3D11 = new SwapChainD3D11Impl(SwapChainDesc, pDeviceD3D11, pDeviceContextD3D11, pNativeWndHandle);
+ pSwapChainD3D11->QueryInterface( IID_SwapChain, reinterpret_cast<IObject**>(ppSwapChain) );
+
+ pDeviceContextD3D11->SetSwapChain(pSwapChainD3D11);
+ // Bind default render target
+ pDeviceContextD3D11->SetRenderTargets( 0, nullptr, nullptr );
+ // Set default viewport
+ pDeviceContextD3D11->SetViewports( 1, nullptr, 0, 0 );
+ }
+ catch( const std::runtime_error & )
+ {
+ if( *ppSwapChain )
+ {
+ (*ppSwapChain)->Release();
+ *ppSwapChain = nullptr;
+ }
+
+ LOG_ERROR( "Failed to create the swap chain" );
+ }
+}
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/src/SamplerD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/SamplerD3D11Impl.cpp
new file mode 100644
index 00000000..3aa13c74
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/src/SamplerD3D11Impl.cpp
@@ -0,0 +1,60 @@
+/* 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.
+ */
+
+#include "pch.h"
+#include "SamplerD3D11Impl.h"
+#include "RenderDeviceD3D11Impl.h"
+#include "D3D11TypeConversions.h"
+
+namespace Diligent
+{
+
+SamplerD3D11Impl::SamplerD3D11Impl(class RenderDeviceD3D11Impl *pRenderDeviceD3D11, const SamplerDesc& SamplerDesc) :
+ TSamplerBase(pRenderDeviceD3D11, SamplerDesc)
+{
+ auto *pd3d11Device = pRenderDeviceD3D11->GetD3D11Device();
+ D3D11_SAMPLER_DESC D3D11SamplerDesc =
+ {
+ FilterTypeToD3D11Filter(SamplerDesc.MinFilter, SamplerDesc.MagFilter, SamplerDesc.MipFilter),
+ TexAddressModeToD3D11AddressMode(SamplerDesc.AddressU),
+ TexAddressModeToD3D11AddressMode(SamplerDesc.AddressV),
+ TexAddressModeToD3D11AddressMode(SamplerDesc.AddressW),
+ SamplerDesc.MipLODBias,
+ SamplerDesc.MaxAnisotropy,
+ ComparisonFuncToD3D11ComparisonFunc(SamplerDesc.ComparisonFunc),
+ {SamplerDesc.BorderColor[0], SamplerDesc.BorderColor[1], SamplerDesc.BorderColor[2], SamplerDesc.BorderColor[3]},
+ SamplerDesc.MinLOD,
+ SamplerDesc.MaxLOD
+ };
+ CHECK_D3D_RESULT_THROW( pd3d11Device->CreateSamplerState(&D3D11SamplerDesc, &m_pd3dSampler),
+ "Failed to create the Direct3D11 sampler");
+}
+
+SamplerD3D11Impl::~SamplerD3D11Impl()
+{
+
+}
+
+IMPLEMENT_QUERY_INTERFACE( SamplerD3D11Impl, IID_SamplerD3D11, TSamplerBase )
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp
new file mode 100644
index 00000000..651261ac
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp
@@ -0,0 +1,838 @@
+/* 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.
+ */
+
+#include "pch.h"
+
+#include <D3Dcompiler.h>
+
+#include "ShaderD3D11Impl.h"
+#include "RenderDeviceD3D11Impl.h"
+#include "StringTools.h"
+#include "ResourceMapping.h"
+#include "BufferD3D11Impl.h"
+#include "GraphicsUtilities.h"
+#include "TextureViewD3D11Impl.h"
+#include "SamplerD3D11Impl.h"
+#include "BufferViewD3D11Impl.h"
+#include "D3D11DebugUtilities.h"
+#include "DataBlobImpl.h"
+
+using namespace Diligent;
+
+namespace Diligent
+{
+const String ShaderD3D11Impl::m_SamplerSuffix = "_sampler";
+const UINT InvalidBindPoint = std::numeric_limits<UINT>::max();
+
+static const Char* g_HLSLDefinitions =
+{
+ #include "HLSLDefinitions_inc.fxh"
+};
+
+
+class D3DIncludeImpl : public ID3DInclude
+{
+public:
+ D3DIncludeImpl(IShaderSourceInputStreamFactory *pStreamFactory) :
+ m_pStreamFactory(pStreamFactory)
+ {
+
+ }
+
+ STDMETHOD( Open )(THIS_ D3D_INCLUDE_TYPE IncludeType, LPCSTR pFileName, LPCVOID pParentData, LPCVOID *ppData, UINT *pBytes)
+ {
+ RefCntAutoPtr<IFileStream> pSourceStream;
+ m_pStreamFactory->CreateInputStream( pFileName, &pSourceStream );
+ if( pSourceStream == nullptr )
+ {
+ LOG_ERROR( "Failed to open shader include file ", pFileName, ". Check that the file exists" );
+ return E_FAIL;
+ }
+
+ RefCntAutoPtr<Diligent::IDataBlob> pFileData( new Diligent::DataBlobImpl );
+ pSourceStream->Read( pFileData );
+ *ppData = pFileData->GetDataPtr();
+ *pBytes = static_cast<UINT>( pFileData->GetSize() );
+
+ m_DataBlobs.insert( std::make_pair(*ppData, pFileData) );
+
+ return S_OK;
+ }
+
+ STDMETHOD( Close )(THIS_ LPCVOID pData)
+ {
+ m_DataBlobs.erase( pData );
+ return S_OK;
+ }
+
+private:
+ IShaderSourceInputStreamFactory *m_pStreamFactory;
+ std::unordered_map< LPCVOID, RefCntAutoPtr<Diligent::IDataBlob> > m_DataBlobs;
+};
+
+static
+HRESULT CompileShader( const char* Source,
+ LPCSTR strFunctionName,
+ const D3D_SHADER_MACRO* pDefines,
+ IShaderSourceInputStreamFactory *pIncludeStreamFactory,
+ LPCSTR profile,
+ ID3DBlob **ppBlobOut )
+{
+ DWORD dwShaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;
+#if defined( DEBUG ) || defined( _DEBUG )
+ // Set the D3D10_SHADER_DEBUG flag to embed debug information in the shaders.
+ // Setting this flag improves the shader debugging experience, but still allows
+ // the shaders to be optimized and to run exactly the way they will run in
+ // the release configuration of this program.
+ dwShaderFlags |= D3DCOMPILE_DEBUG;
+#else
+ // Warning: do not use this flag as it causes shader compiler to fail the compilation and
+ // report strange errors:
+ // dwShaderFlags |= D3D10_SHADER_OPTIMIZATION_LEVEL3;
+#endif
+ HRESULT hr;
+ do
+ {
+ CComPtr<ID3DBlob> errors;
+ auto SourceLen = strlen(Source);
+
+ D3DIncludeImpl IncludeImpl(pIncludeStreamFactory);
+ hr = D3DCompile( Source, SourceLen, NULL, pDefines, &IncludeImpl, strFunctionName, profile, dwShaderFlags, 0, ppBlobOut, &errors );
+
+ if( FAILED(hr) || errors )
+ {
+ std::wstringstream errorss;
+ ComErrorDesc ErrDesc(hr);
+ if( FAILED(hr) )
+ Diligent::FormatMsg( errorss, "Failed to compile shader\n" );
+ else
+ Diligent::FormatMsg( errorss, "Shader compiler output:\n" );
+ Diligent::FormatMsg( errorss, ErrDesc.Get(), "\n" );
+ if( errors )
+ Diligent::FormatMsg( errorss, (char*)errors->GetBufferPointer() );
+ auto ErrorDesc = errorss.str();
+ OutputDebugString( ErrorDesc.c_str() );
+ if( FAILED(hr)
+#ifdef PLATFORM_WINDOWS
+ && IDRETRY != MessageBox( NULL, ErrorDesc.c_str() , L"FX Error", MB_ICONERROR | (Source == nullptr ? MB_ABORTRETRYIGNORE : 0) )
+#endif
+ )
+ {
+ break;
+ }
+ }
+ } while( FAILED(hr) );
+ return hr;
+}
+
+const char* DXShaderProfileToString(SHADER_PROFILE DXProfile)
+{
+ return "5_0";
+ //switch(DXProfile)
+ //{
+ // case DX_SHADER_PROFILE_4_0: return "4_0";
+ // case DX_SHADER_PROFILE_5_0: return "5_0";
+ // default: UNEXPECTED("Unknown DirectX shader profile" ); return "";
+ //}
+}
+
+void ShaderD3D11Impl::LoadShaderResources()
+{
+ CComPtr<ID3D11ShaderReflection> pShaderReflection;
+ CHECK_D3D_RESULT_THROW( D3DReflect( m_pShaderByteCode->GetBufferPointer(), m_pShaderByteCode->GetBufferSize(), __uuidof(pShaderReflection), reinterpret_cast<void**>(static_cast<ID3D11ShaderReflection**>(&pShaderReflection)) ),
+ "Failed to get the shader reflection" );
+
+ struct ResourceBindInfo
+ {
+ String Name;
+ UINT BindPoint;
+ };
+
+ std::vector<ResourceBindInfo> Textures;
+ std::unordered_map<String, ResourceBindInfo> Samplers;
+
+ D3D11_SHADER_DESC shaderDesc;
+ memset( &shaderDesc, 0, sizeof(shaderDesc) );
+ pShaderReflection->GetDesc( &shaderDesc );
+ for( UINT Res = 0; Res < shaderDesc.BoundResources; ++Res )
+ {
+ D3D11_SHADER_INPUT_BIND_DESC BindingDesc;
+ memset( &BindingDesc, 0, sizeof( BindingDesc ) );
+ pShaderReflection->GetResourceBindingDesc( Res, &BindingDesc );
+
+ switch( BindingDesc.Type )
+ {
+ case D3D_SIT_CBUFFER:
+ {
+ ConstBuffBindInfo NewCBInfo(this, BindingDesc.Name, BindingDesc.BindPoint);
+#ifdef _DEBUG
+ std::for_each( m_ConstanBuffers.begin(), m_ConstanBuffers.end(),
+ [&]( const ConstBuffBindInfo &CBInfo )
+ {
+ VERIFY( CBInfo.Name != BindingDesc.Name, "Constant buffer with the same name already exists" );
+ }
+ );
+#endif
+ m_ConstanBuffers.emplace_back( NewCBInfo );
+ break;
+ }
+
+ case D3D_SIT_TBUFFER:
+ {
+ UNSUPPORTED( "TBuffers are not supported" );
+ break;
+ }
+
+ case D3D_SIT_TEXTURE:
+ {
+
+ if( BindingDesc.Dimension == D3D_SRV_DIMENSION_BUFFER )
+ {
+ m_BuffSRVs.emplace_back( BuffSRVBindInfo(this, BindingDesc.Name, BindingDesc.BindPoint) );
+ }
+ else
+ {
+ ResourceBindInfo NewTextureInfo = { BindingDesc.Name, BindingDesc.BindPoint };
+ Textures.emplace_back( NewTextureInfo );
+ }
+ break;
+ }
+
+ case D3D_SIT_SAMPLER:
+ {
+ ResourceBindInfo NewSamplerInfo = { BindingDesc.Name, BindingDesc.BindPoint };
+ Samplers.emplace( std::make_pair( BindingDesc.Name, NewSamplerInfo ) );
+ break;
+ }
+
+ case D3D_SIT_UAV_RWTYPED:
+ {
+ if( BindingDesc.Dimension == D3D_SRV_DIMENSION_BUFFER )
+ {
+ m_BuffUAVs.push_back( BuffUAVBindInfo( this, BindingDesc.Name, BindingDesc.BindPoint, BindingDesc.Type ) );
+ }
+ else
+ {
+ m_TexUAVs.push_back( TexUAVBindInfo( this, BindingDesc.Name, BindingDesc.BindPoint, BindingDesc.Type ) );
+ }
+ break;
+ }
+
+ case D3D_SIT_STRUCTURED:
+ {
+ UNSUPPORTED( "Structured buffers are not supported" );
+ break;
+ }
+
+ case D3D_SIT_UAV_RWSTRUCTURED:
+ {
+ m_BuffUAVs.push_back( BuffUAVBindInfo( this, BindingDesc.Name, BindingDesc.BindPoint, BindingDesc.Type ) );
+ break;
+ }
+
+ case D3D_SIT_BYTEADDRESS:
+ {
+ UNSUPPORTED( "Byte address buffers are not supported" );
+ break;
+ }
+
+ case D3D_SIT_UAV_RWBYTEADDRESS:
+ {
+ m_BuffUAVs.push_back( BuffUAVBindInfo(this, BindingDesc.Name, BindingDesc.BindPoint, BindingDesc.Type) );
+ break;
+ }
+
+ case D3D_SIT_UAV_APPEND_STRUCTURED:
+ {
+ UNSUPPORTED( "Append structured buffers are not supported" );
+ break;
+ }
+
+ case D3D_SIT_UAV_CONSUME_STRUCTURED:
+ {
+ UNSUPPORTED( "Consume structured buffers are not supported" );
+ break;
+ }
+
+ case D3D_SIT_UAV_RWSTRUCTURED_WITH_COUNTER:
+ {
+ UNSUPPORTED( "RW structured buffers with counter are not supported" );
+ break;
+ }
+ }
+ }
+
+ // Merge texture and sampler list
+ for( auto it = Textures.begin(); it != Textures.end(); ++it )
+ {
+ auto SamplerName = it->Name + m_SamplerSuffix;
+ auto SamplerIt = Samplers.find(SamplerName);
+ UINT SamplerBindPoint = InvalidBindPoint;
+ if( SamplerIt != Samplers.end() )
+ {
+ VERIFY( SamplerIt->second.Name == SamplerName, "Unexpected sampler name" );
+ SamplerBindPoint = SamplerIt->second.BindPoint;
+ }
+ else
+ {
+ SamplerName = "";
+ }
+ TexAndSamplerBindInfo TexAndSamplerInfo(this, it->Name, it->BindPoint, SamplerName, SamplerBindPoint);
+ m_TexAndSamplers.emplace_back( TexAndSamplerInfo );
+ }
+
+ // After all resources are loaded, we can populate shader variable hash map.
+ // The map contains raw pointers, but none of the arrays will ever change.
+#define STORE_SHADER_VARIABLES(ResArr)\
+ { \
+ for( auto it = ResArr.begin(); it != ResArr.end(); ++it ) \
+ /* HashMapStringKey will make a copy of the string*/ \
+ m_VariableHash.insert( std::make_pair( Diligent::HashMapStringKey(it->GetName()), &*it ) ); \
+ }
+
+ STORE_SHADER_VARIABLES(m_ConstanBuffers)
+ STORE_SHADER_VARIABLES(m_TexAndSamplers)
+ STORE_SHADER_VARIABLES(m_TexUAVs)
+ STORE_SHADER_VARIABLES(m_BuffUAVs)
+ STORE_SHADER_VARIABLES(m_BuffSRVs)
+
+#undef STORE_SHADER_VARIABLES
+}
+
+ShaderD3D11Impl::ShaderD3D11Impl(RenderDeviceD3D11Impl *pRenderDeviceD3D11, const ShaderCreationAttribs &ShaderCreationAttribs) :
+ TShaderBase(pRenderDeviceD3D11, ShaderCreationAttribs.Desc)
+{
+ std::string strShaderProfile;
+ switch(ShaderCreationAttribs.Desc.ShaderType)
+ {
+ case SHADER_TYPE_VERTEX: strShaderProfile="vs"; break;
+ case SHADER_TYPE_PIXEL: strShaderProfile="ps"; break;
+ case SHADER_TYPE_GEOMETRY:strShaderProfile="gs"; break;
+ case SHADER_TYPE_HULL: strShaderProfile="hs"; break;
+ case SHADER_TYPE_DOMAIN: strShaderProfile="ds"; break;
+ case SHADER_TYPE_COMPUTE: strShaderProfile="cs"; break;
+
+ default: UNEXPECTED( "Unknown shader type" );
+ }
+ strShaderProfile += "_";
+ auto *pProfileSuffix = DXShaderProfileToString(ShaderCreationAttribs.Desc.TargetProfile);
+ strShaderProfile += pProfileSuffix;
+
+ String ShaderSource(g_HLSLDefinitions);
+ if( ShaderCreationAttribs.Source )
+ ShaderSource.append( ShaderCreationAttribs.Source );
+ else
+ {
+ VERIFY(ShaderCreationAttribs.pShaderSourceStreamFactory, "Input stream factory is null");
+ RefCntAutoPtr<IFileStream> pSourceStream;
+ ShaderCreationAttribs.pShaderSourceStreamFactory->CreateInputStream( ShaderCreationAttribs.FilePath, &pSourceStream );
+ RefCntAutoPtr<Diligent::IDataBlob> pFileData( new Diligent::DataBlobImpl );
+ pSourceStream->Read( pFileData );
+ // Null terminator is not read from the stream!
+ auto* FileDataPtr = reinterpret_cast<Char*>( pFileData->GetDataPtr() );
+ auto Size = pFileData->GetSize();
+ ShaderSource.append( FileDataPtr, FileDataPtr + Size/sizeof(*FileDataPtr) );
+ }
+
+ const D3D_SHADER_MACRO *pDefines = nullptr;
+ std::vector<D3D_SHADER_MACRO> D3DMacros;
+ if( ShaderCreationAttribs.Macros )
+ {
+ for( auto* pCurrMacro = ShaderCreationAttribs.Macros; pCurrMacro->Name && pCurrMacro->Definition; ++pCurrMacro )
+ {
+ D3DMacros.push_back( {pCurrMacro->Name, pCurrMacro->Definition} );
+ }
+ D3DMacros.push_back( {nullptr, nullptr} );
+ pDefines = D3DMacros.data();
+ }
+
+ CHECK_D3D_RESULT_THROW( CompileShader( ShaderSource.c_str(), ShaderCreationAttribs.EntryPoint, pDefines, ShaderCreationAttribs.pShaderSourceStreamFactory, strShaderProfile.c_str(), &m_pShaderByteCode ),
+ "Failed to compile the shader");
+
+ auto *pDeviceD3D11 = pRenderDeviceD3D11->GetD3D11Device();
+ switch(ShaderCreationAttribs.Desc.ShaderType)
+ {
+
+#define CREATE_SHADER(SHADER_NAME, ShaderName)\
+ case SHADER_TYPE_##SHADER_NAME: \
+ { \
+ ID3D11##ShaderName##Shader *pShader; \
+ HRESULT hr = pDeviceD3D11->Create##ShaderName##Shader( m_pShaderByteCode->GetBufferPointer(), m_pShaderByteCode->GetBufferSize(), NULL, &pShader ); \
+ CHECK_D3D_RESULT_THROW( hr, "Failed to create D3D11 shader" ); \
+ if( SUCCEEDED(hr) ) \
+ { \
+ pShader->QueryInterface( __uuidof(ID3D11DeviceChild), reinterpret_cast<void**>( static_cast<ID3D11DeviceChild**>(&m_pShader) ) ); \
+ pShader->Release(); \
+ } \
+ break; \
+ }
+
+ CREATE_SHADER(VERTEX, Vertex)
+ CREATE_SHADER(PIXEL, Pixel)
+ CREATE_SHADER(GEOMETRY, Geometry)
+ CREATE_SHADER(DOMAIN, Domain)
+ CREATE_SHADER(HULL, Hull)
+ CREATE_SHADER(COMPUTE, Compute)
+
+ default: UNEXPECTED( "Unknown shader type" );
+ }
+
+ if(!m_pShader)
+ LOG_ERROR_AND_THROW("Failed to create the shader from the byte code");
+
+ LoadShaderResources();
+
+ // Byte code is only required for the vertex shader to create input layout
+ if( ShaderCreationAttribs.Desc.ShaderType != SHADER_TYPE_VERTEX )
+ m_pShaderByteCode.Release();
+}
+
+ShaderD3D11Impl::~ShaderD3D11Impl()
+{
+}
+
+#define LOG_RESORUCE_BINDING_ERROR(ResType, pResource, VarName, ShaderName, ...)\
+{ \
+ const auto &ResName = pResource->GetDesc().Name; \
+ LOG_ERROR_MESSAGE( "Failed to bind ", ResType, " \"", ResName, "\" to variable \"", VarName, \
+ "\" in shader \"", ShaderName, "\". ", __VA_ARGS__ ); \
+}
+
+void ShaderD3D11Impl::BindConstantBuffers( IResourceMapping* pResourceMapping, Uint32 Flags )
+{
+ if( !pResourceMapping )
+ {
+ LOG_ERROR_MESSAGE( "Failed to bind constant buffers in shader \"", m_Desc.Name ? m_Desc.Name : "", "\": resource mapping is null" );
+ return;
+ }
+ // Bind constant buffers
+ if( Flags & BIND_SHADER_RESOURCES_RESET_BINDINGS )
+ {
+ m_BoundCBs.clear();
+ }
+ for( auto it = m_ConstanBuffers.begin(); it != m_ConstanBuffers.end(); ++it )
+ {
+ if( (Flags & BIND_SHADER_RESOURCES_UPDATE_UNRESOLVED) && it->IsBound() )
+ continue;
+
+ RefCntAutoPtr<IDeviceObject> pBuffer;
+ if( pResourceMapping )
+ pResourceMapping->GetResource( it->Name.c_str(), &pBuffer );
+ if( pBuffer )
+ {
+ it->Set( pBuffer );
+ }
+ else
+ {
+ if( (Flags & BIND_SHADER_RESOURCES_ALL_RESOLVED) && !it->IsBound() )
+ LOG_ERROR_MESSAGE("Cannot bind resource to shader variable \"", it->Name, "\": resource not found in the resource mapping")
+ continue;
+ }
+ }
+}
+
+
+void ShaderD3D11Impl::ConstBuffBindInfo::Set( IDeviceObject *pBuffer )
+{
+ auto *pShaderD3D11 = ValidatedCast<ShaderD3D11Impl>( m_pShader );
+ auto &BoundCBs = pShaderD3D11->m_BoundCBs;
+ if( BoundCBs.size() <= BindPoint )
+ BoundCBs.resize( BindPoint + 1 );
+
+ if( pBuffer )
+ {
+ RefCntAutoPtr<IBufferD3D11> pBuffD3D11;
+ pBuffer->QueryInterface( IID_BufferD3D11, reinterpret_cast<IObject**>(static_cast<IBufferD3D11**>(&pBuffD3D11)) );
+ if( pBuffD3D11 )
+ {
+ if( pBuffD3D11->GetDesc().BindFlags & BIND_UNIFORM_BUFFER )
+ {
+ BoundCBs[BindPoint].pd3d11Buff = pBuffD3D11->GetD3D11Buffer();
+ VERIFY(BoundCBs[BindPoint].pd3d11Buff, "No relevant D3D11 buffer")
+ BoundCBs[BindPoint].pBuff = pBuffD3D11;
+ }
+ else
+ {
+ LOG_RESORUCE_BINDING_ERROR("buffer", pBuffer, Name, pShaderD3D11->m_Desc.Name, "Buffer was not created with BIND_UNIFORM_BUFFER flag.")
+ }
+ }
+ else
+ {
+ LOG_RESORUCE_BINDING_ERROR("buffer", pBuffer, Name, pShaderD3D11->m_Desc.Name, "Incorrect resource type: buffer is expected.")
+ }
+ }
+ else
+ {
+ BoundCBs[BindPoint] = BoundCB();
+ }
+}
+
+bool ShaderD3D11Impl::ConstBuffBindInfo::IsBound()
+{
+ auto *pShaderD3D11 = ValidatedCast<ShaderD3D11Impl>( m_pShader );
+ auto &BoundCBs = pShaderD3D11->m_BoundCBs;
+ if( BindPoint < BoundCBs.size() && BoundCBs[BindPoint].pd3d11Buff != nullptr )
+ {
+ VERIFY(BoundCBs[BindPoint].pBuff != nullptr, "No relevant buffer resource")
+ return true;
+ }
+
+ return false;
+}
+
+template<typename TResourceViewType>
+struct ResourceViewTraits{};
+
+template<>
+struct ResourceViewTraits<ITextureViewD3D11>
+{
+ static const Char *Name;
+};
+const Char *ResourceViewTraits<ITextureViewD3D11>::Name = "texture view";
+
+template<>
+struct ResourceViewTraits<IBufferViewD3D11>
+{
+ static const Char *Name;
+};
+const Char *ResourceViewTraits<IBufferViewD3D11>::Name = "buffer view";
+
+// Helper template class that facilitates binding SRVs and UAVs
+class BindViewHelper
+{
+public:
+ BindViewHelper(IResourceMapping *pRM, Uint32 Fl) :
+ pResourceMapping(pRM),
+ Flags(Fl)
+ {}
+
+ template<typename IterType>
+ void Bind( IterType &pShaderVar)
+ {
+ if( (Flags & BIND_SHADER_RESOURCES_UPDATE_UNRESOLVED) && pShaderVar->IsBound() )
+ return;
+
+ const auto& VarName = pShaderVar->GetName();
+ RefCntAutoPtr<IDeviceObject> pView;
+ if( pResourceMapping )
+ pResourceMapping->GetResource( VarName.c_str(), &pView );
+ if( pView )
+ {
+ pShaderVar->Set(pView);
+ }
+ else
+ {
+ if( (Flags & BIND_SHADER_RESOURCES_ALL_RESOLVED) && !pShaderVar->IsBound() )
+ LOG_ERROR_MESSAGE( "Cannot bind resource to shader variable \"", VarName, "\": resource view not found in the resource mapping" )
+ return;
+ }
+ }
+
+private:
+ IResourceMapping* const pResourceMapping;
+ const Uint32 Flags;
+};
+
+// Helper template function to facilitate setting shader variables
+// of different types
+template<typename TResourceViewType, ///< Type of the view (ITextureViewD3D11 or IBufferViewD3D11)
+ typename TD3D11ViewType, ///< Type of the D3D11 view (ID3D11ShaderResourceView or ID3D11UnorderedAccessView)
+ typename TBoundViewType, ///< Type of the bound view data array element (BoundSRV or BoundUAV)
+ typename TGetResourceMethodType, ///< Type of the method to get resource from the view (ITextureViewD3D11::GetTexture or IBufferViewD3D11::GetBuffer)
+ typename TBindSamplerProcType, ///< Type of the procedure to set samplers
+ typename TViewTypeEnum> ///< Type of the expected view enum
+void SetShaderVariableHelper(IDeviceObject *pView,
+ std::vector<TBoundViewType> &ViewArray,
+ UINT BindPoint,
+ const String& VarName,
+ TGetResourceMethodType GetResourceMethod,
+ const Diligent::INTERFACE_ID ViewID,
+ typename TViewTypeEnum ExpectedViewType,
+ const String& ShaderName,
+ TBindSamplerProcType BindSamplerProc)
+{
+ if( ViewArray.size() <= BindPoint )
+ ViewArray.resize( BindPoint + 1 );
+ if( pView )
+ {
+ RefCntAutoPtr<TResourceViewType> pViewD3D11;
+ pView->QueryInterface( ViewID, reinterpret_cast<IObject**>(static_cast<TResourceViewType**>(&pViewD3D11)) );
+ if( pViewD3D11 )
+ {
+ auto ViewType = pViewD3D11->GetDesc().ViewType;
+ if( ViewType == ExpectedViewType )
+ {
+ auto &BoundView = ViewArray[BindPoint];
+ BoundView.pd3d11View = static_cast<TD3D11ViewType*>( pViewD3D11->GetD3D11View() );
+ VERIFY(BoundView.pd3d11View, "No relevant D3D11 view")
+ BoundView.pView = pViewD3D11;
+ BoundView.pResource = (pViewD3D11->*GetResourceMethod)();
+ VERIFY(BoundView.pResource, "No relevant resource")
+ BindSamplerProc(pViewD3D11);
+ }
+ else
+ {
+ const auto *ExpectedViewTypeName = GetViewTypeLiteralName( ExpectedViewType );
+ const auto *ActualViewTypeName = GetViewTypeLiteralName( ViewType );
+ LOG_RESORUCE_BINDING_ERROR(ResourceViewTraits<TResourceViewType>::Name, pViewD3D11, VarName, ShaderName,
+ "Incorrect view type: ", ExpectedViewTypeName, " is expected, ", ActualViewTypeName, " provided." );
+ }
+ }
+ else
+ {
+ LOG_RESORUCE_BINDING_ERROR("resource", pView, VarName, ShaderName, "Incorect resource type: ", ResourceViewTraits<TResourceViewType>::Name, " is expected.")
+ }
+ }
+ else
+ {
+ ViewArray[BindPoint] = TBoundViewType();
+ BindSamplerProc(nullptr);
+ }
+}
+
+void ShaderD3D11Impl::TexAndSamplerBindInfo::Set( IDeviceObject *pView )
+{
+ auto *pShaderD3D11 = ValidatedCast<ShaderD3D11Impl>( m_pShader );
+ SetShaderVariableHelper<ITextureViewD3D11, ID3D11ShaderResourceView>(pView, pShaderD3D11->m_BoundSRVs, BindPoint, Name,
+ &ITextureViewD3D11::GetTexture, IID_TextureViewD3D11, TEXTURE_VIEW_SHADER_RESOURCE,
+ pShaderD3D11->m_Desc.Name,
+ [&]( ITextureViewD3D11 *pTexViewD3D11 )
+ {
+ if( SamplerBindPoint != InvalidBindPoint )
+ {
+ auto &BoundSamplers = pShaderD3D11->m_BoundSamplers;
+ if( BoundSamplers.size() <= SamplerBindPoint )
+ BoundSamplers.resize( SamplerBindPoint + 1 );
+ auto &BndSam = BoundSamplers[SamplerBindPoint];
+ if( pTexViewD3D11 )
+ {
+ auto pSampler = pTexViewD3D11->GetSampler();
+ if( pSampler )
+ {
+ BndSam.pd3d11Sampler = ValidatedCast<SamplerD3D11Impl>(pSampler)->m_pd3dSampler;
+ VERIFY(BndSam.pd3d11Sampler, "No relevant D3D11 sampler")
+ BndSam.pSampler = pSampler;
+ }
+ else
+ {
+ LOG_ERROR_MESSAGE( "Failed to bind sampler to variable \"", SamplerName, ". Sampler is not set in the texture view \"", pTexViewD3D11->GetDesc().Name, "\"" );
+ }
+ }
+ else
+ {
+ BndSam = BoundSampler();
+ }
+ }
+ }
+ );
+
+}
+
+void ShaderD3D11Impl::BuffSRVBindInfo::Set( IDeviceObject *pView )
+{
+ auto *pShaderD3D11 = ValidatedCast<ShaderD3D11Impl>( m_pShader );
+ SetShaderVariableHelper<IBufferViewD3D11, ID3D11ShaderResourceView>(pView, pShaderD3D11->m_BoundSRVs, BindPoint, Name,
+ &IBufferViewD3D11::GetBuffer, IID_BufferViewD3D11, BUFFER_VIEW_SHADER_RESOURCE,
+ pShaderD3D11->m_Desc.Name,
+ []( IBufferViewD3D11 * ){}
+ );
+}
+
+void ShaderD3D11Impl::TexUAVBindInfo::Set( IDeviceObject *pView )
+{
+ auto *pShaderD3D11 = ValidatedCast<ShaderD3D11Impl>( m_pShader );
+ SetShaderVariableHelper<ITextureViewD3D11, ID3D11UnorderedAccessView>(
+ pView, pShaderD3D11->m_BoundUAVs, BindPoint, Name,
+ &ITextureViewD3D11::GetTexture, IID_TextureViewD3D11, TEXTURE_VIEW_UNORDERED_ACCESS,
+ pShaderD3D11->m_Desc.Name,
+ []( ITextureViewD3D11 * ){}
+ );
+}
+
+void ShaderD3D11Impl::BuffUAVBindInfo::Set( IDeviceObject *pView )
+{
+ auto *pShaderD3D11 = ValidatedCast<ShaderD3D11Impl>( m_pShader );
+ SetShaderVariableHelper<IBufferViewD3D11, ID3D11UnorderedAccessView>(pView, pShaderD3D11->m_BoundUAVs, BindPoint, Name,
+ &IBufferViewD3D11::GetBuffer, IID_BufferViewD3D11, BUFFER_VIEW_UNORDERED_ACCESS,
+ pShaderD3D11->m_Desc.Name,
+ []( IBufferViewD3D11 * ){}
+ );
+}
+
+template<typename TBoundViewType>
+bool CheckBoundResource(const std::vector<TBoundViewType> &ViewArray, UINT BindPoint)
+{
+ if( BindPoint < ViewArray.size() && ViewArray[BindPoint].pd3d11View != nullptr )
+ {
+ VERIFY(ViewArray[BindPoint].pResource != nullptr, "No relevant resource")
+ VERIFY(ViewArray[BindPoint].pView != nullptr, "No relevant resource view")
+ return true;
+ }
+ return false;
+}
+
+bool ShaderD3D11Impl::TexAndSamplerBindInfo::IsBound()
+{
+ auto *pShaderD3D11 = ValidatedCast<ShaderD3D11Impl>( m_pShader );
+ return CheckBoundResource( pShaderD3D11->m_BoundSRVs, BindPoint );
+}
+
+bool ShaderD3D11Impl::BuffSRVBindInfo::IsBound()
+{
+ auto *pShaderD3D11 = ValidatedCast<ShaderD3D11Impl>( m_pShader );
+ return CheckBoundResource( pShaderD3D11->m_BoundSRVs, BindPoint );
+}
+
+bool ShaderD3D11Impl::UAVBindInfoBase::IsBound()
+{
+ auto *pShaderD3D11 = ValidatedCast<ShaderD3D11Impl>( m_pShader );
+ return CheckBoundResource( pShaderD3D11->m_BoundUAVs, BindPoint );
+}
+
+void ShaderD3D11Impl::BindSRVsAndSamplers(IResourceMapping* pResourceMapping, Uint32 Flags )
+{
+ if( !pResourceMapping )
+ {
+ LOG_ERROR_MESSAGE( "Failed to bind SRVs and samplers in shader \"", m_Desc.Name ? m_Desc.Name : "", "\": resource mapping is null" );
+ return;
+ }
+
+ if( Flags & BIND_SHADER_RESOURCES_RESET_BINDINGS )
+ {
+ m_BoundSRVs.clear();
+ m_BoundSamplers.clear();
+ }
+
+ BindViewHelper BindSRVHelper(pResourceMapping, Flags);
+
+ for( auto it = m_TexAndSamplers.begin(); it != m_TexAndSamplers.end(); ++it )
+ {
+ BindSRVHelper.Bind(it);
+ }
+
+ for( auto it = m_BuffSRVs.begin(); it != m_BuffSRVs.end(); ++it )
+ {
+ BindSRVHelper.Bind(it);
+ }
+}
+
+void ShaderD3D11Impl::BindUAVs( IResourceMapping* pResourceMapping, Uint32 Flags )
+{
+ if( !pResourceMapping )
+ {
+ LOG_ERROR_MESSAGE( "Failed to bind UAVs in shader \"", m_Desc.Name ? m_Desc.Name : "", "\": resource mapping is null" );
+ return;
+ }
+
+ // Bind constant buffers
+ if( Flags & BIND_SHADER_RESOURCES_RESET_BINDINGS )
+ {
+ m_BoundUAVs.clear();
+ }
+
+ BindViewHelper BindUAVHelper(pResourceMapping, Flags);
+
+ for( auto it = m_TexUAVs.begin(); it != m_TexUAVs.end(); ++it )
+ {
+ BindUAVHelper.Bind(it);
+ }
+
+ for( auto it = m_BuffUAVs.begin(); it != m_BuffUAVs.end(); ++it )
+ {
+ BindUAVHelper.Bind(it);
+ }
+}
+
+void ShaderD3D11Impl::BindResources( IResourceMapping* pResourceMapping, Uint32 Flags )
+{
+ if( !pResourceMapping )
+ {
+ LOG_ERROR_MESSAGE( "Failed to bind resources in shader \"", m_Desc.Name ? m_Desc.Name : "", "\": resource mapping is null" );
+ return;
+ }
+
+ BindConstantBuffers( pResourceMapping, Flags );
+ BindSRVsAndSamplers( pResourceMapping, Flags );
+ BindUAVs(pResourceMapping, Flags );
+}
+
+IShaderVariable* ShaderD3D11Impl::GetShaderVariable( const Char* Name )
+{
+ // Name will be implicitly converted to HashMapStringKey without making a copy
+ auto it = m_VariableHash.find( Name );
+ if( it == m_VariableHash.end() )
+ {
+ LOG_ERROR_MESSAGE( "Shader variable \"", Name, "\" is not found in shader \"", m_Desc.Name ? m_Desc.Name : "", "\". Attempts to set the variable will be silently ignored." );
+ return &m_DummyShaderVar;
+ }
+ return it->second;
+}
+
+
+
+IMPLEMENT_QUERY_INTERFACE( ShaderD3D11Impl, IID_ShaderD3D11, TShaderBase )
+
+#ifdef VERIFY_SHADER_BINDINGS
+void ShaderD3D11Impl::dbgVerifyBindings()
+{
+ const auto *ShaderName = m_Desc.Name ? m_Desc.Name : "";
+#define LOG_MISSING_BINDING(VarType, Name)\
+ LOG_ERROR_MESSAGE( "No resource is bound to ", VarType, " variable \"", Name, "\" in shader \"", ShaderName, "\"" );
+
+ for( auto cb = m_ConstanBuffers.begin(); cb != m_ConstanBuffers.end(); ++cb )
+ {
+ if( m_BoundCBs.size() <= cb->BindPoint || m_BoundCBs[cb->BindPoint].pd3d11Buff == nullptr )
+ LOG_MISSING_BINDING("constant buffer", cb->Name)
+ }
+
+ for( auto tex = m_TexAndSamplers.begin(); tex != m_TexAndSamplers.end(); ++tex )
+ {
+ if( m_BoundSRVs.size() <= tex->BindPoint || m_BoundSRVs[tex->BindPoint].pd3d11View == nullptr )
+ LOG_MISSING_BINDING("texture", tex->Name)
+
+ if( tex->SamplerBindPoint != InvalidBindPoint &&
+ (m_BoundSamplers.size() <= tex->SamplerBindPoint || m_BoundSamplers[tex->SamplerBindPoint].pd3d11Sampler == nullptr) )
+ LOG_MISSING_BINDING("sampler", tex->SamplerName)
+ }
+
+ for( auto buf = m_BuffSRVs.begin(); buf != m_BuffSRVs.end(); ++buf )
+ {
+ if( m_BoundSRVs.size() <= buf->BindPoint || m_BoundSRVs[buf->BindPoint].pd3d11View == nullptr )
+ LOG_MISSING_BINDING("buffer", buf->Name)
+ }
+
+ for( auto uav = m_TexUAVs.begin(); uav != m_TexUAVs.end(); ++uav )
+ {
+ if( m_BoundUAVs.size() <= uav->BindPoint || m_BoundUAVs[uav->BindPoint].pd3d11View == nullptr )
+ LOG_MISSING_BINDING("texture UAV", uav->Name)
+ }
+
+ for( auto uav = m_BuffUAVs.begin(); uav != m_BuffUAVs.end(); ++uav )
+ {
+ if( m_BoundUAVs.size() <= uav->BindPoint || m_BoundUAVs[uav->BindPoint].pd3d11View == nullptr )
+ LOG_MISSING_BINDING("buffer UAV", uav->Name)
+ }
+}
+#endif
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/src/SwapChainD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/SwapChainD3D11Impl.cpp
new file mode 100644
index 00000000..d2f639a6
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/src/SwapChainD3D11Impl.cpp
@@ -0,0 +1,254 @@
+/* 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.
+ */
+
+#include "pch.h"
+#include "SwapChainD3D11Impl.h"
+#include "RenderDeviceD3D11Impl.h"
+#include "DeviceContextD3D11Impl.h"
+
+using namespace Diligent;
+
+namespace Diligent
+{
+
+SwapChainD3D11Impl::SwapChainD3D11Impl(const SwapChainDesc& SCDesc,
+ RenderDeviceD3D11Impl* pRenderDeviceD3D11,
+ DeviceContextD3D11Impl* pDeviceContextD3D11,
+ void* pNativeWndHandle) :
+ TSwapChainBase(pRenderDeviceD3D11, pDeviceContextD3D11, SCDesc)
+{
+ auto *pDevice = pRenderDeviceD3D11->GetD3D11Device();
+
+ auto DXGIColorBuffFmt = TexFormatToDXGI_Format(m_SwapChainDesc.ColorBufferFormat);
+
+#if defined( PLATFORM_WINDOWS )
+
+ auto hWnd = reinterpret_cast<HWND>(pNativeWndHandle);
+
+ if( m_SwapChainDesc.Width == 0 || m_SwapChainDesc.Height == 0 )
+ {
+ RECT rc;
+ GetClientRect( hWnd, &rc );
+ m_SwapChainDesc.Width = rc.right - rc.left;
+ m_SwapChainDesc.Height = rc.bottom - rc.top;
+ }
+
+ // This sequence obtains the DXGI factory that was used to create the Direct3D device above.
+ CComPtr<IDXGIDevice> pDXGIDevice;
+ pDevice->QueryInterface(__uuidof(IDXGIDevice), reinterpret_cast<void**>( static_cast<IDXGIDevice**>(&pDXGIDevice) ) );
+ CComPtr<IDXGIAdapter> pDXGIAdapter;
+ pDXGIDevice->GetAdapter(&pDXGIAdapter);
+ CComPtr<IDXGIFactory> pDXGIFactory;
+ pDXGIAdapter->GetParent(__uuidof(pDXGIFactory), reinterpret_cast<void**>( static_cast<IDXGIFactory**>(&pDXGIFactory) ));
+
+ DXGI_SWAP_CHAIN_DESC sd;
+ ZeroMemory( &sd, sizeof( sd ) );
+ sd.BufferCount = 1;
+ sd.BufferDesc.Width = m_SwapChainDesc.Width;
+ sd.BufferDesc.Height = m_SwapChainDesc.Height;
+ sd.BufferDesc.Format = DXGIColorBuffFmt;
+ sd.BufferDesc.RefreshRate.Numerator = 0;
+ sd.BufferDesc.RefreshRate.Denominator = 0;
+ sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
+ sd.OutputWindow = hWnd;
+ sd.SampleDesc.Count = m_SwapChainDesc.SamplesCount;
+ sd.SampleDesc.Quality = 0;
+ sd.Windowed = TRUE;
+ sd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; // Set this flag to enable an application to switch
+ // modes by calling IDXGISwapChain::ResizeTarget. When switching from windowed to full-screen mode, the
+ // display mode (or monitor resolution) will be changed to match the dimensions of the application window.
+ CHECK_D3D_RESULT_THROW( pDXGIFactory->CreateSwapChain(pDevice, &sd, &m_pSwapChain),
+ "Failed to create DXGI swap chain" );
+
+#elif defined( PLATFORM_WINDOWS_STORE )
+
+ DXGI_SWAP_CHAIN_DESC1 swapChainDesc = { 0 };
+
+ swapChainDesc.Width = m_SwapChainDesc.Width;
+ swapChainDesc.Height = m_SwapChainDesc.Height;
+ swapChainDesc.Format = DXGIColorBuffFmt;
+ swapChainDesc.Stereo = false;
+ swapChainDesc.SampleDesc.Count = 1; // Don't use multi-sampling.
+ swapChainDesc.SampleDesc.Quality = 0;
+ swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
+ swapChainDesc.BufferCount = 2; // Use double-buffering to minimize latency.
+ swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; // All Windows Store apps must use this SwapEffect.
+ swapChainDesc.Flags = 0;
+ swapChainDesc.Scaling = DXGI_SCALING_NONE;
+ swapChainDesc.AlphaMode = DXGI_ALPHA_MODE_IGNORE;
+
+ CComPtr<IDXGIDevice3> pDXGIDevice;
+ pDevice->QueryInterface(__uuidof(IDXGIDevice3), reinterpret_cast<void**>(static_cast<IDXGIDevice3**>(&pDXGIDevice)));
+ CComPtr<IDXGIAdapter> pDXGIAdapter;
+ pDXGIDevice->GetAdapter(&pDXGIAdapter);
+ CComPtr<IDXGIFactory2> pDXGIFactory;
+ pDXGIAdapter->GetParent(__uuidof(pDXGIFactory), reinterpret_cast<void**>(static_cast<IDXGIFactory2**>(&pDXGIFactory)));
+
+ CComPtr<IDXGISwapChain1> pSwapChain1;
+ HRESULT hr = pDXGIFactory->CreateSwapChainForCoreWindow(
+ pDevice,
+ reinterpret_cast<IUnknown*>(pNativeWndHandle),
+ &swapChainDesc,
+ nullptr,
+ &pSwapChain1);
+ CHECK_D3D_RESULT_THROW( hr, "Failed to create DXGI swap chain" );
+
+ pSwapChain1->QueryInterface( __uuidof(m_pSwapChain), reinterpret_cast<void**>(static_cast<IDXGISwapChain**>(&m_pSwapChain)) );
+
+ // Ensure that DXGI does not queue more than one frame at a time. This both reduces latency and
+ // ensures that the application will only render after each VSync, minimizing power consumption.
+ pDXGIDevice->SetMaximumFrameLatency( 1 );
+
+#endif
+
+ CreateRTVandDSV();
+}
+
+SwapChainD3D11Impl::~SwapChainD3D11Impl()
+{
+
+}
+
+void SwapChainD3D11Impl::CreateRTVandDSV()
+{
+ auto *pDevice = ValidatedCast<RenderDeviceD3D11Impl>(m_pRenderDevice.RawPtr())->GetD3D11Device();
+
+ m_pRenderTargetView.Release();
+ m_pDepthStencilView.Release();
+
+ // Create a render target view
+ CComPtr<ID3D11Texture2D> pBackBuffer;
+ CHECK_D3D_RESULT_THROW( m_pSwapChain->GetBuffer( 0, __uuidof(ID3D11Texture2D), reinterpret_cast<void**>( static_cast<ID3D11Texture2D**>(&pBackBuffer) ) ),
+ "Failed to get back buffer from swap chain" );
+
+ CHECK_D3D_RESULT_THROW( pDevice->CreateRenderTargetView( pBackBuffer, NULL, &m_pRenderTargetView ),
+ "Failed to get RTV for the back buffer" );
+
+ // Create depth buffer
+ D3D11_TEXTURE2D_DESC DepthBufferDesc;
+ DepthBufferDesc.Width = m_SwapChainDesc.Width;
+ DepthBufferDesc.Height = m_SwapChainDesc.Height;
+ DepthBufferDesc.MipLevels = 1;
+ DepthBufferDesc.ArraySize = 1;
+ auto DepthFormat = TexFormatToDXGI_Format( m_SwapChainDesc.DepthBufferFormat );
+ DepthBufferDesc.Format = DepthFormat;
+ DepthBufferDesc.SampleDesc.Count = m_SwapChainDesc.SamplesCount;
+ DepthBufferDesc.SampleDesc.Quality = 0;
+ DepthBufferDesc.Usage = D3D11_USAGE_DEFAULT;
+ DepthBufferDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
+ DepthBufferDesc.CPUAccessFlags = 0;
+ DepthBufferDesc.MiscFlags = 0;
+ CComPtr<ID3D11Texture2D> ptex2DDepthBuffer;
+ CHECK_D3D_RESULT_THROW( pDevice->CreateTexture2D( &DepthBufferDesc, NULL, &ptex2DDepthBuffer ),
+ "Failed to create the depth buffer" );
+
+ // Create DSV
+ CHECK_D3D_RESULT_THROW( pDevice->CreateDepthStencilView( ptex2DDepthBuffer, NULL, &m_pDepthStencilView ),
+ "Failed to create the DSV for the depth buffer" );
+}
+
+IMPLEMENT_QUERY_INTERFACE( SwapChainD3D11Impl, IID_SwapChainD3D11, TSwapChainBase )
+
+void SwapChainD3D11Impl::Present()
+{
+ UINT SyncInterval = 0;
+#ifdef PLATFORM_WINDOWS_STORE
+ SyncInterval = 1; // Interval 0 is not supported on Windows Phone
+#endif
+
+ auto pDeviceContext = m_wpDeviceContext.Lock();
+ if( !pDeviceContext )
+ {
+ LOG_ERROR_MESSAGE( "Immediate context has been released" );
+ return;
+ }
+
+ auto *pImmediateCtx = pDeviceContext.RawPtr();
+ auto *pImmediateCtxD3D11 = ValidatedCast<DeviceContextD3D11Impl>( pImmediateCtx );
+ // Clear the state caches to release all outstanding objects
+ // that are only kept alive by references in the cache
+ // It is better to do this before calling Present() as D3D11
+ // also releases resources during present.
+ pImmediateCtxD3D11->ClearShaderStateCache();
+
+ m_pSwapChain->Present( SyncInterval, 0 );
+
+#ifdef PLATFORM_WINDOWS_STORE
+ // A successful Present call for DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL SwapChains unbinds
+ // backbuffer 0 from all GPU writeable bind points.
+ // We need to rebind all render targets to make sure that
+ // the back buffer is not unbound
+ pImmediateCtxD3D11->RebindRenderTargets();
+#endif
+}
+
+void SwapChainD3D11Impl::Resize( Uint32 NewWidth, Uint32 NewHeight )
+{
+ if( TSwapChainBase::Resize(NewWidth, NewHeight) )
+ {
+ auto pDeviceContext = m_wpDeviceContext.Lock();
+ VERIFY( pDeviceContext, "Immediate context has been released" );
+ if( pDeviceContext )
+ {
+ auto *pImmediateCtxD3D11 = ValidatedCast<DeviceContextD3D11Impl>(pDeviceContext.RawPtr());
+ bool bIsDefaultFBBound = pImmediateCtxD3D11->IsDefaultFBBound();
+ if( bIsDefaultFBBound )
+ {
+ ITextureView *pNullTexView[] = { nullptr };
+ pImmediateCtxD3D11->SetRenderTargets( _countof( pNullTexView ), pNullTexView, nullptr );
+ }
+
+ // Swap chain cannot be resized until all references are released
+ m_pRenderTargetView.Release();
+ m_pDepthStencilView.Release();
+
+ try
+ {
+ DXGI_SWAP_CHAIN_DESC SCDes;
+ memset( &SCDes, 0, sizeof( SCDes ) );
+ m_pSwapChain->GetDesc( &SCDes );
+ CHECK_D3D_RESULT_THROW( m_pSwapChain->ResizeBuffers(SCDes.BufferCount, m_SwapChainDesc.Width,
+ m_SwapChainDesc.Height, SCDes.BufferDesc.Format,
+ SCDes.Flags),
+ "Failed to resize the DXGI swap chain" );
+
+
+ CreateRTVandDSV();
+
+ if( bIsDefaultFBBound )
+ {
+ // Set default render target and viewport
+ pImmediateCtxD3D11->SetRenderTargets( 0, nullptr, nullptr );
+ pImmediateCtxD3D11->SetViewports( 1, nullptr, 0, 0 );
+ }
+ }
+ catch( const std::runtime_error & )
+ {
+ LOG_ERROR( "Failed to resize the swap chain" );
+ }
+ }
+ }
+}
+
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/src/Texture1D_D3D11.cpp b/Graphics/GraphicsEngineD3D11/src/Texture1D_D3D11.cpp
new file mode 100644
index 00000000..75eaab86
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/src/Texture1D_D3D11.cpp
@@ -0,0 +1,226 @@
+/* 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.
+ */
+
+#include "pch.h"
+#include "Texture1D_D3D11.h"
+#include "RenderDeviceD3D11Impl.h"
+#include "D3D11TypeConversions.h"
+
+namespace Diligent
+{
+
+Texture1D_D3D11 :: Texture1D_D3D11(RenderDeviceD3D11Impl *pRenderDeviceD3D11, const TextureDesc& TexDesc, const TextureData &InitData /*= TextureData()*/) :
+ TextureBaseD3D11(pRenderDeviceD3D11, TexDesc, InitData)
+{
+ auto D3D11TexFormat = TexFormatToDXGI_Format(m_Desc.Format, m_Desc.BindFlags);
+ auto D3D11BindFlags = BindFlagsToD3D11BindFlags(m_Desc.BindFlags);
+ auto D3D11CPUAccessFlags = CPUAccessFlagsToD3D11CPUAccessFlags(m_Desc.CPUAccessFlags);
+ auto D3D11Usage = UsageToD3D11Usage(m_Desc.Usage);
+ UINT MiscFlags = MiscTextureFlagsToD3D11Flags(m_Desc.MiscFlags);
+ auto *pDeviceD3D11 = pRenderDeviceD3D11->GetD3D11Device();
+
+ D3D11_TEXTURE1D_DESC Tex1DDesc =
+ {
+ m_Desc.Width,
+ m_Desc.MipLevels,
+ m_Desc.ArraySize,
+ D3D11TexFormat,
+ D3D11Usage,
+ D3D11BindFlags,
+ D3D11CPUAccessFlags,
+ MiscFlags
+ };
+
+ std::vector<D3D11_SUBRESOURCE_DATA> D3D11InitData;
+ PrepareD3D11InitData(InitData, Tex1DDesc.ArraySize * Tex1DDesc.MipLevels, D3D11InitData);
+
+ ID3D11Texture1D *ptex1D = nullptr;
+ HRESULT hr = pDeviceD3D11->CreateTexture1D(&Tex1DDesc, D3D11InitData.size() ? D3D11InitData.data() : nullptr, &ptex1D);
+ m_pd3d11Texture.Attach(ptex1D);
+ CHECK_D3D_RESULT_THROW( hr, "Failed to create the Direct3D11 Texture1D" );
+}
+
+Texture1D_D3D11 :: ~Texture1D_D3D11()
+{
+}
+
+void Texture1D_D3D11::CreateSRV( TextureViewDesc &SRVDesc, ID3D11ShaderResourceView **ppD3D11SRV )
+{
+ VERIFY( ppD3D11SRV && *ppD3D11SRV == nullptr, "SRV pointer address is null or contains non-null pointer to an existing object" );
+
+ VERIFY( SRVDesc.ViewType == TEXTURE_VIEW_SHADER_RESOURCE, "Incorrect view type: shader resource is expected" );
+ if( !(SRVDesc.TextureType == TEXTURE_TYPE_1D || SRVDesc.TextureType == TEXTURE_TYPE_1D_ARRAY) )
+ LOG_ERROR_AND_THROW( "Unsupported texture type. Only TEXTURE_TYPE_1D or TEXTURE_TYPE_1D_ARRAY is allowed" );
+
+ if( SRVDesc.Format == TEX_FORMAT_UNKNOWN )
+ {
+ SRVDesc.Format = m_Desc.Format;
+ }
+
+ D3D11_SHADER_RESOURCE_VIEW_DESC D3D11_SRVDesc;
+ memset(&D3D11_SRVDesc, 0, sizeof(D3D11_SRVDesc));
+ D3D11_SRVDesc.Format = TexFormatToDXGI_Format(SRVDesc.Format, BIND_SHADER_RESOURCE);
+
+ if( SRVDesc.TextureType == TEXTURE_TYPE_1D )
+ {
+ D3D11_SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1D;
+ D3D11_SRVDesc.Texture1D.MipLevels = SRVDesc.NumMipLevels;
+ D3D11_SRVDesc.Texture1D.MostDetailedMip = SRVDesc.MostDetailedMip;
+ }
+ else if( SRVDesc.TextureType == TEXTURE_TYPE_1D_ARRAY )
+ {
+ D3D11_SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1DARRAY;
+ D3D11_SRVDesc.Texture1DArray.ArraySize = SRVDesc.NumArraySlices;
+ D3D11_SRVDesc.Texture1DArray.FirstArraySlice = SRVDesc.FirstArraySlice;
+ D3D11_SRVDesc.Texture1DArray.MipLevels = SRVDesc.NumMipLevels;
+ D3D11_SRVDesc.Texture1DArray.MostDetailedMip = SRVDesc.MostDetailedMip;
+ }
+ else
+ {
+ UNEXPECTED( "Unexpected view type" );
+ }
+
+ auto *pDeviceD3D11 = static_cast<RenderDeviceD3D11Impl*>(GetDevice())->GetD3D11Device();
+ CHECK_D3D_RESULT_THROW( pDeviceD3D11->CreateShaderResourceView( m_pd3d11Texture, &D3D11_SRVDesc, ppD3D11SRV ),
+ "Failed to create D3D11 shader resource view");
+}
+
+void Texture1D_D3D11::CreateRTV( TextureViewDesc &RTVDesc, ID3D11RenderTargetView **ppD3D11RTV )
+{
+ VERIFY( ppD3D11RTV && *ppD3D11RTV == nullptr, "RTV pointer address is null or contains non-null pointer to an existing object" );
+
+ VERIFY( RTVDesc.ViewType == TEXTURE_VIEW_RENDER_TARGET, "Incorrect view type: render target is expected" );
+ if( !(RTVDesc.TextureType == TEXTURE_TYPE_1D || RTVDesc.TextureType == TEXTURE_TYPE_1D_ARRAY ) )
+ LOG_ERROR_AND_THROW( "Unsupported texture type. Only TEXTURE_TYPE_1D or TEXTURE_TYPE_1D_ARRAY is allowed" );
+
+ if( RTVDesc.Format == TEX_FORMAT_UNKNOWN )
+ {
+ RTVDesc.Format = m_Desc.Format;
+ }
+
+ D3D11_RENDER_TARGET_VIEW_DESC D3D11_RTVDesc;
+ memset(&D3D11_RTVDesc, 0, sizeof(D3D11_RTVDesc));
+ D3D11_RTVDesc.Format = TexFormatToDXGI_Format(RTVDesc.Format, BIND_RENDER_TARGET);
+
+ if( RTVDesc.TextureType == TEXTURE_TYPE_1D )
+ {
+ D3D11_RTVDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE1D;
+ D3D11_RTVDesc.Texture1D.MipSlice = RTVDesc.MostDetailedMip;
+ }
+ else if( RTVDesc.TextureType == TEXTURE_TYPE_1D_ARRAY )
+ {
+ D3D11_RTVDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE1DARRAY;
+ D3D11_RTVDesc.Texture1DArray.ArraySize = RTVDesc.NumArraySlices;
+ D3D11_RTVDesc.Texture1DArray.FirstArraySlice = RTVDesc.FirstArraySlice;
+ D3D11_RTVDesc.Texture1DArray.MipSlice = RTVDesc.MostDetailedMip;
+ }
+ else
+ {
+ UNEXPECTED( "Unexpected view type" );
+ }
+
+ auto *pDeviceD3D11 = static_cast<RenderDeviceD3D11Impl*>(GetDevice())->GetD3D11Device();
+ CHECK_D3D_RESULT_THROW( pDeviceD3D11->CreateRenderTargetView( m_pd3d11Texture, &D3D11_RTVDesc, ppD3D11RTV ),
+ "Failed to create D3D11 render target view");
+}
+
+void Texture1D_D3D11::CreateDSV( TextureViewDesc &DSVDesc, ID3D11DepthStencilView **ppD3D11DSV )
+{
+ VERIFY( ppD3D11DSV && *ppD3D11DSV == nullptr, "DSV pointer address is null or contains non-null pointer to an existing object" );
+
+ VERIFY( DSVDesc.ViewType == TEXTURE_VIEW_DEPTH_STENCIL, "Incorrect view type: depth stencil is expected" );
+ if( !(DSVDesc.TextureType == TEXTURE_TYPE_1D || DSVDesc.TextureType == TEXTURE_TYPE_1D_ARRAY) )
+ LOG_ERROR_AND_THROW("Unsupported texture type. Only TEXTURE_TYPE_1D or TEXTURE_TYPE_1D_ARRAY is allowed");
+
+ if( DSVDesc.Format == TEX_FORMAT_UNKNOWN )
+ {
+ DSVDesc.Format = m_Desc.Format;
+ }
+
+ D3D11_DEPTH_STENCIL_VIEW_DESC D3D11_DSVDesc;
+ memset(&D3D11_DSVDesc, 0, sizeof(D3D11_DSVDesc));
+ D3D11_DSVDesc.Format = TexFormatToDXGI_Format(DSVDesc.Format, BIND_DEPTH_STENCIL);
+
+ if( DSVDesc.TextureType == TEXTURE_TYPE_1D )
+ {
+ D3D11_DSVDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE1D;
+ D3D11_DSVDesc.Texture1D.MipSlice = DSVDesc.MostDetailedMip;
+ }
+ else if( DSVDesc.TextureType == TEXTURE_TYPE_1D_ARRAY )
+ {
+ D3D11_DSVDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE1DARRAY;
+ D3D11_DSVDesc.Texture1DArray.ArraySize = DSVDesc.NumArraySlices;
+ D3D11_DSVDesc.Texture1DArray.FirstArraySlice = DSVDesc.FirstArraySlice;
+ D3D11_DSVDesc.Texture1DArray.MipSlice = DSVDesc.MostDetailedMip;
+ }
+ else
+ {
+ UNEXPECTED( "Unexpected view type" );
+ }
+
+ auto *pDeviceD3D11 = static_cast<RenderDeviceD3D11Impl*>(GetDevice())->GetD3D11Device();
+ CHECK_D3D_RESULT_THROW( pDeviceD3D11->CreateDepthStencilView( m_pd3d11Texture, &D3D11_DSVDesc, ppD3D11DSV ),
+ "Failed to create D3D11 depth stencil view");
+}
+
+void Texture1D_D3D11::CreateUAV( TextureViewDesc &UAVDesc, ID3D11UnorderedAccessView **ppD3D11UAV )
+{
+ VERIFY( ppD3D11UAV && *ppD3D11UAV == nullptr, "UAV pointer address is null or contains non-null pointer to an existing object" );
+
+ VERIFY( UAVDesc.ViewType == TEXTURE_VIEW_UNORDERED_ACCESS, "Incorrect view type: unordered access is expected" );
+ if( !(UAVDesc.TextureType == TEXTURE_TYPE_1D || UAVDesc.TextureType == TEXTURE_TYPE_1D_ARRAY) )
+ LOG_ERROR_AND_THROW("Unsupported texture type. Only TEXTURE_TYPE_1D or TEXTURE_TYPE_1D_ARRAY is allowed");
+
+ if( UAVDesc.Format == TEX_FORMAT_UNKNOWN )
+ {
+ UAVDesc.Format = m_Desc.Format;
+ }
+
+ D3D11_UNORDERED_ACCESS_VIEW_DESC D3D11_UAVDesc;
+ memset(&D3D11_UAVDesc, 0, sizeof(D3D11_UAVDesc));
+ D3D11_UAVDesc.Format = TexFormatToDXGI_Format(UAVDesc.Format, BIND_UNORDERED_ACCESS);
+
+ if( UAVDesc.TextureType == TEXTURE_TYPE_1D )
+ {
+ D3D11_UAVDesc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE1D;
+ D3D11_UAVDesc.Texture1D.MipSlice = UAVDesc.MostDetailedMip;
+ }
+ else if( UAVDesc.TextureType == TEXTURE_TYPE_1D_ARRAY )
+ {
+ D3D11_UAVDesc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE1DARRAY;
+ D3D11_UAVDesc.Texture1DArray.ArraySize = UAVDesc.NumArraySlices;
+ D3D11_UAVDesc.Texture1DArray.FirstArraySlice = UAVDesc.FirstArraySlice;
+ D3D11_UAVDesc.Texture1DArray.MipSlice = UAVDesc.MostDetailedMip;
+ }
+ else
+ {
+ UNEXPECTED( "Unexpected view type" );
+ }
+
+
+ auto *pDeviceD3D11 = static_cast<RenderDeviceD3D11Impl*>(GetDevice())->GetD3D11Device();
+ CHECK_D3D_RESULT_THROW( pDeviceD3D11->CreateUnorderedAccessView( m_pd3d11Texture, &D3D11_UAVDesc, ppD3D11UAV ),
+ "Failed to create D3D11 unordered access view");
+}
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/src/Texture2D_D3D11.cpp b/Graphics/GraphicsEngineD3D11/src/Texture2D_D3D11.cpp
new file mode 100644
index 00000000..fc34d18d
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/src/Texture2D_D3D11.cpp
@@ -0,0 +1,284 @@
+/* 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.
+ */
+
+#include "pch.h"
+#include "Texture2D_D3D11.h"
+#include "RenderDeviceD3D11Impl.h"
+#include "D3D11TypeConversions.h"
+
+namespace Diligent
+{
+
+Texture2D_D3D11 :: Texture2D_D3D11(RenderDeviceD3D11Impl *pRenderDeviceD3D11, const TextureDesc& TexDesc, const TextureData &InitData /*= TextureData()*/) :
+ TextureBaseD3D11(pRenderDeviceD3D11, TexDesc, InitData)
+{
+ auto D3D11TexFormat = TexFormatToDXGI_Format(m_Desc.Format, m_Desc.BindFlags);
+ auto D3D11BindFlags = BindFlagsToD3D11BindFlags(m_Desc.BindFlags);
+ auto D3D11CPUAccessFlags = CPUAccessFlagsToD3D11CPUAccessFlags(m_Desc.CPUAccessFlags);
+ auto D3D11Usage = UsageToD3D11Usage(m_Desc.Usage);
+ UINT MiscFlags = MiscTextureFlagsToD3D11Flags(m_Desc.MiscFlags);
+ DXGI_SAMPLE_DESC D3D11SampleDesc = {m_Desc.SampleCount, 0};
+ auto *pDeviceD3D11 = pRenderDeviceD3D11->GetD3D11Device();
+
+ D3D11_TEXTURE2D_DESC Tex2DDesc =
+ {
+ m_Desc.Width,
+ m_Desc.Height,
+ m_Desc.MipLevels,
+ m_Desc.ArraySize,
+ D3D11TexFormat,
+ D3D11SampleDesc,
+ D3D11Usage,
+ D3D11BindFlags,
+ D3D11CPUAccessFlags,
+ MiscFlags
+ };
+
+ std::vector<D3D11_SUBRESOURCE_DATA> D3D11InitData;
+ PrepareD3D11InitData(InitData, Tex2DDesc.ArraySize * Tex2DDesc.MipLevels, D3D11InitData);
+
+ ID3D11Texture2D *ptex2D = nullptr;
+ HRESULT hr = pDeviceD3D11->CreateTexture2D(&Tex2DDesc, D3D11InitData.size() ? D3D11InitData.data() : nullptr, &ptex2D);
+ m_pd3d11Texture.Attach(ptex2D);
+ CHECK_D3D_RESULT_THROW( hr, "Failed to create the Direct3D11 Texture2D" );
+}
+
+Texture2D_D3D11 :: ~Texture2D_D3D11()
+{
+}
+
+void Texture2D_D3D11::CreateSRV( TextureViewDesc &SRVDesc, ID3D11ShaderResourceView **ppD3D11SRV )
+{
+ VERIFY( ppD3D11SRV && *ppD3D11SRV == nullptr, "SRV pointer address is null or contains non-null pointer to an existing object" );
+
+ VERIFY( SRVDesc.ViewType == TEXTURE_VIEW_SHADER_RESOURCE, "Incorrect view type: shader resource is expected" );
+ if( !(SRVDesc.TextureType == TEXTURE_TYPE_2D || SRVDesc.TextureType == TEXTURE_TYPE_2D_ARRAY) )
+ LOG_ERROR_AND_THROW("Unsupported texture type. Only TEXTURE_TYPE_2D or TEXTURE_TYPE_2D_ARRAY is allowed");
+
+ if( SRVDesc.Format == TEX_FORMAT_UNKNOWN )
+ {
+ SRVDesc.Format = m_Desc.Format;
+ }
+
+ D3D11_SHADER_RESOURCE_VIEW_DESC D3D11_SRVDesc;
+ memset(&D3D11_SRVDesc, 0, sizeof(D3D11_SRVDesc));
+ D3D11_SRVDesc.Format = TexFormatToDXGI_Format(SRVDesc.Format, BIND_SHADER_RESOURCE);
+
+
+ if( SRVDesc.TextureType == TEXTURE_TYPE_2D )
+ {
+ if( m_Desc.SampleCount > 1 )
+ {
+ D3D11_SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DMS;
+ D3D11_SRVDesc.Texture2DMS.UnusedField_NothingToDefine = 0;
+ }
+ else
+ {
+ D3D11_SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
+ D3D11_SRVDesc.Texture2D.MipLevels = SRVDesc.NumMipLevels;
+ D3D11_SRVDesc.Texture2D.MostDetailedMip = SRVDesc.MostDetailedMip;
+ }
+ }
+ else if( SRVDesc.TextureType == TEXTURE_TYPE_2D_ARRAY )
+ {
+ if( m_Desc.SampleCount > 1 )
+ {
+ D3D11_SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY;
+ D3D11_SRVDesc.Texture2DMSArray.ArraySize = SRVDesc.NumArraySlices;
+ D3D11_SRVDesc.Texture2DMSArray.FirstArraySlice = SRVDesc.FirstArraySlice;
+ }
+ else
+ {
+ D3D11_SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY;
+ D3D11_SRVDesc.Texture2DArray.ArraySize = SRVDesc.NumArraySlices;
+ D3D11_SRVDesc.Texture2DArray.FirstArraySlice = SRVDesc.FirstArraySlice;
+ D3D11_SRVDesc.Texture2DArray.MipLevels = SRVDesc.NumMipLevels;
+ D3D11_SRVDesc.Texture2DArray.MostDetailedMip = SRVDesc.MostDetailedMip;
+ }
+ }
+ else
+ {
+ UNEXPECTED( "Unexpected view type" );
+ }
+
+ auto *pDeviceD3D11 = static_cast<RenderDeviceD3D11Impl*>(GetDevice())->GetD3D11Device();
+ CHECK_D3D_RESULT_THROW( pDeviceD3D11->CreateShaderResourceView( m_pd3d11Texture, &D3D11_SRVDesc, ppD3D11SRV ),
+ "Failed to create D3D11 shader resource view");
+}
+
+void Texture2D_D3D11::CreateRTV( TextureViewDesc &RTVDesc, ID3D11RenderTargetView **ppD3D11RTV )
+{
+ VERIFY( ppD3D11RTV && *ppD3D11RTV == nullptr, "RTV pointer address is null or contains non-null pointer to an existing object" );
+
+ VERIFY( RTVDesc.ViewType == TEXTURE_VIEW_RENDER_TARGET, "Incorrect view type: render target is expected" );
+ if( !(RTVDesc.TextureType == TEXTURE_TYPE_2D || RTVDesc.TextureType == TEXTURE_TYPE_2D_ARRAY) )
+ LOG_ERROR_AND_THROW( "Unsupported texture type. Only TEXTURE_TYPE_2D or TEXTURE_TYPE_2D_ARRAY is allowed" );
+
+ if( RTVDesc.Format == TEX_FORMAT_UNKNOWN )
+ {
+ RTVDesc.Format = m_Desc.Format;
+ }
+
+ D3D11_RENDER_TARGET_VIEW_DESC D3D11_RTVDesc;
+ memset(&D3D11_RTVDesc, 0, sizeof(D3D11_RTVDesc));
+ D3D11_RTVDesc.Format = TexFormatToDXGI_Format(RTVDesc.Format, BIND_RENDER_TARGET);
+
+ if( RTVDesc.TextureType == TEXTURE_TYPE_2D )
+ {
+ if( m_Desc.SampleCount > 1 )
+ {
+ D3D11_RTVDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMS;
+ D3D11_RTVDesc.Texture2DMS.UnusedField_NothingToDefine = 0;
+ }
+ else
+ {
+ D3D11_RTVDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
+ D3D11_RTVDesc.Texture2D.MipSlice = RTVDesc.MostDetailedMip;
+ }
+ }
+ else if( RTVDesc.TextureType == TEXTURE_TYPE_2D_ARRAY )
+ {
+ if( m_Desc.SampleCount > 1 )
+ {
+ D3D11_RTVDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY;
+ D3D11_RTVDesc.Texture2DMSArray.ArraySize = RTVDesc.NumArraySlices;
+ D3D11_RTVDesc.Texture2DMSArray.FirstArraySlice = RTVDesc.FirstArraySlice;
+ }
+ else
+ {
+ D3D11_RTVDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
+ D3D11_RTVDesc.Texture2DArray.ArraySize = RTVDesc.NumArraySlices;
+ D3D11_RTVDesc.Texture2DArray.FirstArraySlice = RTVDesc.FirstArraySlice;
+ D3D11_RTVDesc.Texture2DArray.MipSlice = RTVDesc.MostDetailedMip;
+ }
+ }
+ else
+ {
+ UNEXPECTED( "Unexpected view type" );
+ }
+
+
+ auto *pDeviceD3D11 = static_cast<RenderDeviceD3D11Impl*>(GetDevice())->GetD3D11Device();
+ CHECK_D3D_RESULT_THROW( pDeviceD3D11->CreateRenderTargetView( m_pd3d11Texture, &D3D11_RTVDesc, ppD3D11RTV ),
+ "Failed to create D3D11 render target view");
+}
+
+void Texture2D_D3D11::CreateDSV( TextureViewDesc &DSVDesc, ID3D11DepthStencilView **ppD3D11DSV )
+{
+ VERIFY( ppD3D11DSV && *ppD3D11DSV == nullptr, "DSV pointer address is null or contains non-null pointer to an existing object" );
+
+ VERIFY( DSVDesc.ViewType == TEXTURE_VIEW_DEPTH_STENCIL, "Incorrect view type: depth stencil is expected" );
+ if( !(DSVDesc.TextureType == TEXTURE_TYPE_2D || DSVDesc.TextureType == TEXTURE_TYPE_2D_ARRAY) )
+ LOG_ERROR_AND_THROW("Unsupported texture type. Only TEXTURE_TYPE_2D or TEXTURE_TYPE_2D_ARRAY is allowed");
+
+ if( DSVDesc.Format == TEX_FORMAT_UNKNOWN )
+ {
+ DSVDesc.Format = m_Desc.Format;
+ }
+
+ D3D11_DEPTH_STENCIL_VIEW_DESC D3D11_DSVDesc;
+ memset(&D3D11_DSVDesc, 0, sizeof(D3D11_DSVDesc));
+ D3D11_DSVDesc.Format = TexFormatToDXGI_Format(DSVDesc.Format, BIND_DEPTH_STENCIL);
+
+ if( DSVDesc.TextureType == TEXTURE_TYPE_2D )
+ {
+ if( m_Desc.SampleCount > 1 )
+ {
+ D3D11_DSVDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMS;
+ D3D11_DSVDesc.Texture2DMS.UnusedField_NothingToDefine = 0;
+ }
+ else
+ {
+ D3D11_DSVDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
+ D3D11_DSVDesc.Texture2D.MipSlice = DSVDesc.MostDetailedMip;
+ }
+ }
+ else if( DSVDesc.TextureType == TEXTURE_TYPE_2D_ARRAY )
+ {
+ if( m_Desc.SampleCount > 1 )
+ {
+ D3D11_DSVDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY;
+ D3D11_DSVDesc.Texture2DMSArray.ArraySize = DSVDesc.NumArraySlices;
+ D3D11_DSVDesc.Texture2DMSArray.FirstArraySlice = DSVDesc.FirstArraySlice;
+ }
+ else
+ {
+ D3D11_DSVDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY;
+ D3D11_DSVDesc.Texture2DArray.ArraySize = DSVDesc.NumArraySlices;
+ D3D11_DSVDesc.Texture2DArray.FirstArraySlice = DSVDesc.FirstArraySlice;
+ D3D11_DSVDesc.Texture2DArray.MipSlice = DSVDesc.MostDetailedMip;
+ }
+ }
+ else
+ {
+ UNEXPECTED( "Unexpected view type" );
+ }
+
+ auto *pDeviceD3D11 = static_cast<RenderDeviceD3D11Impl*>(GetDevice())->GetD3D11Device();
+ CHECK_D3D_RESULT_THROW( pDeviceD3D11->CreateDepthStencilView( m_pd3d11Texture, &D3D11_DSVDesc, ppD3D11DSV ),
+ "Failed to create D3D11 depth stencil view");
+}
+
+void Texture2D_D3D11::CreateUAV( TextureViewDesc &UAVDesc, ID3D11UnorderedAccessView **ppD3D11UAV )
+{
+ VERIFY( ppD3D11UAV && *ppD3D11UAV == nullptr, "UAV pointer address is null or contains non-null pointer to an existing object" );
+
+ if( m_Desc.SampleCount > 1 )
+ LOG_ERROR_AND_THROW("UAVs are not allowed for multisampled resources");
+
+ VERIFY( UAVDesc.ViewType == TEXTURE_VIEW_UNORDERED_ACCESS, "Incorrect view type: unordered access is expected" );
+ if( !(UAVDesc.TextureType == TEXTURE_TYPE_2D || UAVDesc.TextureType == TEXTURE_TYPE_2D_ARRAY) )
+ LOG_ERROR_AND_THROW( "Unsupported texture type. Only TEXTURE_TYPE_2D or TEXTURE_TYPE_2D_ARRAY is allowed" );
+
+ if( UAVDesc.Format == TEX_FORMAT_UNKNOWN )
+ {
+ UAVDesc.Format = m_Desc.Format;
+ }
+
+ D3D11_UNORDERED_ACCESS_VIEW_DESC D3D11_UAVDesc;
+ memset(&D3D11_UAVDesc, 0, sizeof(D3D11_UAVDesc));
+ D3D11_UAVDesc.Format = TexFormatToDXGI_Format(UAVDesc.Format, BIND_UNORDERED_ACCESS);
+
+ if( UAVDesc.TextureType == TEXTURE_TYPE_2D )
+ {
+ D3D11_UAVDesc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
+ D3D11_UAVDesc.Texture2D.MipSlice = UAVDesc.MostDetailedMip;
+ }
+ else if( UAVDesc.TextureType == TEXTURE_TYPE_2D_ARRAY )
+ {
+ D3D11_UAVDesc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2DARRAY;
+ D3D11_UAVDesc.Texture2DArray.ArraySize = UAVDesc.NumArraySlices;
+ D3D11_UAVDesc.Texture2DArray.FirstArraySlice = UAVDesc.FirstArraySlice;
+ D3D11_UAVDesc.Texture2DArray.MipSlice = UAVDesc.MostDetailedMip;
+ }
+ else
+ {
+ UNEXPECTED( "Unexpected view type" );
+ }
+
+ auto *pDeviceD3D11 = static_cast<RenderDeviceD3D11Impl*>(GetDevice())->GetD3D11Device();
+ CHECK_D3D_RESULT_THROW( pDeviceD3D11->CreateUnorderedAccessView( m_pd3d11Texture, &D3D11_UAVDesc, ppD3D11UAV ),
+ "Failed to create D3D11 unordered access view");
+}
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/src/Texture3D_D3D11.cpp b/Graphics/GraphicsEngineD3D11/src/Texture3D_D3D11.cpp
new file mode 100644
index 00000000..9546660e
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/src/Texture3D_D3D11.cpp
@@ -0,0 +1,154 @@
+/* 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.
+ */
+
+#include "pch.h"
+#include "Texture3D_D3D11.h"
+#include "RenderDeviceD3D11Impl.h"
+#include "D3D11TypeConversions.h"
+
+namespace Diligent
+{
+
+Texture3D_D3D11 :: Texture3D_D3D11(RenderDeviceD3D11Impl *pRenderDeviceD3D11, const TextureDesc& TexDesc, const TextureData &InitData /*= TextureData()*/) :
+ TextureBaseD3D11(pRenderDeviceD3D11, TexDesc, InitData)
+{
+ auto D3D11TexFormat = TexFormatToDXGI_Format(m_Desc.Format, m_Desc.BindFlags);
+ auto D3D11BindFlags = BindFlagsToD3D11BindFlags(m_Desc.BindFlags);
+ auto D3D11CPUAccessFlags = CPUAccessFlagsToD3D11CPUAccessFlags(m_Desc.CPUAccessFlags);
+ auto D3D11Usage = UsageToD3D11Usage(m_Desc.Usage);
+ UINT MiscFlags = MiscTextureFlagsToD3D11Flags(m_Desc.MiscFlags);
+ auto *pDeviceD3D11 = pRenderDeviceD3D11->GetD3D11Device();
+
+ D3D11_TEXTURE3D_DESC Tex3DDesc =
+ {
+ m_Desc.Width,
+ m_Desc.Height,
+ m_Desc.Depth,
+ m_Desc.MipLevels,
+ D3D11TexFormat,
+ D3D11Usage,
+ D3D11BindFlags,
+ D3D11CPUAccessFlags,
+ MiscFlags
+ };
+
+ std::vector<D3D11_SUBRESOURCE_DATA> D3D11InitData;
+ PrepareD3D11InitData(InitData, Tex3DDesc.MipLevels, D3D11InitData);
+
+ ID3D11Texture3D *ptex3D = nullptr;
+ HRESULT hr = pDeviceD3D11->CreateTexture3D(&Tex3DDesc, D3D11InitData.size() ? D3D11InitData.data() : nullptr, &ptex3D);
+ m_pd3d11Texture.Attach(ptex3D);
+ CHECK_D3D_RESULT_THROW( hr, "Failed to create the Direct3D11 Texture3D" );
+}
+
+void Texture3D_D3D11::CreateSRV( TextureViewDesc &SRVDesc, ID3D11ShaderResourceView **ppD3D11SRV )
+{
+ VERIFY( ppD3D11SRV && *ppD3D11SRV == nullptr, "SRV pointer address is null or contains non-null pointer to an existing object" );
+
+ VERIFY( SRVDesc.ViewType == TEXTURE_VIEW_SHADER_RESOURCE, "Incorrect view type: shader resource is expected" );
+ if( SRVDesc.TextureType != TEXTURE_TYPE_3D )
+ LOG_ERROR_AND_THROW("Unsupported texture view type. Only TEXTURE_TYPE_3D is allowed");
+
+ if( SRVDesc.Format == TEX_FORMAT_UNKNOWN )
+ {
+ SRVDesc.Format = m_Desc.Format;
+ }
+
+ D3D11_SHADER_RESOURCE_VIEW_DESC D3D11_SRVDesc;
+ memset(&D3D11_SRVDesc, 0, sizeof(D3D11_SRVDesc));
+ D3D11_SRVDesc.Format = TexFormatToDXGI_Format(SRVDesc.Format, BIND_SHADER_RESOURCE);
+
+ D3D11_SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D;
+ D3D11_SRVDesc.Texture3D.MipLevels = SRVDesc.NumMipLevels;
+ D3D11_SRVDesc.Texture3D.MostDetailedMip = SRVDesc.MostDetailedMip;
+
+ auto *pDeviceD3D11 = static_cast<RenderDeviceD3D11Impl*>(GetDevice())->GetD3D11Device();
+ CHECK_D3D_RESULT_THROW( pDeviceD3D11->CreateShaderResourceView( m_pd3d11Texture, &D3D11_SRVDesc, ppD3D11SRV ),
+ "Failed to create D3D11 shader resource view");
+}
+
+void Texture3D_D3D11::CreateRTV( TextureViewDesc &RTVDesc, ID3D11RenderTargetView **ppD3D11RTV )
+{
+ VERIFY( ppD3D11RTV && *ppD3D11RTV == nullptr, "RTV pointer address is null or contains non-null pointer to an existing object" );
+
+ VERIFY( RTVDesc.ViewType == TEXTURE_VIEW_RENDER_TARGET, "Incorrect view type: render target is expected" );
+ if( RTVDesc.TextureType != TEXTURE_TYPE_3D )
+ LOG_ERROR_AND_THROW( "Unsupported texture view type. Only TEXTURE_TYPE_3D is allowed" );
+
+ if( RTVDesc.Format == TEX_FORMAT_UNKNOWN )
+ {
+ RTVDesc.Format = m_Desc.Format;
+ }
+
+ D3D11_RENDER_TARGET_VIEW_DESC D3D11_RTVDesc;
+ memset(&D3D11_RTVDesc, 0, sizeof(D3D11_RTVDesc));
+ D3D11_RTVDesc.Format = TexFormatToDXGI_Format(RTVDesc.Format, BIND_RENDER_TARGET);
+
+ D3D11_RTVDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE3D;
+ D3D11_RTVDesc.Texture3D.FirstWSlice = RTVDesc.FirstDepthSlice;
+ D3D11_RTVDesc.Texture3D.WSize = RTVDesc.NumDepthSlices;
+ D3D11_RTVDesc.Texture3D.MipSlice = RTVDesc.MostDetailedMip;
+
+ auto *pDeviceD3D11 = static_cast<RenderDeviceD3D11Impl*>(GetDevice())->GetD3D11Device();
+ CHECK_D3D_RESULT_THROW( pDeviceD3D11->CreateRenderTargetView( m_pd3d11Texture, &D3D11_RTVDesc, ppD3D11RTV ),
+ "Failed to create D3D11 render target view");
+}
+
+void Texture3D_D3D11::CreateDSV( TextureViewDesc &pDSVDesc, ID3D11DepthStencilView **ppD3D11DSV )
+{
+ LOG_ERROR_AND_THROW("Depth stencil views are not supported for 3D textures");
+}
+
+void Texture3D_D3D11::CreateUAV( TextureViewDesc &UAVDesc, ID3D11UnorderedAccessView **ppD3D11UAV )
+{
+ VERIFY( ppD3D11UAV && *ppD3D11UAV == nullptr, "UAV pointer address is null or contains non-null pointer to an existing object" );
+
+ VERIFY( UAVDesc.ViewType == TEXTURE_VIEW_UNORDERED_ACCESS, "Incorrect view type: unordered access is expected" );
+ if( UAVDesc.TextureType != TEXTURE_TYPE_3D )
+ LOG_ERROR_AND_THROW("Unsupported texture view type. Only TEXTURE_TYPE_3D is allowed");
+
+ if( UAVDesc.Format == TEX_FORMAT_UNKNOWN )
+ {
+ UAVDesc.Format = m_Desc.Format;
+ }
+
+ D3D11_UNORDERED_ACCESS_VIEW_DESC D3D11_UAVDesc;
+ memset(&D3D11_UAVDesc, 0, sizeof(D3D11_UAVDesc));
+ D3D11_UAVDesc.Format = TexFormatToDXGI_Format(UAVDesc.Format, BIND_UNORDERED_ACCESS);
+
+ D3D11_UAVDesc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE3D;
+ D3D11_UAVDesc.Texture3D.FirstWSlice = UAVDesc.FirstDepthSlice;
+ D3D11_UAVDesc.Texture3D.WSize = UAVDesc.NumDepthSlices;
+ D3D11_UAVDesc.Texture3D.MipSlice = UAVDesc.MostDetailedMip;
+
+ auto *pDeviceD3D11 = static_cast<RenderDeviceD3D11Impl*>(GetDevice())->GetD3D11Device();
+ CHECK_D3D_RESULT_THROW( pDeviceD3D11->CreateUnorderedAccessView( m_pd3d11Texture, &D3D11_UAVDesc, ppD3D11UAV ),
+ "Failed to create D3D11 unordered access view");
+}
+
+
+Texture3D_D3D11 :: ~Texture3D_D3D11()
+{
+}
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/src/TextureBaseD3D11.cpp b/Graphics/GraphicsEngineD3D11/src/TextureBaseD3D11.cpp
new file mode 100644
index 00000000..2462bec7
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/src/TextureBaseD3D11.cpp
@@ -0,0 +1,216 @@
+/* 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.
+ */
+
+#include "pch.h"
+#include "TextureBaseD3D11.h"
+#include "RenderDeviceD3D11Impl.h"
+#include "DeviceContextD3D11Impl.h"
+#include "D3D11TypeConversions.h"
+#include "TextureViewD3D11Impl.h"
+
+using namespace Diligent;
+
+namespace Diligent
+{
+
+TextureBaseD3D11 :: TextureBaseD3D11(RenderDeviceD3D11Impl *pRenderDeviceD3D11, const TextureDesc& TexDesc, const TextureData &InitData /*= TextureData()*/) :
+ TTextureBase(pRenderDeviceD3D11, TexDesc)
+{
+ if( TexDesc.Usage == USAGE_STATIC && InitData.pSubResources == nullptr )
+ LOG_ERROR_AND_THROW("Static Texture must be initialized with data at creation time");
+}
+
+IMPLEMENT_QUERY_INTERFACE( TextureBaseD3D11, IID_TextureD3D11, TTextureBase )
+
+void TextureBaseD3D11::CreateViewInternal( const struct TextureViewDesc &ViewDesc, ITextureView **ppView, bool bIsDefaultView )
+{
+ VERIFY( ppView != nullptr, "View pointer address is null" );
+ if( !ppView )return;
+ VERIFY( *ppView == nullptr, "Overwriting reference to existing object may cause memory leaks" );
+
+ *ppView = nullptr;
+
+ try
+ {
+ auto UpdatedViewDesc = ViewDesc;
+
+ CorrectTextureViewDesc( UpdatedViewDesc );
+
+ RefCntAutoPtr<ID3D11View> pD3D11View;
+ switch( ViewDesc.ViewType )
+ {
+ case TEXTURE_VIEW_SHADER_RESOURCE:
+ {
+ VERIFY( m_Desc.BindFlags & BIND_SHADER_RESOURCE, "BIND_SHADER_RESOURCE flag is not set" );
+ ID3D11ShaderResourceView *pSRV = nullptr;
+ CreateSRV( UpdatedViewDesc, &pSRV );
+ pD3D11View.Attach( pSRV );
+ }
+ break;
+
+ case TEXTURE_VIEW_RENDER_TARGET:
+ {
+ VERIFY( m_Desc.BindFlags & BIND_RENDER_TARGET, "BIND_RENDER_TARGET flag is not set" );
+ ID3D11RenderTargetView *pRTV = nullptr;
+ CreateRTV( UpdatedViewDesc, &pRTV );
+ pD3D11View.Attach( pRTV );
+ }
+ break;
+
+ case TEXTURE_VIEW_DEPTH_STENCIL:
+ {
+ VERIFY( m_Desc.BindFlags & BIND_DEPTH_STENCIL, "BIND_DEPTH_STENCIL is not set" );
+ ID3D11DepthStencilView *pDSV = nullptr;
+ CreateDSV( UpdatedViewDesc, &pDSV );
+ pD3D11View.Attach( pDSV );
+ }
+ break;
+
+ case TEXTURE_VIEW_UNORDERED_ACCESS:
+ {
+ VERIFY( m_Desc.BindFlags & BIND_UNORDERED_ACCESS, "BIND_UNORDERED_ACCESS flag is not set" );
+ ID3D11UnorderedAccessView *pUAV = nullptr;
+ CreateUAV( UpdatedViewDesc, &pUAV );
+ pD3D11View.Attach( pUAV );
+ }
+ break;
+
+ default: UNEXPECTED( "Unknown view type" ); break;
+ }
+
+ auto pViewD3D11 = new TextureViewD3D11Impl( GetDevice(), UpdatedViewDesc, this, pD3D11View, bIsDefaultView );
+ VERIFY( pViewD3D11->GetDesc().ViewType == ViewDesc.ViewType, "Incorrect view type" );
+
+ if( bIsDefaultView )
+ *ppView = pViewD3D11;
+ else
+ pViewD3D11->QueryInterface(IID_TextureView, reinterpret_cast<IObject**>(ppView) );
+ }
+ catch( const std::runtime_error & )
+ {
+ const auto *ViewTypeName = GetTexViewTypeLiteralName(ViewDesc.ViewType);
+ LOG_ERROR("Failed to create view \"", ViewDesc.Name ? ViewDesc.Name : "", "\" (", ViewTypeName, ") for texture \"", m_Desc.Name ? m_Desc.Name : "", "\"" )
+ }
+}
+
+void TextureBaseD3D11 :: PrepareD3D11InitData(const TextureData &InitData, Uint32 NumSubresources, std::vector<D3D11_SUBRESOURCE_DATA> &D3D11InitData)
+{
+ if( InitData.pSubResources )
+ {
+ if( NumSubresources == InitData.NumSubresources )
+ {
+ D3D11InitData.resize(NumSubresources);
+ for(UINT Subres=0; Subres < NumSubresources; ++Subres)
+ {
+ auto &CurrSubres = InitData.pSubResources[Subres];
+ D3D11InitData[Subres].pSysMem = CurrSubres.pData;
+ D3D11InitData[Subres].SysMemPitch = CurrSubres.Stride;
+ D3D11InitData[Subres].SysMemSlicePitch = CurrSubres.DepthStride;
+ }
+ }
+ else
+ UNEXPECTED( "Incorrect number of subrsources" );
+ }
+}
+
+
+TextureBaseD3D11 :: ~TextureBaseD3D11()
+{
+}
+
+void TextureBaseD3D11::UpdateData( IDeviceContext *pContext, Uint32 MipLevel, Uint32 Slice, const Box &DstBox, const TextureSubResData &SubresData )
+{
+ TTextureBase::UpdateData( pContext, MipLevel, Slice, DstBox, SubresData );
+ VERIFY( m_Desc.Usage == USAGE_DEFAULT, "Only default usage resiurces can be updated with UpdateData()" );
+
+ auto *pd3d11DeviceContext = static_cast<DeviceContextD3D11Impl*>(pContext)->GetD3D11DeviceContext();
+
+ D3D11_BOX D3D11Box;
+ D3D11Box.left = DstBox.MinX;
+ D3D11Box.right = DstBox.MaxX;
+ D3D11Box.top = DstBox.MinY;
+ D3D11Box.bottom = DstBox.MaxY;
+ D3D11Box.front = DstBox.MinZ;
+ D3D11Box.back = DstBox.MaxZ;
+ auto SubresIndex = D3D11CalcSubresource(MipLevel, Slice, m_Desc.MipLevels);
+ pd3d11DeviceContext->UpdateSubresource(m_pd3d11Texture, SubresIndex, &D3D11Box, SubresData.pData, SubresData.Stride, SubresData.DepthStride);
+}
+
+void TextureBaseD3D11 :: CopyData(IDeviceContext *pContext,
+ ITexture *pSrcTexture,
+ Uint32 SrcMipLevel,
+ Uint32 SrcSlice,
+ const Box *pSrcBox,
+ Uint32 DstMipLevel,
+ Uint32 DstSlice,
+ Uint32 DstX,
+ Uint32 DstY,
+ Uint32 DstZ)
+{
+ TTextureBase::CopyData( pContext, pSrcTexture, SrcMipLevel, SrcSlice, pSrcBox,
+ DstMipLevel, DstSlice, DstX, DstY, DstZ );
+
+ auto *pd3d11DeviceContext = ValidatedCast<DeviceContextD3D11Impl>(pContext )->GetD3D11DeviceContext();
+ auto *pSrTextureBaseD3D11 = ValidatedCast<TextureBaseD3D11>( pSrcTexture );
+
+ D3D11_BOX D3D11SrcBox, *pD3D11SrcBox = nullptr;
+ if( pSrcBox )
+ {
+ D3D11SrcBox.left = pSrcBox->MinX;
+ D3D11SrcBox.right = pSrcBox->MaxX;
+ D3D11SrcBox.top = pSrcBox->MinY;
+ D3D11SrcBox.bottom = pSrcBox->MaxY;
+ D3D11SrcBox.front = pSrcBox->MinZ;
+ D3D11SrcBox.back = pSrcBox->MaxZ;
+ pD3D11SrcBox = &D3D11SrcBox;
+ }
+ auto SrcSubRes = D3D11CalcSubresource(SrcMipLevel, SrcSlice, pSrTextureBaseD3D11->GetDesc().MipLevels);
+ auto DstSubRes = D3D11CalcSubresource(DstMipLevel, DstSlice, m_Desc.MipLevels);
+ pd3d11DeviceContext->CopySubresourceRegion(m_pd3d11Texture, DstSubRes, DstX, DstY, DstZ, pSrTextureBaseD3D11->GetD3D11Texture(), SrcSubRes, pD3D11SrcBox);
+}
+
+void TextureBaseD3D11 :: Map(IDeviceContext *pContext, MAP_TYPE MapType, Uint32 MapFlags, PVoid &pMappedData)
+{
+ TTextureBase::Map( pContext, MapType, MapFlags, pMappedData );
+
+ //auto *pd3d11DeviceContext = static_cast<RenderDeviceD3D11Impl*>( static_cast<CRenderDevice*>(m_pDevice) )->GetD3D11DeviceContext();
+ //auto d3d11MapType = MapTypeToD3D11MapType(MapType);
+ //auto d3d11MapFlags = MapFlagsToD3D11MapFlags(MapFlags);
+
+ //D3D11_MAPPED_SUBRESOURCE MappedBuff;
+ //pd3d11DeviceContext->Map(m_pd3d11Texture, 0, d3d11MapType, d3d11MapFlags, &MappedBuff);
+
+ //pMappedData = MappedBuff.pData;
+
+ //VERIFY( pMappedData, "Map failed" );
+}
+
+void TextureBaseD3D11::Unmap( IDeviceContext *pContext )
+{
+ TTextureBase::Unmap( pContext );
+
+ //auto *pd3d11DeviceContext = static_cast<RenderDeviceD3D11Impl*>( static_cast<CRenderDevice*>(m_pDevice) )->GetD3D11DeviceContext();
+ //pd3d11DeviceContext->Unmap(m_pd3d11Texture, 0);
+}
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/src/TextureViewD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/TextureViewD3D11Impl.cpp
new file mode 100644
index 00000000..1cebd403
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/src/TextureViewD3D11Impl.cpp
@@ -0,0 +1,61 @@
+/* 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.
+ */
+
+#include "pch.h"
+#include "TextureViewD3D11Impl.h"
+#include "DeviceContextD3D11Impl.h"
+
+namespace Diligent
+{
+
+TextureViewD3D11Impl::TextureViewD3D11Impl( IRenderDevice *pDevice,
+ const TextureViewDesc& ViewDesc,
+ ITexture *pTexture,
+ ID3D11View* pD3D11View,
+ bool bIsDefaultView ) :
+ TTextureViewBase( pDevice, ViewDesc, pTexture, bIsDefaultView ),
+ m_pD3D11View( pD3D11View )
+{
+}
+
+ID3D11View* TextureViewD3D11Impl::GetD3D11View()
+{
+ return m_pD3D11View;
+}
+
+IMPLEMENT_QUERY_INTERFACE( TextureViewD3D11Impl, IID_TextureViewD3D11, TTextureViewBase )
+
+void TextureViewD3D11Impl::GenerateMips( IDeviceContext *pContext )
+{
+ VERIFY( m_Desc.ViewType == TEXTURE_VIEW_SHADER_RESOURCE, "GenerateMips() is allowed for shader resource views only, ", GetTexViewTypeLiteralName(m_Desc.ViewType), " is not allowed." );
+ if( m_Desc.ViewType != TEXTURE_VIEW_SHADER_RESOURCE )
+ {
+ LOG_ERROR("GenerateMips() is allowed for shader resource views only, ", GetTexViewTypeLiteralName(m_Desc.ViewType), " is not allowed.");
+ return;
+ }
+ auto *pd3d11Ctx = ValidatedCast<IDeviceContextD3D11>( pContext )->GetD3D11DeviceContext();
+ auto *pd3d11SRV = static_cast<ID3D11ShaderResourceView*>( GetD3D11View() );
+ pd3d11Ctx->GenerateMips(pd3d11SRV);
+}
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/src/VertexDescD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/VertexDescD3D11Impl.cpp
new file mode 100644
index 00000000..46be4675
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/src/VertexDescD3D11Impl.cpp
@@ -0,0 +1,72 @@
+/* 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.
+ */
+
+#include "pch.h"
+#include "VertexDescD3D11Impl.h"
+#include "RenderDeviceD3D11Impl.h"
+#include "ShaderD3D11Impl.h"
+#include "D3D11TypeConversions.h"
+
+namespace Diligent
+{
+
+VertexDescD3D11Impl::VertexDescD3D11Impl(RenderDeviceD3D11Impl *pRenderDeviceD3D11, const LayoutDesc &LayoutDesc, IShader *pVertexShader) :
+ TVertexDescriptionBase( pRenderDeviceD3D11, LayoutDesc )
+{
+ // Use m_LayoutDesc as original LayoutDescription might have been corrected
+ auto *pLayoutElements = m_LayoutElements.data();
+ auto NumElements = m_LayoutElements.size();
+
+ if( pVertexShader->GetDesc().ShaderType != SHADER_TYPE_VERTEX )
+ LOG_ERROR_AND_THROW( "Invalid shader type provided for the input layout creation" );
+ std::vector<D3D11_INPUT_ELEMENT_DESC> InputElements;
+ ID3DBlob *pVSByteCode = static_cast<ShaderD3D11Impl*>(pVertexShader)->m_pShaderByteCode;
+ if( !pVSByteCode )
+ LOG_ERROR_AND_THROW( "Vertex Shader byte code does not exist" );
+
+ InputElements.resize(NumElements);
+ for(Uint32 iElem=0; iElem < NumElements; ++iElem)
+ {
+ const auto &CurrElem = pLayoutElements[iElem];
+ auto &D3D11Elem = InputElements[iElem];
+ D3D11Elem.SemanticName = "ATTRIB";
+ D3D11Elem.SemanticIndex = CurrElem.InputIndex;
+ D3D11Elem.AlignedByteOffset = CurrElem.RelativeOffset;
+ D3D11Elem.InputSlot = CurrElem.BufferSlot;
+ D3D11Elem.Format = TypeToDXGI_Format(CurrElem.ValueType, CurrElem.NumComponents, CurrElem.IsNormalized);
+ D3D11Elem.InputSlotClass = (CurrElem.Frequency == LayoutElement::FREQUENCY_PER_VERTEX) ? D3D11_INPUT_PER_VERTEX_DATA : D3D11_INPUT_PER_INSTANCE_DATA;
+ D3D11Elem.InstanceDataStepRate = (CurrElem.Frequency == LayoutElement::FREQUENCY_PER_VERTEX) ? 0 : CurrElem.InstanceDataStepRate;
+ }
+
+ auto *pDeviceD3D11 = pRenderDeviceD3D11->GetD3D11Device();
+ CHECK_D3D_RESULT_THROW( pDeviceD3D11->CreateInputLayout(InputElements.data(), static_cast<UINT>(InputElements.size()), pVSByteCode->GetBufferPointer(), pVSByteCode->GetBufferSize(), &m_pd3d11InputLayout),
+ "Failed to create the Direct3D11 input layout");
+}
+
+VertexDescD3D11Impl::~VertexDescD3D11Impl()
+{
+}
+
+IMPLEMENT_QUERY_INTERFACE( VertexDescD3D11Impl, IID_VertexDescriptionD3D11, TVertexDescriptionBase )
+
+}
diff --git a/Graphics/GraphicsEngineD3D11/src/pch.cpp b/Graphics/GraphicsEngineD3D11/src/pch.cpp
new file mode 100644
index 00000000..c7d1ec78
--- /dev/null
+++ b/Graphics/GraphicsEngineD3D11/src/pch.cpp
@@ -0,0 +1,31 @@
+/* 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.
+ */
+
+// stdafx.cpp : source file that includes just the standard includes
+// GraphicsEngineD3D11.pch will be the pre-compiled header
+// stdafx.obj will contain the pre-compiled type information
+
+#include "pch.h"
+
+// TODO: reference any additional headers you need in STDAFX.H
+// and not in this file