summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineD3DBase
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2016-08-20 06:35:47 +0000
committerEgor Yusov <egor.yusov@gmail.com>2016-08-20 06:35:47 +0000
commit2b64f003622ee7871fd7aec041622427dd2fc88f (patch)
tree893dab48c6d0e7121e047d8d3bb6d5bf172ce2d5 /Graphics/GraphicsEngineD3DBase
parentRelease v1.0.0 (diff)
downloadDiligentCore-2b64f003622ee7871fd7aec041622427dd2fc88f.tar.gz
DiligentCore-2b64f003622ee7871fd7aec041622427dd2fc88f.zip
Updated to Diligent Engine 2.0
Diffstat (limited to 'Graphics/GraphicsEngineD3DBase')
-rw-r--r--Graphics/GraphicsEngineD3DBase/build/UWP/GraphicsEngineD3DBase.vcxproj200
-rw-r--r--Graphics/GraphicsEngineD3DBase/build/UWP/GraphicsEngineD3DBase.vcxproj.filters2
-rw-r--r--Graphics/GraphicsEngineD3DBase/build/Win32/GraphicsEngineD3DBase.vcxproj128
-rw-r--r--Graphics/GraphicsEngineD3DBase/build/Win32/GraphicsEngineD3DBase.vcxproj.filters2
-rw-r--r--Graphics/GraphicsEngineD3DBase/build/Windows.Shared/GraphicsEngineD3DBase.Shared.vcxitems43
-rw-r--r--Graphics/GraphicsEngineD3DBase/build/Windows.Shared/GraphicsEngineD3DBase.Shared.vcxitems.filters56
-rw-r--r--Graphics/GraphicsEngineD3DBase/build/Windows.Shared/GraphicsEngineD3DBase.props28
-rw-r--r--Graphics/GraphicsEngineD3DBase/include/D3DErrors.h89
-rw-r--r--Graphics/GraphicsEngineD3DBase/include/D3DShaderResourceLoader.h335
-rw-r--r--Graphics/GraphicsEngineD3DBase/include/D3DTypeConversionImpl.h538
-rw-r--r--Graphics/GraphicsEngineD3DBase/include/D3DViewDescConversionImpl.h319
-rw-r--r--Graphics/GraphicsEngineD3DBase/include/DXGITypeConversions.h37
-rw-r--r--Graphics/GraphicsEngineD3DBase/include/HLSLDefinitions.fxh61
-rw-r--r--Graphics/GraphicsEngineD3DBase/include/HLSLDefinitions_inc.fxh61
-rw-r--r--Graphics/GraphicsEngineD3DBase/include/RenderDeviceD3DBase.h159
-rw-r--r--Graphics/GraphicsEngineD3DBase/include/ShaderD3DBase.h45
-rw-r--r--Graphics/GraphicsEngineD3DBase/include/ShaderResources.h396
-rw-r--r--Graphics/GraphicsEngineD3DBase/include/ShaderVariableD3DBase.h75
-rw-r--r--Graphics/GraphicsEngineD3DBase/src/DXGITypeConversions.cpp406
-rw-r--r--Graphics/GraphicsEngineD3DBase/src/ShaderD3DBase.cpp198
-rw-r--r--Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp219
21 files changed, 3397 insertions, 0 deletions
diff --git a/Graphics/GraphicsEngineD3DBase/build/UWP/GraphicsEngineD3DBase.vcxproj b/Graphics/GraphicsEngineD3DBase/build/UWP/GraphicsEngineD3DBase.vcxproj
new file mode 100644
index 00000000..d2cbe9fc
--- /dev/null
+++ b/Graphics/GraphicsEngineD3DBase/build/UWP/GraphicsEngineD3DBase.vcxproj
@@ -0,0 +1,200 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|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>{acd6f956-ff3b-4fe9-8be3-c0eecfdbbf93}</ProjectGuid>
+ <Keyword>StaticLibrary</Keyword>
+ <RootNamespace>GraphicsEngineD3DBase</RootNamespace>
+ <DefaultLanguage>en-US</DefaultLanguage>
+ <MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
+ <AppContainerApplication>true</AppContainerApplication>
+ <ApplicationType>Windows Store</ApplicationType>
+ <WindowsTargetPlatformVersion>10.0.10586.0</WindowsTargetPlatformVersion>
+ <WindowsTargetPlatformMinVersion>10.0.10240.0</WindowsTargetPlatformMinVersion>
+ <ApplicationTypeRevision>10.0</ApplicationTypeRevision>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v140</PlatformToolset>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v140</PlatformToolset>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v140</PlatformToolset>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <PlatformToolset>v140</PlatformToolset>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <PlatformToolset>v140</PlatformToolset>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <PlatformToolset>v140</PlatformToolset>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <ImportGroup Label="Shared">
+ <Import Project="..\Windows.Shared\GraphicsEngineD3DBase.Shared.vcxitems" Label="Shared" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ <Import Project="..\..\..\..\Shared\build\UWP\UWP_Win32Dbg.props" />
+ <Import Project="..\Windows.Shared\GraphicsEngineD3DBase.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\UWP\UWP_Win32Rel.props" />
+ <Import Project="..\Windows.Shared\GraphicsEngineD3DBase.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\UWP\UWP_ArmDbg.props" />
+ <Import Project="..\Windows.Shared\GraphicsEngineD3DBase.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\UWP\UWP_ArmRel.props" />
+ <Import Project="..\Windows.Shared\GraphicsEngineD3DBase.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\UWP\UWP_X64Dbg.props" />
+ <Import Project="..\Windows.Shared\GraphicsEngineD3DBase.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\UWP\UWP_X64Rel.props" />
+ <Import Project="..\Windows.Shared\GraphicsEngineD3DBase.props" />
+ </ImportGroup>
+ <PropertyGroup Label="UserMacros" />
+ <PropertyGroup />
+ <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>
+ <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>
+ <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>
+ <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>
+ <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>
+ <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>
+ <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/GraphicsEngineD3DBase/build/UWP/GraphicsEngineD3DBase.vcxproj.filters b/Graphics/GraphicsEngineD3DBase/build/UWP/GraphicsEngineD3DBase.vcxproj.filters
new file mode 100644
index 00000000..c31757ec
--- /dev/null
+++ b/Graphics/GraphicsEngineD3DBase/build/UWP/GraphicsEngineD3DBase.vcxproj.filters
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" /> \ No newline at end of file
diff --git a/Graphics/GraphicsEngineD3DBase/build/Win32/GraphicsEngineD3DBase.vcxproj b/Graphics/GraphicsEngineD3DBase/build/Win32/GraphicsEngineD3DBase.vcxproj
new file mode 100644
index 00000000..02bf1cb3
--- /dev/null
+++ b/Graphics/GraphicsEngineD3DBase/build/Win32/GraphicsEngineD3DBase.vcxproj
@@ -0,0 +1,128 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|Win32">
+ <Configuration>Debug</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|Win32">
+ <Configuration>Release</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Debug|x64">
+ <Configuration>Debug</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|x64">
+ <Configuration>Release</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>{40FD58ED-AABC-4CBD-BEE4-33116995A626}</ProjectGuid>
+ <RootNamespace>GraphicsEngineD3DBase</RootNamespace>
+ <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v140</PlatformToolset>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v140</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v140</PlatformToolset>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v140</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <ImportGroup Label="Shared">
+ <Import Project="..\Windows.Shared\GraphicsEngineD3DBase.Shared.vcxitems" Label="Shared" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ <Import Project="..\..\..\..\Shared\build\Windows\Win32d.props" />
+ <Import Project="..\Windows.Shared\GraphicsEngineD3DBase.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="..\Windows.Shared\GraphicsEngineD3DBase.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\Windows\Win64d.props" />
+ <Import Project="..\Windows.Shared\GraphicsEngineD3DBase.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\Windows\Win64r.props" />
+ <Import Project="..\Windows.Shared\GraphicsEngineD3DBase.props" />
+ </ImportGroup>
+ <PropertyGroup Label="UserMacros" />
+ <PropertyGroup />
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <ClCompile>
+ <Optimization>Disabled</Optimization>
+ <SDLCheck>true</SDLCheck>
+ </ClCompile>
+ <Link>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <ClCompile>
+ <Optimization>Disabled</Optimization>
+ <SDLCheck>true</SDLCheck>
+ </ClCompile>
+ <Link>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <ClCompile>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <SDLCheck>true</SDLCheck>
+ </ClCompile>
+ <Link>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <ClCompile>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <SDLCheck>true</SDLCheck>
+ </ClCompile>
+ <Link>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ </Link>
+ </ItemDefinitionGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project> \ No newline at end of file
diff --git a/Graphics/GraphicsEngineD3DBase/build/Win32/GraphicsEngineD3DBase.vcxproj.filters b/Graphics/GraphicsEngineD3DBase/build/Win32/GraphicsEngineD3DBase.vcxproj.filters
new file mode 100644
index 00000000..9cd85105
--- /dev/null
+++ b/Graphics/GraphicsEngineD3DBase/build/Win32/GraphicsEngineD3DBase.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/GraphicsEngineD3DBase/build/Windows.Shared/GraphicsEngineD3DBase.Shared.vcxitems b/Graphics/GraphicsEngineD3DBase/build/Windows.Shared/GraphicsEngineD3DBase.Shared.vcxitems
new file mode 100644
index 00000000..ec2067e5
--- /dev/null
+++ b/Graphics/GraphicsEngineD3DBase/build/Windows.Shared/GraphicsEngineD3DBase.Shared.vcxitems
@@ -0,0 +1,43 @@
+<?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>{9e0110fc-5339-4196-8397-ba4fa34a4b84}</ItemsProjectGuid>
+ <ItemsRootNamespace>ArithmeticCodec</ItemsRootNamespace>
+ <ItemsProjectName>GraphicsEngineD3DBase.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\D3DErrors.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\D3DShaderResourceLoader.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\D3DTypeConversionImpl.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\D3DViewDescConversionImpl.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\DXGITypeConversions.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\RenderDeviceD3DBase.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\ShaderD3DBase.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\ShaderResources.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\ShaderVariableD3DBase.h" />
+ </ItemGroup>
+ <ItemGroup>
+ <CustomBuild Include="$(MSBuildThisFileDirectory)..\..\include\HLSLDefinitions.fxh">
+ <FileType>Document</FileType>
+ <Command>$(EngineRoot)\Utilities\File2Include\File2String.exe %(FullPath) $(ProjectRoot)\include\%(Filename)_inc.fxh</Command>
+ <Outputs>$(ProjectRoot)\include\%(Filename)_inc.h</Outputs>
+ <Message>Processing HLSLDefinitions.fxh...</Message>
+ </CustomBuild>
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\src\DXGITypeConversions.cpp" />
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\src\ShaderD3DBase.cpp" />
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\src\ShaderResources.cpp" />
+ </ItemGroup>
+</Project> \ No newline at end of file
diff --git a/Graphics/GraphicsEngineD3DBase/build/Windows.Shared/GraphicsEngineD3DBase.Shared.vcxitems.filters b/Graphics/GraphicsEngineD3DBase/build/Windows.Shared/GraphicsEngineD3DBase.Shared.vcxitems.filters
new file mode 100644
index 00000000..8d4bb64f
--- /dev/null
+++ b/Graphics/GraphicsEngineD3DBase/build/Windows.Shared/GraphicsEngineD3DBase.Shared.vcxitems.filters
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup>
+ <Filter Include="include">
+ <UniqueIdentifier>{8a08aac0-0c0c-460e-997b-e2a2480f9348}</UniqueIdentifier>
+ </Filter>
+ <Filter Include="src">
+ <UniqueIdentifier>{f03946b0-f3aa-4358-845a-1f1d9c13056d}</UniqueIdentifier>
+ </Filter>
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\D3DErrors.h">
+ <Filter>include</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\D3DShaderResourceLoader.h">
+ <Filter>include</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\D3DViewDescConversionImpl.h">
+ <Filter>include</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\DXGITypeConversions.h">
+ <Filter>include</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\D3DTypeConversionImpl.h">
+ <Filter>include</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\RenderDeviceD3DBase.h">
+ <Filter>include</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\ShaderD3DBase.h">
+ <Filter>include</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\ShaderResources.h">
+ <Filter>include</Filter>
+ </ClInclude>
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\..\include\ShaderVariableD3DBase.h">
+ <Filter>include</Filter>
+ </ClInclude>
+ </ItemGroup>
+ <ItemGroup>
+ <CustomBuild Include="$(MSBuildThisFileDirectory)..\..\include\HLSLDefinitions.fxh">
+ <Filter>include</Filter>
+ </CustomBuild>
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\src\DXGITypeConversions.cpp">
+ <Filter>src</Filter>
+ </ClCompile>
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\src\ShaderD3DBase.cpp">
+ <Filter>src</Filter>
+ </ClCompile>
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\src\ShaderResources.cpp">
+ <Filter>src</Filter>
+ </ClCompile>
+ </ItemGroup>
+</Project> \ No newline at end of file
diff --git a/Graphics/GraphicsEngineD3DBase/build/Windows.Shared/GraphicsEngineD3DBase.props b/Graphics/GraphicsEngineD3DBase/build/Windows.Shared/GraphicsEngineD3DBase.props
new file mode 100644
index 00000000..38b91f11
--- /dev/null
+++ b/Graphics/GraphicsEngineD3DBase/build/Windows.Shared/GraphicsEngineD3DBase.props
@@ -0,0 +1,28 @@
+<?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>
+ <IncludePath>$(GraphicsRoot)\GraphicsEngineD3DBase\include;$(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>
+ <ClCompile>
+ <PrecompiledHeader>NotUsing</PrecompiledHeader>
+ </ClCompile>
+ </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/GraphicsEngineD3DBase/include/D3DErrors.h b/Graphics/GraphicsEngineD3DBase/include/D3DErrors.h
new file mode 100644
index 00000000..5280820f
--- /dev/null
+++ b/Graphics/GraphicsEngineD3DBase/include/D3DErrors.h
@@ -0,0 +1,89 @@
+/* Copyright 2015-2016 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+#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/GraphicsEngineD3DBase/include/D3DShaderResourceLoader.h b/Graphics/GraphicsEngineD3DBase/include/D3DShaderResourceLoader.h
new file mode 100644
index 00000000..7e58c910
--- /dev/null
+++ b/Graphics/GraphicsEngineD3DBase/include/D3DShaderResourceLoader.h
@@ -0,0 +1,335 @@
+/* Copyright 2015-2016 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+#include "Shader.h"
+#include "StringTools.h"
+
+/// \file
+/// D3D shader resource loading
+
+namespace Diligent
+{
+ template<typename D3D_SHADER_DESC,
+ typename D3D_SHADER_INPUT_BIND_DESC,
+ typename TShaderReflection,
+
+ typename TOnResourcesCounted,
+ typename TOnNewCB,
+ typename TOnNewTexUAV,
+ typename TOnNewBuffUAV,
+ typename TOnNewBuffSRV,
+ typename TOnNewSampler,
+ typename TOnNewTexSRV>
+ void LoadD3DShaderResources(ID3DBlob *pShaderByteCode,
+
+ TOnResourcesCounted OnResourcesCounted,
+ TOnNewCB OnNewCB,
+ TOnNewTexUAV OnNewTexUAV,
+ TOnNewBuffUAV OnNewBuffUAV,
+ TOnNewBuffSRV OnNewBuffSRV,
+ TOnNewSampler OnNewSampler,
+ TOnNewTexSRV OnNewTexSRV,
+
+ const ShaderDesc &ShdrDesc,
+ const Char *SamplerSuffix)
+ {
+ CComPtr<TShaderReflection> pShaderReflection;
+ CHECK_D3D_RESULT_THROW( D3DReflect( pShaderByteCode->GetBufferPointer(), pShaderByteCode->GetBufferSize(), __uuidof(pShaderReflection), reinterpret_cast<void**>(static_cast<TShaderReflection**>(&pShaderReflection)) ),
+ "Failed to get the shader reflection" );
+
+ D3D_SHADER_DESC shaderDesc = {};
+ pShaderReflection->GetDesc( &shaderDesc );
+
+ std::vector<D3DShaderResourceAttribs, STDAllocatorRawMem<D3DShaderResourceAttribs> > Resources( STD_ALLOCATOR_RAW_MEM(D3DShaderResourceAttribs, GetRawAllocator(), "Allocator for vector<D3DShaderResourceAttribs>") );
+ Resources.reserve(shaderDesc.BoundResources);
+
+ Uint32 NumCBs = 0, NumTexSRVs = 0, NumTexUAVs = 0, NumBufSRVs = 0, NumBufUAVs = 0, NumSamplers = 0;
+ // Number of resources to skip (used for array resources)
+ UINT SkipCount = 1;
+ for( UINT Res = 0; Res < shaderDesc.BoundResources; Res += SkipCount )
+ {
+ D3D_SHADER_INPUT_BIND_DESC BindingDesc = {};
+ pShaderReflection->GetResourceBindingDesc( Res, &BindingDesc );
+
+ String Name(BindingDesc.Name);
+
+ SkipCount = 1;
+
+ UINT BindCount = BindingDesc.BindCount;
+
+ // Handle arrays
+ // For shader models 5_0 and before, every resource array element is enumerated individually.
+ // For instance, if the following texture array is defined in the shader:
+ //
+ // Texture2D<float3> g_tex2DDiffuse[4];
+ //
+ // The reflection system will enumerate 4 resources with the following names:
+ // "g_tex2DDiffuse[0]"
+ // "g_tex2DDiffuse[1]"
+ // "g_tex2DDiffuse[2]"
+ // "g_tex2DDiffuse[3]"
+ //
+ // Notice that if some array element is not used by the shader, it will not be enumerated
+
+ auto OpenBracketPos = Name.find('[');
+ if (String::npos != OpenBracketPos)
+ {
+ VERIFY(BindCount == 1, "When array elements are enumerated individually, BindCount is expected to always be 1")
+
+ // Name == "g_tex2DDiffuse[0]"
+ // ^
+ // OpenBracketPos
+ Name.erase(OpenBracketPos, Name.length() - OpenBracketPos);
+ // Name == "g_tex2DDiffuse"
+ VERIFY_EXPR(Name.length() == OpenBracketPos);
+#ifdef _DEBUG
+ for (const auto &ExistingRes : Resources)
+ {
+ VERIFY(ExistingRes.Name != Name, "Resource with the same name has already been enumerated. All array elements are expected to be enumerated one after another")
+ }
+#endif
+ for( UINT ArrElem = Res+1; ArrElem < shaderDesc.BoundResources; ++ArrElem)
+ {
+ D3D_SHADER_INPUT_BIND_DESC ArrElemBindingDesc = {};
+ pShaderReflection->GetResourceBindingDesc( ArrElem, &ArrElemBindingDesc );
+
+ // Make sure this case is handled correctly:
+ // "g_tex2DDiffuse[.]" != "g_tex2DDiffuse2[.]"
+ if ( strncmp(Name.c_str(), ArrElemBindingDesc.Name, OpenBracketPos) == 0 && ArrElemBindingDesc.Name[OpenBracketPos] == '[')
+ {
+ //g_tex2DDiffuse[2]
+ // ^
+ UINT Ind = atoi(ArrElemBindingDesc.Name+OpenBracketPos+1);
+ BindCount = std::max(BindCount, Ind+1);
+ VERIFY(ArrElemBindingDesc.BindPoint == BindingDesc.BindPoint + Ind,
+ "Array elements are expected to use contigous bind points.\n",
+ BindingDesc.Name, " uses slot ", BindingDesc.BindPoint, ", so ", ArrElemBindingDesc.Name, " is expected to use slot ", BindingDesc.BindPoint + Ind, " while ", ArrElemBindingDesc.BindPoint, " is actually used" );
+
+ // Note that skip count may not necessarily be the same as BindCount.
+ // If some array elements are not used by the shader, the reflection system skips them
+ ++SkipCount;
+ }
+ else
+ {
+ break;
+ }
+ }
+ }
+
+
+ SHADER_VARIABLE_TYPE VarType = SHADER_VARIABLE_TYPE_NUM_TYPES;
+ bool IsStaticSampler = false;
+ if (BindingDesc.Type == D3D_SIT_SAMPLER)
+ {
+ for (Uint32 s = 0; s < ShdrDesc.NumStaticSamplers; ++s)
+ {
+ if( StrCmpSuff(Name.c_str(), ShdrDesc.StaticSamplers[s].TextureName, SamplerSuffix) )
+ {
+ IsStaticSampler = true;
+ break;
+ }
+ }
+ // Use texture name to derive sampler type
+ VarType = GetShaderVariableType(ShdrDesc.DefaultVariableType, ShdrDesc.VariableDesc, ShdrDesc.NumVariables,
+ [&](const char *TexName)
+ {
+ return StrCmpSuff(Name.c_str(), TexName, SamplerSuffix);
+ }
+ );
+ }
+ else
+ {
+ VarType = GetShaderVariableType(Name.c_str(), ShdrDesc.DefaultVariableType, ShdrDesc.VariableDesc, ShdrDesc.NumVariables);
+ }
+
+
+ switch( BindingDesc.Type )
+ {
+ case D3D_SIT_CBUFFER: ++NumCBs; break;
+ case D3D_SIT_TBUFFER: UNSUPPORTED( "TBuffers are not supported" ); break;
+ case D3D_SIT_TEXTURE: ++(BindingDesc.Dimension == D3D_SRV_DIMENSION_BUFFER ? NumBufSRVs : NumTexSRVs); break;
+ case D3D_SIT_SAMPLER: ++NumSamplers; break;
+ case D3D_SIT_UAV_RWTYPED: ++(BindingDesc.Dimension == D3D_SRV_DIMENSION_BUFFER ? NumBufUAVs : NumTexUAVs); break;
+ case D3D_SIT_STRUCTURED: UNSUPPORTED( "Structured buffers are not supported" ); break;
+ case D3D_SIT_UAV_RWSTRUCTURED: ++NumBufUAVs; break;
+ case D3D_SIT_BYTEADDRESS: UNSUPPORTED( "Byte address buffers are not supported" ); break;
+ case D3D_SIT_UAV_RWBYTEADDRESS: ++NumBufUAVs; 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;
+ default: UNEXPECTED("Unexpected resource type")
+ }
+ Resources.emplace_back(std::move(Name), BindingDesc.BindPoint, BindCount, BindingDesc.Type, VarType, BindingDesc.Dimension, D3DShaderResourceAttribs::InvalidSamplerId, IsStaticSampler);
+ }
+
+
+#ifdef _DEBUG
+ if(ShdrDesc.NumVariables != 0 || ShdrDesc.NumStaticSamplers != 0 )
+ {
+ for (Uint32 v = 0; v < ShdrDesc.NumVariables; ++v)
+ {
+ bool VariableFound = false;
+ const auto *VarName = ShdrDesc.VariableDesc[v].Name;
+
+ for (const auto& Res : Resources)
+ {
+ // Skip samplers as they are not handled as independent variables
+ if (Res.GetInputType() != D3D_SIT_SAMPLER && Res.Name.compare(VarName) == 0)
+ {
+ VariableFound = true;
+ break;
+ }
+ }
+ if(!VariableFound)
+ {
+ LOG_WARNING_MESSAGE("Variable \"", VarName, "\" not found in shader \"", ShdrDesc.Name, '\"');
+ }
+ }
+
+ for (Uint32 s = 0; s < ShdrDesc.NumStaticSamplers; ++s)
+ {
+ bool TextureFound = false;
+ const auto *TexName = ShdrDesc.StaticSamplers[s].TextureName;
+
+ for (const auto& Res : Resources)
+ {
+ if ( Res.GetInputType() == D3D_SIT_TEXTURE && Res.GetSRVDimension() != D3D_SRV_DIMENSION_BUFFER && Res.Name.compare(TexName) == 0)
+ {
+ TextureFound = true;
+ break;
+ }
+ }
+ if(!TextureFound)
+ {
+ LOG_WARNING_MESSAGE("Static sampler specifies a texture \"", TexName, "\" that is not found in shader \"", ShdrDesc.Name, '\"');
+ }
+ }
+ }
+#endif
+
+ OnResourcesCounted(NumCBs, NumTexSRVs, NumTexUAVs, NumBufSRVs, NumBufUAVs, NumSamplers);
+
+ std::vector<D3DShaderResourceAttribs, STDAllocatorRawMem<D3DShaderResourceAttribs> > TextureSRVs( STD_ALLOCATOR_RAW_MEM(D3DShaderResourceAttribs, GetRawAllocator(), "Allocator for vector<D3DShaderResourceAttribs>") );
+ TextureSRVs.reserve(NumTexSRVs);
+
+ for(auto &Res : Resources)
+ {
+ switch( Res.GetInputType() )
+ {
+ case D3D_SIT_CBUFFER:
+ {
+ OnNewCB( std::move(Res) );
+ break;
+ }
+
+ case D3D_SIT_TBUFFER:
+ {
+ UNSUPPORTED( "TBuffers are not supported" );
+ break;
+ }
+
+ case D3D_SIT_TEXTURE:
+ {
+ if( Res.GetSRVDimension() == D3D_SRV_DIMENSION_BUFFER )
+ {
+ OnNewBuffSRV( std::move(Res) );
+ }
+ else
+ {
+ TextureSRVs.emplace_back( std::move(Res) );
+ }
+ break;
+ }
+
+ case D3D_SIT_SAMPLER:
+ {
+ OnNewSampler( std::move(Res) );
+ break;
+ }
+
+ case D3D_SIT_UAV_RWTYPED:
+ {
+ if( Res.GetSRVDimension() == D3D_SRV_DIMENSION_BUFFER )
+ {
+ OnNewBuffUAV( std::move(Res) );
+ }
+ else
+ {
+ OnNewTexUAV( std::move(Res) );
+ }
+ break;
+ }
+
+ case D3D_SIT_STRUCTURED:
+ {
+ UNSUPPORTED( "Structured buffers are not supported" );
+ break;
+ }
+
+ case D3D_SIT_UAV_RWSTRUCTURED:
+ {
+ OnNewBuffUAV( std::move(Res) );
+ break;
+ }
+
+ case D3D_SIT_BYTEADDRESS:
+ {
+ UNSUPPORTED( "Byte address buffers are not supported" );
+ break;
+ }
+
+ case D3D_SIT_UAV_RWBYTEADDRESS:
+ {
+ OnNewBuffUAV( std::move(Res) );
+ 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;
+ }
+ }
+ }
+
+ // Process texture SRVs. We need to do this after all samplers are initialized
+ for( auto &Tex : TextureSRVs )
+ {
+ OnNewTexSRV( std::move(Tex) );
+ }
+ }
+}
diff --git a/Graphics/GraphicsEngineD3DBase/include/D3DTypeConversionImpl.h b/Graphics/GraphicsEngineD3DBase/include/D3DTypeConversionImpl.h
new file mode 100644
index 00000000..ebb8825b
--- /dev/null
+++ b/Graphics/GraphicsEngineD3DBase/include/D3DTypeConversionImpl.h
@@ -0,0 +1,538 @@
+/* Copyright 2015-2016 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+/// \file
+/// Implementation of D3D type conversions
+
+/// This file must be included after D3D11TypeDefinitions.h or D3D12TypeDefinitions.h
+
+namespace Diligent
+{
+
+ template<typename D3D_COMPARISON_FUNC>
+ inline D3D_COMPARISON_FUNC ComparisonFuncToD3DComparisonFunc(COMPARISON_FUNCTION Func)
+ {
+ // D3D12_COMPARISON_FUNC is equal to D3D11_COMPARISON_FUNC
+ switch(Func)
+ {
+ case COMPARISON_FUNC_UNKNOWN: UNEXPECTED("Comparison function is not specified" ); return D3D_COMPARISON_FUNC_ALWAYS;
+ case COMPARISON_FUNC_NEVER: return D3D_COMPARISON_FUNC_NEVER;
+ case COMPARISON_FUNC_LESS: return D3D_COMPARISON_FUNC_LESS;
+ case COMPARISON_FUNC_EQUAL: return D3D_COMPARISON_FUNC_EQUAL;
+ case COMPARISON_FUNC_LESS_EQUAL: return D3D_COMPARISON_FUNC_LESS_EQUAL;
+ case COMPARISON_FUNC_GREATER: return D3D_COMPARISON_FUNC_GREATER;
+ case COMPARISON_FUNC_NOT_EQUAL: return D3D_COMPARISON_FUNC_NOT_EQUAL;
+ case COMPARISON_FUNC_GREATER_EQUAL: return D3D_COMPARISON_FUNC_GREATER_EQUAL;
+ case COMPARISON_FUNC_ALWAYS: return D3D_COMPARISON_FUNC_ALWAYS;
+ default: UNEXPECTED("Unknown comparison function" ); return D3D_COMPARISON_FUNC_ALWAYS;
+ }
+ }
+
+
+ template<typename D3D_TEXTURE_ADDRESS_MODE>
+ D3D_TEXTURE_ADDRESS_MODE TexAddressModeToD3DAddressMode(TEXTURE_ADDRESS_MODE Mode)
+ {
+ switch(Mode)
+ {
+ case TEXTURE_ADDRESS_UNKNOWN: UNEXPECTED("Texture address mode is not specified" ); return D3D_TEXTURE_ADDRESS_CLAMP;
+ case TEXTURE_ADDRESS_WRAP: return D3D_TEXTURE_ADDRESS_WRAP;
+ case TEXTURE_ADDRESS_MIRROR: return D3D_TEXTURE_ADDRESS_MIRROR;
+ case TEXTURE_ADDRESS_CLAMP: return D3D_TEXTURE_ADDRESS_CLAMP;
+ case TEXTURE_ADDRESS_BORDER: return D3D_TEXTURE_ADDRESS_BORDER;
+ case TEXTURE_ADDRESS_MIRROR_ONCE: return D3D_TEXTURE_ADDRESS_MIRROR_ONCE;
+ default: UNEXPECTED("Unknown texture address mode" ); return D3D_TEXTURE_ADDRESS_CLAMP;
+ }
+ }
+
+ template<typename D3D_PRIM_TOPOLOGY>
+ D3D_PRIM_TOPOLOGY TopologyToD3DTopology(PRIMITIVE_TOPOLOGY Topology)
+ {
+ static bool bIsInit = false;
+ static D3D_PRIM_TOPOLOGY d3dPrimTopology[PRIMITIVE_TOPOLOGY_NUM_TOPOLOGIES] = {};
+ if( !bIsInit )
+ {
+ d3dPrimTopology[PRIMITIVE_TOPOLOGY_UNDEFINED] = D3D_PRIMITIVE_TOPOLOGY_UNDEFINED;
+ d3dPrimTopology[PRIMITIVE_TOPOLOGY_TRIANGLE_LIST] = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
+ d3dPrimTopology[PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP] = D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP;
+ d3dPrimTopology[PRIMITIVE_TOPOLOGY_POINT_LIST] = D3D_PRIMITIVE_TOPOLOGY_POINTLIST;
+ d3dPrimTopology[PRIMITIVE_TOPOLOGY_LINE_LIST] = D3D_PRIMITIVE_TOPOLOGY_LINELIST;
+
+ bIsInit = true;
+ }
+
+ VERIFY_EXPR(Topology >= PRIMITIVE_TOPOLOGY_UNDEFINED && Topology<PRIMITIVE_TOPOLOGY_NUM_TOPOLOGIES);
+ return d3dPrimTopology[Topology];
+ }
+
+
+ // ================= Rasterizer state attributes conversion functions =================
+
+ template<typename D3D_FILL_MODE>
+ D3D_FILL_MODE FillModeToD3DFillMode(FILL_MODE FillMode)
+ {
+ // D3D12_FILL_MODE is identical tp D3D11_FILL_MODE
+ static bool bIsInit = false;
+ static D3D_FILL_MODE d3dFillModes[FILL_MODE_NUM_MODES] = {};
+ if( !bIsInit )
+ {
+ d3dFillModes[ FILL_MODE_WIREFRAME ] = D3D_FILL_MODE_WIREFRAME;
+ d3dFillModes[ FILL_MODE_SOLID ] = D3D_FILL_MODE_SOLID;
+
+ bIsInit = true;
+ }
+ if( FILL_MODE_UNDEFINED < FillMode && FillMode < FILL_MODE_NUM_MODES )
+ {
+ auto d3dFillMode = d3dFillModes[FillMode];
+ VERIFY( d3dFillMode != 0, "Incorrect fill mode" );
+ return d3dFillMode;
+ }
+ else
+ {
+ UNEXPECTED( "Incorrect fill mode (", FillMode, ")" )
+ return static_cast<D3D_FILL_MODE>(0);
+ }
+ }
+
+ template<typename D3D_CULL_MODE>
+ D3D_CULL_MODE CullModeToD3DCullMode( CULL_MODE CullMode )
+ {
+ // D3D_CULL_MODE is identical to D3D11_CULL_MODE
+ static bool bIsInit = false;
+ static D3D_CULL_MODE d3dCullModes[CULL_MODE_NUM_MODES] = {};
+ if( !bIsInit )
+ {
+ d3dCullModes[ CULL_MODE_NONE ] = D3D_CULL_MODE_NONE;
+ d3dCullModes[ CULL_MODE_FRONT ] = D3D_CULL_MODE_FRONT;
+ d3dCullModes[ CULL_MODE_BACK ] = D3D_CULL_MODE_BACK;
+
+ bIsInit = true;
+ }
+
+ if( CULL_MODE_UNDEFINED < CullMode && CullMode < CULL_MODE_NUM_MODES )
+ {
+ auto d3dCullMode = d3dCullModes[CullMode];
+ VERIFY( d3dCullMode != 0, "Incorrect cull mode" );
+ return d3dCullMode;
+ }
+ else
+ {
+ UNEXPECTED( "Incorrect cull mode (", CullMode, ")" )
+ return static_cast<D3D_CULL_MODE>(0);
+ }
+ }
+
+ template<typename D3D_RASTERIZER_DESC, typename D3D_FILL_MODE, typename D3D_CULL_MODE>
+ void RasterizerStateDesc_To_D3D_RASTERIZER_DESC(const RasterizerStateDesc &RasterizerDesc, D3D_RASTERIZER_DESC &d3dRSDesc)
+ {
+ d3dRSDesc.FillMode = FillModeToD3DFillMode<D3D_FILL_MODE>(RasterizerDesc.FillMode);
+ d3dRSDesc.CullMode = CullModeToD3DCullMode<D3D_CULL_MODE>(RasterizerDesc.CullMode);
+ d3dRSDesc.FrontCounterClockwise = RasterizerDesc.FrontCounterClockwise ? TRUE : FALSE;
+ d3dRSDesc.DepthBias = RasterizerDesc.DepthBias;
+ d3dRSDesc.DepthBiasClamp = RasterizerDesc.DepthBiasClamp;
+ d3dRSDesc.SlopeScaledDepthBias = RasterizerDesc.SlopeScaledDepthBias;
+ d3dRSDesc.DepthClipEnable = RasterizerDesc.DepthClipEnable ? TRUE : FALSE;
+
+ //d3d12RSDesc.ScissorEnable = RSDesc.ScissorEnable ? TRUE : FALSE;
+
+ d3dRSDesc.AntialiasedLineEnable = RasterizerDesc.AntialiasedLineEnable ? TRUE : FALSE;
+ d3dRSDesc.MultisampleEnable = d3dRSDesc.AntialiasedLineEnable;
+ }
+
+
+
+ // ================= Blend state attributes conversion functions =================
+
+ template<typename D3D_BLEND>
+ D3D_BLEND BlendFactorToD3DBlend( BLEND_FACTOR bf )
+ {
+ // D3D11_BLEND and D3D12_BLEND are identical
+
+ // 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 D3D_BLEND D3DBlend[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
+ D3DBlend[ BLEND_FACTOR_ZERO ] = D3D_BLEND_ZERO;
+ D3DBlend[ BLEND_FACTOR_ONE ] = D3D_BLEND_ONE;
+ D3DBlend[ BLEND_FACTOR_SRC_COLOR ] = D3D_BLEND_SRC_COLOR;
+ D3DBlend[ BLEND_FACTOR_INV_SRC_COLOR ] = D3D_BLEND_INV_SRC_COLOR;
+ D3DBlend[ BLEND_FACTOR_SRC_ALPHA ] = D3D_BLEND_SRC_ALPHA;
+ D3DBlend[ BLEND_FACTOR_INV_SRC_ALPHA ] = D3D_BLEND_INV_SRC_ALPHA;
+ D3DBlend[ BLEND_FACTOR_DEST_ALPHA ] = D3D_BLEND_DEST_ALPHA;
+ D3DBlend[ BLEND_FACTOR_INV_DEST_ALPHA ] = D3D_BLEND_INV_DEST_ALPHA;
+ D3DBlend[ BLEND_FACTOR_DEST_COLOR ] = D3D_BLEND_DEST_COLOR;
+ D3DBlend[ BLEND_FACTOR_INV_DEST_COLOR ] = D3D_BLEND_INV_DEST_COLOR;
+ D3DBlend[ BLEND_FACTOR_SRC_ALPHA_SAT ] = D3D_BLEND_SRC_ALPHA_SAT;
+ D3DBlend[ BLEND_FACTOR_BLEND_FACTOR ] = D3D_BLEND_BLEND_FACTOR;
+ D3DBlend[ BLEND_FACTOR_INV_BLEND_FACTOR ] = D3D_BLEND_INV_BLEND_FACTOR;
+ D3DBlend[ BLEND_FACTOR_SRC1_COLOR ] = D3D_BLEND_SRC1_COLOR;
+ D3DBlend[ BLEND_FACTOR_INV_SRC1_COLOR ] = D3D_BLEND_INV_SRC1_COLOR;
+ D3DBlend[ BLEND_FACTOR_SRC1_ALPHA ] = D3D_BLEND_SRC1_ALPHA;
+ D3DBlend[ BLEND_FACTOR_INV_SRC1_ALPHA ] = D3D_BLEND_INV_SRC1_ALPHA;
+
+ bIsInit = true;
+ }
+ if( bf > BLEND_FACTOR_UNDEFINED && bf < BLEND_FACTOR_NUM_FACTORS )
+ {
+ auto d3dbf = D3DBlend[bf];
+ VERIFY( d3dbf != 0, "Incorrect blend factor" );
+ return d3dbf;
+ }
+ else
+ {
+ UNEXPECTED("Incorrect blend factor (", bf, ")" )
+ return static_cast<D3D_BLEND>( 0 );
+ }
+ }
+
+ template<typename D3D_BLEND_OP>
+ D3D_BLEND_OP BlendOperationToD3DBlendOp( BLEND_OPERATION BlendOp )
+ {
+ // D3D12_BLEND_OP and D3D11_BLEND_OP are identical
+
+ static bool bIsInit = false;
+ static D3D_BLEND_OP D3DBlendOp[BLEND_OPERATION_NUM_OPERATIONS] = {};
+ if( !bIsInit )
+ {
+ D3DBlendOp[ BLEND_OPERATION_ADD ] = D3D_BLEND_OP_ADD;
+ D3DBlendOp[ BLEND_OPERATION_SUBTRACT ] = D3D_BLEND_OP_SUBTRACT;
+ D3DBlendOp[ BLEND_OPERATION_REV_SUBTRACT ] = D3D_BLEND_OP_REV_SUBTRACT;
+ D3DBlendOp[ BLEND_OPERATION_MIN ] = D3D_BLEND_OP_MIN;
+ D3DBlendOp[ BLEND_OPERATION_MAX ] = D3D_BLEND_OP_MAX;
+
+ bIsInit = true;
+ }
+
+ if( BlendOp > BLEND_OPERATION_UNDEFINED && BlendOp < BLEND_OPERATION_NUM_OPERATIONS )
+ {
+ auto d3dbop = D3DBlendOp[BlendOp];
+ VERIFY( d3dbop != 0, "Incorrect blend operation" );
+ return d3dbop;
+ }
+ else
+ {
+ UNEXPECTED( "Incorrect blend operation (", BlendOp, ")" )
+ return static_cast<D3D_BLEND_OP>(0);
+ }
+ }
+
+ template<typename D3D_BLEND_DESC, typename D3D_BLEND, typename D3D_BLEND_OP>
+ void BlendStateDescToD3DBlendDesc(const BlendStateDesc &BSDesc, D3D_BLEND_DESC &d3d12BlendDesc)
+ {
+ // D3D_BLEND_DESC and D3D11_BLEND_DESC structures are identical
+ d3d12BlendDesc.AlphaToCoverageEnable = BSDesc.AlphaToCoverageEnable ? TRUE : FALSE;
+ d3d12BlendDesc.IndependentBlendEnable = BSDesc.IndependentBlendEnable ? TRUE : FALSE;
+ VERIFY( BSDesc.MaxRenderTargets >= 8, "Number of render targets is expected to be at least 8" );
+ for( int i = 0; i < 8; ++i )
+ {
+ const auto& SrcRTDesc = BSDesc.RenderTargets[i];
+ auto &DstRTDesc = d3d12BlendDesc.RenderTarget[i];
+ DstRTDesc.BlendEnable = SrcRTDesc.BlendEnable ? TRUE : FALSE;
+
+ DstRTDesc.SrcBlend = BlendFactorToD3DBlend<D3D_BLEND>(SrcRTDesc.SrcBlend);
+ DstRTDesc.DestBlend = BlendFactorToD3DBlend<D3D_BLEND>(SrcRTDesc.DestBlend);
+ DstRTDesc.BlendOp = BlendOperationToD3DBlendOp<D3D_BLEND_OP>(SrcRTDesc.BlendOp);
+
+ DstRTDesc.SrcBlendAlpha = BlendFactorToD3DBlend<D3D_BLEND>(SrcRTDesc.SrcBlendAlpha);
+ DstRTDesc.DestBlendAlpha = BlendFactorToD3DBlend<D3D_BLEND>(SrcRTDesc.DestBlendAlpha);
+ DstRTDesc.BlendOpAlpha = BlendOperationToD3DBlendOp<D3D_BLEND_OP>(SrcRTDesc.BlendOpAlpha);
+
+ DstRTDesc.RenderTargetWriteMask =
+ ((SrcRTDesc.RenderTargetWriteMask & COLOR_MASK_RED) ? D3D_COLOR_WRITE_ENABLE_RED : 0) |
+ ((SrcRTDesc.RenderTargetWriteMask & COLOR_MASK_GREEN) ? D3D_COLOR_WRITE_ENABLE_GREEN : 0) |
+ ((SrcRTDesc.RenderTargetWriteMask & COLOR_MASK_BLUE) ? D3D_COLOR_WRITE_ENABLE_BLUE : 0) |
+ ((SrcRTDesc.RenderTargetWriteMask & COLOR_MASK_ALPHA) ? D3D_COLOR_WRITE_ENABLE_ALPHA : 0);
+ }
+ }
+
+
+
+ // ====================== Depth-stencil state attributes conversion functions ======================
+
+ template<typename D3D_STENCIL_OP>
+ D3D_STENCIL_OP StencilOpToD3DStencilOp( STENCIL_OP StencilOp )
+ {
+ static bool bIsInit = false;
+ static D3D_STENCIL_OP StOpToD3DStOpMap[STENCIL_OP_NUM_OPS] = {};
+ if( !bIsInit )
+ {
+ StOpToD3DStOpMap[ STENCIL_OP_KEEP ] = D3D_STENCIL_OP_KEEP;
+ StOpToD3DStOpMap[ STENCIL_OP_ZERO ] = D3D_STENCIL_OP_ZERO;
+ StOpToD3DStOpMap[ STENCIL_OP_REPLACE ] = D3D_STENCIL_OP_REPLACE;
+ StOpToD3DStOpMap[ STENCIL_OP_INCR_SAT ] = D3D_STENCIL_OP_INCR_SAT;
+ StOpToD3DStOpMap[ STENCIL_OP_DECR_SAT ] = D3D_STENCIL_OP_DECR_SAT;
+ StOpToD3DStOpMap[ STENCIL_OP_INVERT ] = D3D_STENCIL_OP_INVERT;
+ StOpToD3DStOpMap[ STENCIL_OP_INCR_WRAP] = D3D_STENCIL_OP_INCR;
+ StOpToD3DStOpMap[ STENCIL_OP_DECR_WRAP] = D3D_STENCIL_OP_DECR;
+
+ bIsInit = true;
+ }
+
+ if( StencilOp > STENCIL_OP_UNDEFINED && StencilOp < STENCIL_OP_NUM_OPS )
+ {
+ auto d3dStencilOp = StOpToD3DStOpMap[StencilOp];
+ VERIFY( d3dStencilOp != 0, "Unexpected stencil op" );
+ return d3dStencilOp;
+ }
+ else
+ {
+ UNEXPECTED( "Stencil operation (", StencilOp, ") is out of allowed range [1, ", STENCIL_OP_NUM_OPS - 1, "]" )
+ return static_cast<D3D_STENCIL_OP>(0);
+ }
+ }
+
+ template<typename D3D_DEPTH_STENCILOP_DESC, typename D3D_STENCIL_OP, typename D3D_COMPARISON_FUNC>
+ D3D_DEPTH_STENCILOP_DESC StencilOpDescToD3DStencilOpDesc(const StencilOpDesc &StOpDesc)
+ {
+ // D3D12_DEPTH_STENCILOP_DESC is identical to D3D11_DEPTH_STENCILOP_DESC
+ D3D_DEPTH_STENCILOP_DESC D3DStOpDesc;
+ D3DStOpDesc.StencilFailOp = StencilOpToD3DStencilOp<D3D_STENCIL_OP>( StOpDesc.StencilFailOp );
+ D3DStOpDesc.StencilDepthFailOp = StencilOpToD3DStencilOp<D3D_STENCIL_OP>( StOpDesc.StencilDepthFailOp );
+ D3DStOpDesc.StencilPassOp = StencilOpToD3DStencilOp<D3D_STENCIL_OP>( StOpDesc.StencilPassOp );
+ D3DStOpDesc.StencilFunc = ComparisonFuncToD3DComparisonFunc<D3D_COMPARISON_FUNC>( StOpDesc.StencilFunc );
+ return D3DStOpDesc;
+ }
+
+ template<typename D3D_DEPTH_STENCIL_DESC, typename D3D_DEPTH_STENCILOP_DESC, typename D3D_STENCIL_OP, typename D3D_COMPARISON_FUNC>
+ void DepthStencilStateDesc_To_D3D_DEPTH_STENCIL_DESC(const DepthStencilStateDesc &DepthStencilDesc, D3D_DEPTH_STENCIL_DESC &d3dDSSDesc)
+ {
+ // D3D_DEPTH_STENCIL_DESC is identical to D3D11_DEPTH_STENCIL_DESC
+ d3dDSSDesc.DepthEnable = DepthStencilDesc.DepthEnable ? TRUE : FALSE;
+ d3dDSSDesc.DepthWriteMask = DepthStencilDesc.DepthWriteEnable ? D3D_DEPTH_WRITE_MASK_ALL : D3D_DEPTH_WRITE_MASK_ZERO;
+ d3dDSSDesc.DepthFunc = ComparisonFuncToD3DComparisonFunc<D3D_COMPARISON_FUNC>( DepthStencilDesc.DepthFunc );
+ d3dDSSDesc.StencilEnable = DepthStencilDesc.StencilEnable ? TRUE : FALSE;
+ d3dDSSDesc.StencilReadMask = DepthStencilDesc.StencilReadMask;
+ d3dDSSDesc.StencilWriteMask = DepthStencilDesc.StencilWriteMask;
+ d3dDSSDesc.FrontFace = StencilOpDescToD3DStencilOpDesc<D3D_DEPTH_STENCILOP_DESC, D3D_STENCIL_OP, D3D_COMPARISON_FUNC>( DepthStencilDesc.FrontFace );
+ d3dDSSDesc.BackFace = StencilOpDescToD3DStencilOpDesc<D3D_DEPTH_STENCILOP_DESC, D3D_STENCIL_OP, D3D_COMPARISON_FUNC>( DepthStencilDesc.BackFace );
+ }
+
+
+
+ template<typename D3D_INPUT_ELEMENT_DESC>
+ void LayoutElements_To_D3D_INPUT_ELEMENT_DESCs(const std::vector<LayoutElement, STDAllocatorRawMem<LayoutElement> > &LayoutElements, std::vector<D3D_INPUT_ELEMENT_DESC, STDAllocatorRawMem<D3D_INPUT_ELEMENT_DESC>> &D3DInputElements)
+ {
+ // D3D12_INPUT_ELEMENT_DESC and D3D11_INPUT_ELEMENT_DESC are identical
+ auto NumElements = LayoutElements.size();
+ D3DInputElements.resize(NumElements);
+ for(Uint32 iElem=0; iElem < NumElements; ++iElem)
+ {
+ const auto &CurrElem = LayoutElements[iElem];
+ auto &D3DElem = D3DInputElements[iElem];
+ D3DElem.SemanticName = "ATTRIB";
+ D3DElem.SemanticIndex = CurrElem.InputIndex;
+ D3DElem.AlignedByteOffset = CurrElem.RelativeOffset;
+ D3DElem.InputSlot = CurrElem.BufferSlot;
+ D3DElem.Format = TypeToDXGI_Format(CurrElem.ValueType, CurrElem.NumComponents, CurrElem.IsNormalized);
+ D3DElem.InputSlotClass = (CurrElem.Frequency == LayoutElement::FREQUENCY_PER_VERTEX) ? D3D_INPUT_CLASSIFICATION_PER_VERTEX_DATA : D3D_INPUT_CLASSIFICATION_PER_INSTANCE_DATA;
+ D3DElem.InstanceDataStepRate = (CurrElem.Frequency == LayoutElement::FREQUENCY_PER_VERTEX) ? 0 : CurrElem.InstanceDataStepRate;
+ }
+ }
+
+
+ template<typename D3D_FILTER>
+ D3D_FILTER FilterTypeToD3DFilter(FILTER_TYPE MinFilter, FILTER_TYPE MagFilter, FILTER_TYPE MipFilter)
+ {
+ switch( MinFilter )
+ {
+ // Regular filters
+ case FILTER_TYPE_POINT:
+ if( MagFilter == FILTER_TYPE_POINT )
+ {
+ if( MipFilter == FILTER_TYPE_POINT )
+ return D3D_FILTER_MIN_MAG_MIP_POINT;
+ else if( MipFilter == FILTER_TYPE_LINEAR )
+ return D3D_FILTER_MIN_MAG_POINT_MIP_LINEAR;
+ }
+ else if( MagFilter == FILTER_TYPE_LINEAR )
+ {
+ if( MipFilter == FILTER_TYPE_POINT )
+ return D3D_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT;
+ else if( MipFilter == FILTER_TYPE_LINEAR )
+ return D3D_FILTER_MIN_POINT_MAG_MIP_LINEAR;
+ }
+ break;
+
+ case FILTER_TYPE_LINEAR:
+ if( MagFilter == FILTER_TYPE_POINT )
+ {
+ if( MipFilter == FILTER_TYPE_POINT )
+ return D3D_FILTER_MIN_LINEAR_MAG_MIP_POINT;
+ else if( MipFilter == FILTER_TYPE_LINEAR )
+ return D3D_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR;
+ }
+ else if( MagFilter == FILTER_TYPE_LINEAR )
+ {
+ if( MipFilter == FILTER_TYPE_POINT )
+ return D3D_FILTER_MIN_MAG_LINEAR_MIP_POINT;
+ else if( MipFilter == FILTER_TYPE_LINEAR )
+ return D3D_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 D3D_FILTER_ANISOTROPIC;
+ break;
+
+
+
+ // Comparison filters
+ case FILTER_TYPE_COMPARISON_POINT:
+ if( MagFilter == FILTER_TYPE_COMPARISON_POINT )
+ {
+ if( MipFilter == FILTER_TYPE_COMPARISON_POINT )
+ return D3D_FILTER_COMPARISON_MIN_MAG_MIP_POINT;
+ else if( MipFilter == FILTER_TYPE_COMPARISON_LINEAR )
+ return D3D_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR;
+ }
+ else if( MagFilter == FILTER_TYPE_COMPARISON_LINEAR )
+ {
+ if( MipFilter == FILTER_TYPE_COMPARISON_POINT )
+ return D3D_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT;
+ else if( MipFilter == FILTER_TYPE_COMPARISON_LINEAR )
+ return D3D_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 D3D_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT;
+ else if( MipFilter == FILTER_TYPE_COMPARISON_LINEAR )
+ return D3D_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR;
+ }
+ else if( MagFilter == FILTER_TYPE_COMPARISON_LINEAR )
+ {
+ if( MipFilter == FILTER_TYPE_COMPARISON_POINT )
+ return D3D_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT;
+ else if( MipFilter == FILTER_TYPE_COMPARISON_LINEAR )
+ return D3D_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 D3D_FILTER_COMPARISON_ANISOTROPIC;
+ break;
+
+
+
+ // Minimum filters
+ case FILTER_TYPE_MINIMUM_POINT:
+ if( MagFilter == FILTER_TYPE_MINIMUM_POINT )
+ {
+ if( MipFilter == FILTER_TYPE_MINIMUM_POINT )
+ return D3D_FILTER_MINIMUM_MIN_MAG_MIP_POINT;
+ else if( MipFilter == FILTER_TYPE_MINIMUM_LINEAR )
+ return D3D_FILTER_MINIMUM_MIN_MAG_POINT_MIP_LINEAR;
+ }
+ else if( MagFilter == FILTER_TYPE_MINIMUM_LINEAR )
+ {
+ if( MipFilter == FILTER_TYPE_MINIMUM_POINT )
+ return D3D_FILTER_MINIMUM_MIN_POINT_MAG_LINEAR_MIP_POINT;
+ else if( MipFilter == FILTER_TYPE_MINIMUM_LINEAR )
+ return D3D_FILTER_MINIMUM_MIN_POINT_MAG_MIP_LINEAR;
+ }
+ break;
+
+ case FILTER_TYPE_MINIMUM_LINEAR:
+ if( MagFilter == FILTER_TYPE_MINIMUM_POINT )
+ {
+ if( MipFilter == FILTER_TYPE_MINIMUM_POINT )
+ return D3D_FILTER_MINIMUM_MIN_LINEAR_MAG_MIP_POINT;
+ else if( MipFilter == FILTER_TYPE_MINIMUM_LINEAR )
+ return D3D_FILTER_MINIMUM_MIN_LINEAR_MAG_POINT_MIP_LINEAR;
+ }
+ else if( MagFilter == FILTER_TYPE_MINIMUM_LINEAR )
+ {
+ if( MipFilter == FILTER_TYPE_MINIMUM_POINT )
+ return D3D_FILTER_MINIMUM_MIN_MAG_LINEAR_MIP_POINT;
+ else if( MipFilter == FILTER_TYPE_MINIMUM_LINEAR )
+ return D3D_FILTER_MINIMUM_MIN_MAG_MIP_LINEAR;
+ }
+ break;
+
+ case FILTER_TYPE_MINIMUM_ANISOTROPIC:
+ VERIFY( MagFilter == FILTER_TYPE_MINIMUM_ANISOTROPIC && MipFilter == FILTER_TYPE_MINIMUM_ANISOTROPIC,
+ "For minimum anistropic filtering, all filters must be anisotropic" );
+ return D3D_FILTER_MINIMUM_ANISOTROPIC;
+ break;
+
+
+
+ // Maximum filters
+ case FILTER_TYPE_MAXIMUM_POINT:
+ if( MagFilter == FILTER_TYPE_MAXIMUM_POINT )
+ {
+ if( MipFilter == FILTER_TYPE_MAXIMUM_POINT )
+ return D3D_FILTER_MAXIMUM_MIN_MAG_MIP_POINT;
+ else if( MipFilter == FILTER_TYPE_MAXIMUM_LINEAR )
+ return D3D_FILTER_MAXIMUM_MIN_MAG_POINT_MIP_LINEAR;
+ }
+ else if( MagFilter == FILTER_TYPE_MAXIMUM_LINEAR )
+ {
+ if( MipFilter == FILTER_TYPE_MAXIMUM_POINT )
+ return D3D_FILTER_MAXIMUM_MIN_POINT_MAG_LINEAR_MIP_POINT;
+ else if( MipFilter == FILTER_TYPE_MAXIMUM_LINEAR )
+ return D3D_FILTER_MAXIMUM_MIN_POINT_MAG_MIP_LINEAR;
+ }
+ break;
+
+ case FILTER_TYPE_MAXIMUM_LINEAR:
+ if( MagFilter == FILTER_TYPE_MAXIMUM_POINT )
+ {
+ if( MipFilter == FILTER_TYPE_MAXIMUM_POINT )
+ return D3D_FILTER_MAXIMUM_MIN_LINEAR_MAG_MIP_POINT;
+ else if( MipFilter == FILTER_TYPE_MAXIMUM_LINEAR )
+ return D3D_FILTER_MAXIMUM_MIN_LINEAR_MAG_POINT_MIP_LINEAR;
+ }
+ else if( MagFilter == FILTER_TYPE_MAXIMUM_LINEAR )
+ {
+ if( MipFilter == FILTER_TYPE_MAXIMUM_POINT )
+ return D3D_FILTER_MAXIMUM_MIN_MAG_LINEAR_MIP_POINT;
+ else if( MipFilter == FILTER_TYPE_MAXIMUM_LINEAR )
+ return D3D_FILTER_MAXIMUM_MIN_MAG_MIP_LINEAR;
+ }
+ break;
+
+ case FILTER_TYPE_MAXIMUM_ANISOTROPIC:
+ VERIFY( MagFilter == FILTER_TYPE_MAXIMUM_ANISOTROPIC && MipFilter == FILTER_TYPE_MAXIMUM_ANISOTROPIC,
+ "For maximum anistropic filtering, all filters must be anisotropic" );
+ return D3D_FILTER_MAXIMUM_ANISOTROPIC;
+ break;
+ }
+
+ UNEXPECTED( "Unsupported filter combination" );
+ return D3D_FILTER_MIN_MAG_MIP_POINT;
+ }
+}
diff --git a/Graphics/GraphicsEngineD3DBase/include/D3DViewDescConversionImpl.h b/Graphics/GraphicsEngineD3DBase/include/D3DViewDescConversionImpl.h
new file mode 100644
index 00000000..baa0a3ab
--- /dev/null
+++ b/Graphics/GraphicsEngineD3DBase/include/D3DViewDescConversionImpl.h
@@ -0,0 +1,319 @@
+/* Copyright 2015-2016 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+/// \file
+/// Implementation of D3D type conversions
+
+/// This file must be included after D3D11TypeDefinitions.h or D3D12TypeDefinitions.h
+
+#include "DXGITypeConversions.h"
+
+namespace Diligent
+{
+ template<typename D3D_SHADER_RESOURCE_VIEW_DESC>
+ void TextureViewDesc_to_D3D_SRV_DESC(const TextureViewDesc& SRVDesc, D3D_SHADER_RESOURCE_VIEW_DESC &d3dSRVDesc, Uint32 SampleCount)
+ {
+ memset(&d3dSRVDesc, 0, sizeof(d3dSRVDesc));
+ d3dSRVDesc.Format = TexFormatToDXGI_Format(SRVDesc.Format, BIND_SHADER_RESOURCE);
+
+ switch (SRVDesc.TextureDim)
+ {
+ case RESOURCE_DIM_TEX_1D:
+ d3dSRVDesc.ViewDimension = D3D_SRV_DIMENSION_TEXTURE1D;
+ d3dSRVDesc.Texture1D.MipLevels = SRVDesc.NumMipLevels;
+ d3dSRVDesc.Texture1D.MostDetailedMip = SRVDesc.MostDetailedMip;
+ break;
+
+ case RESOURCE_DIM_TEX_1D_ARRAY:
+ d3dSRVDesc.ViewDimension = D3D_SRV_DIMENSION_TEXTURE1DARRAY;
+ d3dSRVDesc.Texture1DArray.ArraySize = SRVDesc.NumArraySlices;
+ d3dSRVDesc.Texture1DArray.FirstArraySlice = SRVDesc.FirstArraySlice;
+ d3dSRVDesc.Texture1DArray.MipLevels = SRVDesc.NumMipLevels;
+ d3dSRVDesc.Texture1DArray.MostDetailedMip = SRVDesc.MostDetailedMip;
+ break;
+
+ case RESOURCE_DIM_TEX_2D:
+ if( SampleCount > 1 )
+ {
+ d3dSRVDesc.ViewDimension = D3D_SRV_DIMENSION_TEXTURE2DMS;
+ d3dSRVDesc.Texture2DMS.UnusedField_NothingToDefine = 0;
+ }
+ else
+ {
+ d3dSRVDesc.ViewDimension = D3D_SRV_DIMENSION_TEXTURE2D;
+ d3dSRVDesc.Texture2D.MipLevels = SRVDesc.NumMipLevels;
+ d3dSRVDesc.Texture2D.MostDetailedMip = SRVDesc.MostDetailedMip;
+ }
+ break;
+
+ case RESOURCE_DIM_TEX_2D_ARRAY:
+ if( SampleCount > 1 )
+ {
+ d3dSRVDesc.ViewDimension = D3D_SRV_DIMENSION_TEXTURE2DMSARRAY;
+ d3dSRVDesc.Texture2DMSArray.ArraySize = SRVDesc.NumArraySlices;
+ d3dSRVDesc.Texture2DMSArray.FirstArraySlice = SRVDesc.FirstArraySlice;
+ }
+ else
+ {
+ d3dSRVDesc.ViewDimension = D3D_SRV_DIMENSION_TEXTURE2DARRAY;
+ d3dSRVDesc.Texture2DArray.ArraySize = SRVDesc.NumArraySlices;
+ d3dSRVDesc.Texture2DArray.FirstArraySlice = SRVDesc.FirstArraySlice;
+ d3dSRVDesc.Texture2DArray.MipLevels = SRVDesc.NumMipLevels;
+ d3dSRVDesc.Texture2DArray.MostDetailedMip = SRVDesc.MostDetailedMip;
+ }
+ break;
+
+ case RESOURCE_DIM_TEX_3D:
+ d3dSRVDesc.ViewDimension = D3D_SRV_DIMENSION_TEXTURE3D;
+ d3dSRVDesc.Texture3D.MipLevels = SRVDesc.NumMipLevels;
+ d3dSRVDesc.Texture3D.MostDetailedMip = SRVDesc.MostDetailedMip;
+ break;
+
+ case RESOURCE_DIM_TEX_CUBE:
+ d3dSRVDesc.ViewDimension = D3D_SRV_DIMENSION_TEXTURECUBE;
+ d3dSRVDesc.TextureCube.MipLevels = SRVDesc.NumMipLevels;
+ d3dSRVDesc.TextureCube.MostDetailedMip = SRVDesc.MostDetailedMip;
+ break;
+
+ case RESOURCE_DIM_TEX_CUBE_ARRAY:
+ d3dSRVDesc.ViewDimension = D3D_SRV_DIMENSION_TEXTURECUBEARRAY;
+ d3dSRVDesc.TextureCubeArray.MipLevels = SRVDesc.NumMipLevels;
+ d3dSRVDesc.TextureCubeArray.MostDetailedMip = SRVDesc.MostDetailedMip;
+ d3dSRVDesc.TextureCubeArray.First2DArrayFace = SRVDesc.FirstArraySlice;
+ d3dSRVDesc.TextureCubeArray.NumCubes = SRVDesc.NumArraySlices / 6;
+ break;
+
+ default:
+ UNEXPECTED( "Unexpected view type" );
+ }
+ }
+
+ template<typename D3D_RENDER_TARGET_VIEW_DESC>
+ void TextureViewDesc_to_D3D_RTV_DESC(const TextureViewDesc& RTVDesc, D3D_RENDER_TARGET_VIEW_DESC &d3dRTVDesc, Uint32 SampleCount)
+ {
+ memset(&d3dRTVDesc, 0, sizeof(d3dRTVDesc));
+ d3dRTVDesc.Format = TexFormatToDXGI_Format(RTVDesc.Format, BIND_RENDER_TARGET);
+
+ switch(RTVDesc.TextureDim)
+ {
+ case RESOURCE_DIM_TEX_1D:
+ d3dRTVDesc.ViewDimension = D3D_RTV_DIMENSION_TEXTURE1D;
+ d3dRTVDesc.Texture1D.MipSlice = RTVDesc.MostDetailedMip;
+ break;
+
+ case RESOURCE_DIM_TEX_1D_ARRAY:
+ d3dRTVDesc.ViewDimension = D3D_RTV_DIMENSION_TEXTURE1DARRAY;
+ d3dRTVDesc.Texture1DArray.ArraySize = RTVDesc.NumArraySlices;
+ d3dRTVDesc.Texture1DArray.FirstArraySlice = RTVDesc.FirstArraySlice;
+ d3dRTVDesc.Texture1DArray.MipSlice = RTVDesc.MostDetailedMip;
+ break;
+
+
+ case RESOURCE_DIM_TEX_2D:
+ if( SampleCount > 1 )
+ {
+ d3dRTVDesc.ViewDimension = D3D_RTV_DIMENSION_TEXTURE2DMS;
+ d3dRTVDesc.Texture2DMS.UnusedField_NothingToDefine = 0;
+ }
+ else
+ {
+ d3dRTVDesc.ViewDimension = D3D_RTV_DIMENSION_TEXTURE2D;
+ d3dRTVDesc.Texture2D.MipSlice = RTVDesc.MostDetailedMip;
+ }
+ break;
+
+ case RESOURCE_DIM_TEX_2D_ARRAY:
+ if( SampleCount > 1 )
+ {
+ d3dRTVDesc.ViewDimension = D3D_RTV_DIMENSION_TEXTURE2DMSARRAY;
+ d3dRTVDesc.Texture2DMSArray.ArraySize = RTVDesc.NumArraySlices;
+ d3dRTVDesc.Texture2DMSArray.FirstArraySlice = RTVDesc.FirstArraySlice;
+ }
+ else
+ {
+ d3dRTVDesc.ViewDimension = D3D_RTV_DIMENSION_TEXTURE2DARRAY;
+ d3dRTVDesc.Texture2DArray.ArraySize = RTVDesc.NumArraySlices;
+ d3dRTVDesc.Texture2DArray.FirstArraySlice = RTVDesc.FirstArraySlice;
+ d3dRTVDesc.Texture2DArray.MipSlice = RTVDesc.MostDetailedMip;
+ }
+ break;
+
+ case RESOURCE_DIM_TEX_3D:
+ d3dRTVDesc.ViewDimension = D3D_RTV_DIMENSION_TEXTURE3D;
+ d3dRTVDesc.Texture3D.FirstWSlice = RTVDesc.FirstDepthSlice;
+ d3dRTVDesc.Texture3D.WSize = RTVDesc.NumDepthSlices;
+ d3dRTVDesc.Texture3D.MipSlice = RTVDesc.MostDetailedMip;
+ break;
+
+ default:
+ UNEXPECTED( "Unexpected view type" );
+ }
+ }
+
+ template<typename D3D_DEPTH_STENCIL_VIEW_DESC>
+ void TextureViewDesc_to_D3D_DSV_DESC(const TextureViewDesc& DSVDesc, D3D_DEPTH_STENCIL_VIEW_DESC &d3dDSVDesc, Uint32 SampleCount)
+ {
+ memset(&d3dDSVDesc, 0, sizeof(d3dDSVDesc));
+ d3dDSVDesc.Format = TexFormatToDXGI_Format(DSVDesc.Format, BIND_DEPTH_STENCIL);
+
+ switch(DSVDesc.TextureDim)
+ {
+ case RESOURCE_DIM_TEX_1D:
+ d3dDSVDesc.ViewDimension = D3D_DSV_DIMENSION_TEXTURE1D;
+ d3dDSVDesc.Texture1D.MipSlice = DSVDesc.MostDetailedMip;
+ break;
+
+ case RESOURCE_DIM_TEX_1D_ARRAY:
+ d3dDSVDesc.ViewDimension = D3D_DSV_DIMENSION_TEXTURE1DARRAY;
+ d3dDSVDesc.Texture1DArray.ArraySize = DSVDesc.NumArraySlices;
+ d3dDSVDesc.Texture1DArray.FirstArraySlice = DSVDesc.FirstArraySlice;
+ d3dDSVDesc.Texture1DArray.MipSlice = DSVDesc.MostDetailedMip;
+ break;
+
+
+ case RESOURCE_DIM_TEX_2D:
+ if( SampleCount > 1 )
+ {
+ d3dDSVDesc.ViewDimension = D3D_DSV_DIMENSION_TEXTURE2DMS;
+ d3dDSVDesc.Texture2DMS.UnusedField_NothingToDefine = 0;
+ }
+ else
+ {
+ d3dDSVDesc.ViewDimension = D3D_DSV_DIMENSION_TEXTURE2D;
+ d3dDSVDesc.Texture2D.MipSlice = DSVDesc.MostDetailedMip;
+ }
+ break;
+
+ case RESOURCE_DIM_TEX_2D_ARRAY:
+ if( SampleCount > 1 )
+ {
+ d3dDSVDesc.ViewDimension = D3D_DSV_DIMENSION_TEXTURE2DMSARRAY;
+ d3dDSVDesc.Texture2DMSArray.ArraySize = DSVDesc.NumArraySlices;
+ d3dDSVDesc.Texture2DMSArray.FirstArraySlice = DSVDesc.FirstArraySlice;
+ }
+ else
+ {
+ d3dDSVDesc.ViewDimension = D3D_DSV_DIMENSION_TEXTURE2DARRAY;
+ d3dDSVDesc.Texture2DArray.ArraySize = DSVDesc.NumArraySlices;
+ d3dDSVDesc.Texture2DArray.FirstArraySlice = DSVDesc.FirstArraySlice;
+ d3dDSVDesc.Texture2DArray.MipSlice = DSVDesc.MostDetailedMip;
+ }
+ break;
+
+ case RESOURCE_DIM_TEX_3D:
+ LOG_ERROR_AND_THROW("Depth stencil views are not supported for 3D textures");
+ break;
+
+ default:
+ UNEXPECTED( "Unexpected view type" );
+ }
+ }
+
+ template<typename D3D_UNORDERED_ACCESS_VIEW_DESC>
+ void TextureViewDesc_to_D3D_UAV_DESC(const TextureViewDesc& UAVDesc, D3D_UNORDERED_ACCESS_VIEW_DESC &d3dUAVDesc)
+ {
+ memset(&d3dUAVDesc, 0, sizeof(d3dUAVDesc));
+ d3dUAVDesc.Format = TexFormatToDXGI_Format(UAVDesc.Format, BIND_UNORDERED_ACCESS);
+
+ switch(UAVDesc.TextureDim)
+ {
+ case RESOURCE_DIM_TEX_1D:
+ d3dUAVDesc.ViewDimension = D3D_UAV_DIMENSION_TEXTURE1D;
+ d3dUAVDesc.Texture1D.MipSlice = UAVDesc.MostDetailedMip;
+ break;
+
+ case RESOURCE_DIM_TEX_1D_ARRAY:
+ d3dUAVDesc.ViewDimension = D3D_UAV_DIMENSION_TEXTURE1DARRAY;
+ d3dUAVDesc.Texture1DArray.ArraySize = UAVDesc.NumArraySlices;
+ d3dUAVDesc.Texture1DArray.FirstArraySlice = UAVDesc.FirstArraySlice;
+ d3dUAVDesc.Texture1DArray.MipSlice = UAVDesc.MostDetailedMip;
+ break;
+
+ case RESOURCE_DIM_TEX_2D:
+ d3dUAVDesc.ViewDimension = D3D_UAV_DIMENSION_TEXTURE2D;
+ d3dUAVDesc.Texture2D.MipSlice = UAVDesc.MostDetailedMip;
+ break;
+
+ case RESOURCE_DIM_TEX_2D_ARRAY:
+ d3dUAVDesc.ViewDimension = D3D_UAV_DIMENSION_TEXTURE2DARRAY;
+ d3dUAVDesc.Texture2DArray.ArraySize = UAVDesc.NumArraySlices;
+ d3dUAVDesc.Texture2DArray.FirstArraySlice = UAVDesc.FirstArraySlice;
+ d3dUAVDesc.Texture2DArray.MipSlice = UAVDesc.MostDetailedMip;
+ break;
+
+ case RESOURCE_DIM_TEX_3D:
+ d3dUAVDesc.ViewDimension = D3D_UAV_DIMENSION_TEXTURE3D;
+ d3dUAVDesc.Texture3D.FirstWSlice = UAVDesc.FirstDepthSlice;
+ d3dUAVDesc.Texture3D.WSize = UAVDesc.NumDepthSlices;
+ d3dUAVDesc.Texture3D.MipSlice = UAVDesc.MostDetailedMip;
+ break;
+
+ default:
+ UNEXPECTED( "Unexpected view type" );
+ }
+ }
+
+ template<typename D3D_UNORDERED_ACCESS_VIEW_DESC>
+ void BufferViewDesc_to_D3D_SRV_DESC(const BufferDesc &BuffDesc, const BufferViewDesc& SRVDesc, D3D_UNORDERED_ACCESS_VIEW_DESC &d3dSRVDesc)
+ {
+ if( SRVDesc.ByteOffset != 0 )
+ {
+ VERIFY( BuffDesc.Mode == BUFFER_MODE_STRUCTURED, "Non-zero byte offset is only supported for structured buffers" );
+ }
+
+ memset( &d3dSRVDesc, 0, sizeof( d3dSRVDesc ) );
+ const auto &BuffFmt = BuffDesc.Format;
+ if( BuffDesc.Mode == BUFFER_MODE_FORMATED )
+ d3dSRVDesc.Format = TypeToDXGI_Format( BuffFmt.ValueType, BuffFmt.NumComponents, BuffFmt.IsNormalized );
+
+ VERIFY( SRVDesc.ViewType == BUFFER_VIEW_SHADER_RESOURCE, "Incorrect view type: shader resource is expected" );
+ VERIFY( (SRVDesc.ByteOffset % BuffDesc.ElementByteStride) == 0, "Byte offest is not multiple of element byte stride" );
+ VERIFY( (SRVDesc.ByteWidth % BuffDesc.ElementByteStride) == 0, "Byte width is not multiple of element byte stride" );
+ d3dSRVDesc.Buffer.FirstElement = SRVDesc.ByteOffset / BuffDesc.ElementByteStride;
+ d3dSRVDesc.Buffer.NumElements = SRVDesc.ByteWidth / BuffDesc.ElementByteStride;
+ d3dSRVDesc.ViewDimension = D3D_SRV_DIMENSION_BUFFER;
+ }
+
+ template<typename D3D_UNORDERED_ACCESS_VIEW_DESC>
+ void BufferViewDesc_to_D3D_UAV_DESC(const BufferDesc &BuffDesc, const BufferViewDesc& UAVDesc, D3D_UNORDERED_ACCESS_VIEW_DESC &d3dUAVDesc)
+ {
+ if( UAVDesc.ByteOffset != 0 )
+ {
+ VERIFY( BuffDesc.Mode == BUFFER_MODE_STRUCTURED, "Non-zero byte offset is only supported for structured buffers" );
+ }
+
+ memset( &d3dUAVDesc, 0, sizeof(d3dUAVDesc) );
+ const auto &BuffFmt = BuffDesc.Format;
+ if( BuffDesc.Mode == BUFFER_MODE_FORMATED )
+ d3dUAVDesc.Format = TypeToDXGI_Format( BuffFmt.ValueType, BuffFmt.NumComponents, BuffFmt.IsNormalized );
+
+ VERIFY( UAVDesc.ViewType == BUFFER_VIEW_UNORDERED_ACCESS, "Incorrect view type: unordered access is expected" );
+ VERIFY( (UAVDesc.ByteOffset % BuffDesc.ElementByteStride) == 0, "Byte offest is not multiple of element byte stride" );
+ VERIFY( (UAVDesc.ByteWidth % BuffDesc.ElementByteStride) == 0, "Byte width is not multiple of element byte stride" );
+ d3dUAVDesc.Buffer.FirstElement = UAVDesc.ByteOffset / BuffDesc.ElementByteStride;
+ d3dUAVDesc.Buffer.NumElements = UAVDesc.ByteWidth / BuffDesc.ElementByteStride;
+ d3dUAVDesc.ViewDimension = D3D_UAV_DIMENSION_BUFFER;
+ }
+}
diff --git a/Graphics/GraphicsEngineD3DBase/include/DXGITypeConversions.h b/Graphics/GraphicsEngineD3DBase/include/DXGITypeConversions.h
new file mode 100644
index 00000000..1f0889d8
--- /dev/null
+++ b/Graphics/GraphicsEngineD3DBase/include/DXGITypeConversions.h
@@ -0,0 +1,37 @@
+/* Copyright 2015-2016 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+/// \file
+/// Common D3D type conversion utilities
+
+#include <dxgi.h>
+#include "GraphicsTypes.h"
+
+namespace Diligent
+{
+ DXGI_FORMAT TexFormatToDXGI_Format(TEXTURE_FORMAT TexFormat, Uint32 BindFlags = 0);
+ DXGI_FORMAT TypeToDXGI_Format(VALUE_TYPE ValType, Uint32 NumComponents, Bool bIsNormalized);
+}
+
diff --git a/Graphics/GraphicsEngineD3DBase/include/HLSLDefinitions.fxh b/Graphics/GraphicsEngineD3DBase/include/HLSLDefinitions.fxh
new file mode 100644
index 00000000..fd19be08
--- /dev/null
+++ b/Graphics/GraphicsEngineD3DBase/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/GraphicsEngineD3DBase/include/HLSLDefinitions_inc.fxh b/Graphics/GraphicsEngineD3DBase/include/HLSLDefinitions_inc.fxh
new file mode 100644
index 00000000..84012ff1
--- /dev/null
+++ b/Graphics/GraphicsEngineD3DBase/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/GraphicsEngineD3DBase/include/RenderDeviceD3DBase.h b/Graphics/GraphicsEngineD3DBase/include/RenderDeviceD3DBase.h
new file mode 100644
index 00000000..be7e940d
--- /dev/null
+++ b/Graphics/GraphicsEngineD3DBase/include/RenderDeviceD3DBase.h
@@ -0,0 +1,159 @@
+/* Copyright 2015-2016 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+/// \file
+/// Implementation of the Diligent::RenderDeviceBase template class and related structures
+
+#include "RenderDeviceBase.h"
+
+namespace Diligent
+{
+
+/// Base implementation of a D3D render device
+
+template<typename BaseInterface>
+class RenderDeviceD3DBase : public RenderDeviceBase<BaseInterface>
+{
+public:
+ RenderDeviceD3DBase(IMemoryAllocator &RawMemAllocator,
+ Uint32 NumDeferredContexts,
+ size_t TextureObjSize,
+ size_t TexViewObjSize,
+ size_t BufferObjSize,
+ size_t BuffViewObjSize,
+ size_t ShaderObjSize,
+ size_t SamplerObjSize,
+ size_t PSOSize,
+ size_t SRBSize) :
+ RenderDeviceBase<BaseInterface>(RawMemAllocator, NumDeferredContexts, TextureObjSize, TexViewObjSize, BufferObjSize, BuffViewObjSize, ShaderObjSize, SamplerObjSize, PSOSize, SRBSize)
+ {
+ // Flag texture formats always supported in D3D11 and D3D12
+
+#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);
+#undef FLAG_FORMAT
+ }
+};
+
+}
diff --git a/Graphics/GraphicsEngineD3DBase/include/ShaderD3DBase.h b/Graphics/GraphicsEngineD3DBase/include/ShaderD3DBase.h
new file mode 100644
index 00000000..0fd007fa
--- /dev/null
+++ b/Graphics/GraphicsEngineD3DBase/include/ShaderD3DBase.h
@@ -0,0 +1,45 @@
+/* Copyright 2015-2016 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+#include <d3dcommon.h>
+
+#include "Shader.h"
+
+/// \file
+/// Base implementation of a D3D shader
+
+namespace Diligent
+{
+ /// Base implementation of a D3D shader
+ class ShaderD3DBase
+ {
+ public:
+ ShaderD3DBase(const ShaderCreationAttribs &CreationAttribs);
+
+ protected:
+
+ CComPtr<ID3DBlob> m_pShaderByteCode;
+ };
+}
diff --git a/Graphics/GraphicsEngineD3DBase/include/ShaderResources.h b/Graphics/GraphicsEngineD3DBase/include/ShaderResources.h
new file mode 100644
index 00000000..ad63d64b
--- /dev/null
+++ b/Graphics/GraphicsEngineD3DBase/include/ShaderResources.h
@@ -0,0 +1,396 @@
+/* Copyright 2015-2016 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+/// \file
+/// Declaration of Diligent::ShaderResources class
+
+// ShaderResources class uses continuous chunk of memory to store all resources, as follows:
+//
+//
+// m_MemoryBuffer m_TexSRVOffset m_TexUAVOffset m_BufSRVOffset m_BufUAVOffset m_SamplersOffset m_MemorySize
+// | | | | | | |
+// | CB[0] ... CB[Ncb-1] | TexSRV[0] ... TexSRV[Ntsrv-1] | TexUAV[0] ... TexUAV[Ntuav-1] | BufSRV[0] ... BufSRV[Nbsrv-1] | BufUAV[0] ... BufUAV[Nbuav-1] | Sam[0] ... Sam[Nsam-1] |
+//
+// Ncb - number of constant buffers
+// Ntsrv - number of texture SRVs
+// Ntuav - number of texture UAVs
+// Nbsrv - number of buffer SRVs
+// Nbuav - number of buffer UAVs
+// Nsam - number of samplers
+//
+//
+// If texture SRV is assigned a sampler, it is referenced through SamplerId:
+//
+// _________________________SamplerId_______________________
+// | |
+// | V
+// | CBs | ... TexSRV[n] ... | TexUAVs | BufSRVs | BufUAVs | Sam[0] ... Sam[SamplerId] ... |
+//
+//
+
+#define NOMINMAX
+#include <d3dcommon.h>
+
+namespace Diligent
+{
+
+static const Char* D3DSamplerSuffix = "_sampler";
+
+inline bool IsAllowedType(SHADER_VARIABLE_TYPE VarType, Uint32 AllowedTypeBits)noexcept
+{
+ return ((1 << VarType) & AllowedTypeBits) != 0;
+}
+
+inline Uint32 GetAllowedTypeBits(const SHADER_VARIABLE_TYPE *AllowedVarTypes, Uint32 NumAllowedTypes)noexcept
+{
+ if(AllowedVarTypes == nullptr)
+ return 0xFFFFFFFF;
+
+ Uint32 AllowedTypeBits = 0;
+ for(Uint32 i=0; i < NumAllowedTypes; ++i)
+ AllowedTypeBits |= 1 << AllowedVarTypes[i];
+ return AllowedTypeBits;
+}
+
+
+struct D3DShaderResourceAttribs
+{
+ D3DShaderResourceAttribs(String &&_Name,
+ UINT _BindPoint,
+ UINT _BindCount,
+ D3D_SHADER_INPUT_TYPE _InputType,
+ SHADER_VARIABLE_TYPE _VariableType,
+ D3D_SRV_DIMENSION SRVDimension,
+ Uint32 SamplerId,
+ bool _IsStaticSampler) :
+ Name(std::move(_Name)),
+ BindPoint(static_cast<Uint16>(_BindPoint)),
+ BindCount(static_cast<Uint16>(_BindCount)),
+ PackedAttribs( PackAttribs(_InputType, _VariableType, SRVDimension, SamplerId, _IsStaticSampler) )
+ {
+ VERIFY( static_cast<Uint32>(_InputType) <= ShaderInputTypeMask, "Shader input type is out of expected range");
+ VERIFY( static_cast<Uint32>(_VariableType) <= VariableTypeMask, "Variable type is out of expected range");
+ VERIFY( static_cast<Uint32>(SRVDimension) <= SRVDimMask, "SRV dimensions is out of expected range");
+ VERIFY(SamplerId <= SamplerIdMask, "Sampler Id is out of allowed range" );
+ VERIFY_EXPR(GetInputType() == _InputType);
+ VERIFY_EXPR(GetVariableType() == _VariableType);
+ VERIFY(_BindPoint <= MaxBindPoint || _BindPoint == InvalidBindPoint, "Bind Point is out of allowed range" );
+ VERIFY(_BindCount <= MaxBindCount, "Bind Count is out of allowed range" );
+#ifdef _DEBUG
+ if(_InputType==D3D_SIT_SAMPLER)
+ {
+ VERIFY_EXPR(IsStaticSampler() == _IsStaticSampler);
+ }
+ else
+ {
+ VERIFY(!_IsStaticSampler, "Only samplers can be marked as static");
+ }
+
+ if (_InputType == D3D_SIT_TEXTURE)
+ {
+ VERIFY_EXPR(GetSamplerId() == SamplerId);
+ }
+ else
+ {
+ VERIFY(SamplerId == InvalidSamplerId, "Only textures can be assigned valid texture sampler")
+ }
+
+ if(_IsStaticSampler)
+ {
+ VERIFY( _InputType == D3D_SIT_SAMPLER, "Invalid input type: D3D_SIT_SAMPLER is expected" );
+ }
+#endif
+ }
+
+ D3DShaderResourceAttribs(const D3DShaderResourceAttribs& rhs) = default;
+
+ D3DShaderResourceAttribs(const D3DShaderResourceAttribs& rhs, Uint32 SamplerId)noexcept :
+ Name(rhs.Name),
+ BindPoint(rhs.BindPoint),
+ BindCount(rhs.BindCount),
+ PackedAttribs( PackAttribs(rhs.GetInputType(), rhs.GetVariableType(), rhs.GetSRVDimension(), SamplerId, false) )
+ {
+ VERIFY(GetInputType() == D3D_SIT_TEXTURE, "Only textures can be assigned a texture sampler");
+
+ VERIFY_EXPR(GetInputType() == rhs.GetInputType());
+ VERIFY_EXPR(GetVariableType() == rhs.GetVariableType());
+ VERIFY_EXPR(GetSamplerId() == SamplerId);
+ }
+
+ D3DShaderResourceAttribs(D3DShaderResourceAttribs&& rhs, Uint32 SamplerId)noexcept :
+ Name(std::move(rhs.Name)),
+ BindPoint(rhs.BindPoint),
+ BindCount(rhs.BindCount),
+ PackedAttribs( PackAttribs(rhs.GetInputType(), rhs.GetVariableType(), rhs.GetSRVDimension(), SamplerId, false) )
+ {
+ VERIFY(GetInputType() == D3D_SIT_TEXTURE, "Only textures can be assigned a texture sampler");
+
+ VERIFY_EXPR(GetInputType() == rhs.GetInputType());
+ VERIFY_EXPR(GetVariableType() == rhs.GetVariableType());
+ VERIFY_EXPR(GetSamplerId() == SamplerId);
+ }
+
+ D3DShaderResourceAttribs(D3DShaderResourceAttribs&& rhs)noexcept :
+ Name(std::move(rhs.Name)),
+ BindPoint(rhs.BindPoint),
+ BindCount(rhs.BindCount),
+ PackedAttribs( rhs.PackedAttribs )
+ {
+ }
+
+ D3D_SHADER_INPUT_TYPE GetInputType()const
+ {
+ return static_cast<D3D_SHADER_INPUT_TYPE>( (PackedAttribs >> ShaderInputTypeBitOffset) & ShaderInputTypeMask );
+ }
+
+ SHADER_VARIABLE_TYPE GetVariableType()const
+ {
+ return static_cast<SHADER_VARIABLE_TYPE>( (PackedAttribs >> VariableTypeBitOffset) & VariableTypeMask );
+ }
+
+ D3D_SRV_DIMENSION GetSRVDimension()const
+ {
+ return static_cast<D3D_SRV_DIMENSION>( (PackedAttribs >> SRVDimBitOffset) & SRVDimMask );
+ }
+
+ Uint32 GetSamplerId()const
+ {
+ VERIFY( GetInputType() == D3D_SIT_TEXTURE, "Invalid input type: D3D_SIT_TEXTURE is expected" );
+ return (PackedAttribs >> SamplerIdBitOffset) & SamplerIdMask;
+ }
+
+ bool IsStaticSampler()const
+ {
+ VERIFY( GetInputType() == D3D_SIT_SAMPLER, "Invalid input type: D3D_SIT_SAMPLER is expected" );
+ return (PackedAttribs & (1 << IsStaticSamplerFlagBitOffset)) != 0;
+ }
+
+ bool IsValidSampler()const
+ {
+ VERIFY( GetInputType() == D3D_SIT_TEXTURE, "Invalid input type: D3D_SIT_TEXTURE is expected" );
+ return GetSamplerId() != InvalidSamplerId;
+ }
+
+ bool IsValidBindPoint()const
+ {
+ return BindPoint != InvalidBindPoint;
+ }
+
+ static const Uint16 InvalidBindPoint = std::numeric_limits<Uint16>::max();
+
+ String Name; // Move ctor will not work if it is const
+ const Uint16 BindPoint;
+ const Uint16 BindCount;
+
+ String GetPrintName(Uint32 ArrayInd)const
+ {
+ VERIFY_EXPR(ArrayInd < BindCount);
+ if(BindCount > 1)
+ return String(Name) + '[' + std::to_string(ArrayInd) + ']';
+ else
+ return Name;
+ }
+private:
+ static const Uint16 MaxBindPoint = InvalidBindPoint-1;
+ static const Uint16 MaxBindCount = std::numeric_limits<Uint16>::max();
+
+ static const Uint32 ShaderInputTypeBits = 4; // Max value: D3D_SIT_UAV_RWSTRUCTURED_WITH_COUNTER==11
+ static const Uint32 ShaderInputTypeMask = (1 << ShaderInputTypeBits)-1;
+ static const Uint32 ShaderInputTypeBitOffset = 0;
+ static_assert( D3D_SIT_UAV_RWSTRUCTURED_WITH_COUNTER <= ShaderInputTypeMask, "Not enough bits to represent D3D_SHADER_INPUT_TYPE" );
+
+ static const Uint32 VariableTypeBits = 3; // Max value: SHADER_VARIABLE_TYPE_DYNAMIC == 2
+ static const Uint32 VariableTypeMask = (1<<VariableTypeBits)-1;
+ static const Uint32 VariableTypeBitOffset = ShaderInputTypeBitOffset + ShaderInputTypeBits;
+ static_assert( SHADER_VARIABLE_TYPE_NUM_TYPES-1 <= VariableTypeMask, "Not enough bits to represent SHADER_VARIABLE_TYPE" );
+
+ static const Uint32 SRVDimBits = 4; // Max value: D3D_SRV_DIMENSION_BUFFEREX == 11
+ static const Uint32 SRVDimMask = (1<<SRVDimBits)-1;
+ static const Uint32 SRVDimBitOffset = VariableTypeBitOffset + VariableTypeBits;
+ static_assert( D3D_SRV_DIMENSION_BUFFEREX <= SRVDimMask, "Not enough bits to represent D3D_SRV_DIMENSION" );
+
+ static const Uint32 SamplerIdBits = 32 - 1 - ShaderInputTypeBits - VariableTypeBits - SRVDimBits;
+ static const Uint32 SamplerIdMask = (1 << SamplerIdBits) - 1;
+ static const Uint32 SamplerIdBitOffset = SRVDimBitOffset + SRVDimBits;
+public:
+ static const Uint32 InvalidSamplerId = SamplerIdMask;
+private:
+
+ static const Uint32 IsStaticSamplerFlagBits = 1;
+ static const Uint32 IsStaticSamplerFlagMask = (1 << IsStaticSamplerFlagBits) - 1;
+ static const Uint32 IsStaticSamplerFlagBitOffset = SamplerIdBitOffset + SamplerIdBits;
+ static_assert(IsStaticSamplerFlagBitOffset == 31, "Unexpected static sampler flag offset");
+
+ static Uint32 PackAttribs(D3D_SHADER_INPUT_TYPE _InputType, SHADER_VARIABLE_TYPE _VariableType, D3D_SRV_DIMENSION SRVDimension, Uint32 SamplerId, bool _IsStaticSampler)
+ {
+ return ((static_cast<Uint32>(_InputType) & ShaderInputTypeMask) << ShaderInputTypeBitOffset) |
+ ((static_cast<Uint32>(_VariableType) & VariableTypeMask) << VariableTypeBitOffset ) |
+ ((static_cast<Uint32>(SRVDimension) & SRVDimMask) << SRVDimBitOffset) |
+ ((SamplerId & SamplerIdMask) << SamplerIdBitOffset) |
+ ((_IsStaticSampler ? 1 : 0) << IsStaticSamplerFlagBitOffset);
+ }
+
+ // 4 3 4 20 1
+ // bit | 0 1 2 3 | 4 5 6 | 7 8 9 10 | 11 12 ... 30 | 31 |
+ // | | | | | |
+ // | InputType | VariableType | SRV Dim | SamplerId | StaticSamplerFlag |
+ const Uint32 PackedAttribs;
+};
+
+/// Diligent::ShaderResources class
+class ShaderResources
+{
+public:
+ ShaderResources(IMemoryAllocator &Allocator, SHADER_TYPE ShaderType);
+
+ // Copies specified types of resources from another ShaderResources objects
+ ShaderResources(IMemoryAllocator &Allocator,
+ const ShaderResources& SrcResources,
+ const SHADER_VARIABLE_TYPE *AllowedVarTypes,
+ Uint32 NumAllowedTypes);
+
+ ShaderResources (const ShaderResources&) = delete;
+ ShaderResources (ShaderResources&&) = delete;
+ ShaderResources& operator = (const ShaderResources&) = delete;
+ ShaderResources& operator = (ShaderResources&&) = delete;
+
+ ~ShaderResources();
+
+ Uint32 GetNumCBs() const noexcept{ return (m_TexSRVOffset - 0); }
+ Uint32 GetNumTexSRV() const noexcept{ return (m_TexUAVOffset - m_TexSRVOffset); }
+ Uint32 GetNumTexUAV() const noexcept{ return (m_BufSRVOffset - m_TexUAVOffset); }
+ Uint32 GetNumBufSRV() const noexcept{ return (m_BufUAVOffset - m_BufSRVOffset); }
+ Uint32 GetNumBufUAV() const noexcept{ return (m_SamplersOffset - m_BufUAVOffset); }
+ Uint32 GetNumSamplers()const noexcept{ return (m_BufferEndOffset- m_SamplersOffset); }
+
+ const D3DShaderResourceAttribs& GetCB (Uint32 n)const noexcept{ return GetResAttribs(n, GetNumCBs(), 0); }
+ const D3DShaderResourceAttribs& GetTexSRV (Uint32 n)const noexcept{ return GetResAttribs(n, GetNumTexSRV(), m_TexSRVOffset); }
+ const D3DShaderResourceAttribs& GetTexUAV (Uint32 n)const noexcept{ return GetResAttribs(n, GetNumTexUAV(), m_TexUAVOffset); }
+ const D3DShaderResourceAttribs& GetBufSRV (Uint32 n)const noexcept{ return GetResAttribs(n, GetNumBufSRV(), m_BufSRVOffset); }
+ const D3DShaderResourceAttribs& GetBufUAV (Uint32 n)const noexcept{ return GetResAttribs(n, GetNumBufUAV(), m_BufUAVOffset); }
+ const D3DShaderResourceAttribs& GetSampler(Uint32 n)const noexcept{ return GetResAttribs(n, GetNumSamplers(), m_SamplersOffset); }
+
+
+ void CountResources(const SHADER_VARIABLE_TYPE *AllowedVarTypes, Uint32 NumAllowedTypes,
+ Uint32& NumCBs, Uint32& NumTexSRVs, Uint32& NumTexUAVs,
+ Uint32& NumBufSRVs, Uint32& NumBufUAVs, Uint32& NumSamplers)const noexcept;
+
+ SHADER_TYPE GetShaderType()const noexcept{return m_ShaderType;}
+
+ template<typename THandleCB,
+ typename THandleTexSRV,
+ typename THandleTexUAV,
+ typename THandleBufSRV,
+ typename THandleBufUAV>
+ void ProcessResources(const SHADER_VARIABLE_TYPE *AllowedVarTypes,
+ Uint32 NumAllowedTypes,
+ THandleCB HandleCB,
+ THandleTexSRV HandleTexSRV,
+ THandleTexUAV HandleTexUAV,
+ THandleBufSRV HandleBufSRV,
+ THandleBufUAV HandleBufUAV)const
+ {
+ Uint32 AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes);
+
+ for(Uint32 n=0; n < GetNumCBs(); ++n)
+ {
+ const auto& CB = GetCB(n);
+ if( IsAllowedType(CB.GetVariableType(), AllowedTypeBits) )
+ HandleCB(CB);
+ }
+
+ for(Uint32 n=0; n < GetNumTexSRV(); ++n)
+ {
+ const auto &TexSRV = GetTexSRV(n);
+ if( IsAllowedType(TexSRV.GetVariableType(), AllowedTypeBits) )
+ HandleTexSRV(TexSRV);
+ }
+
+ for(Uint32 n=0; n < GetNumTexUAV(); ++n)
+ {
+ const auto &TexUAV = GetTexUAV(n);
+ if( IsAllowedType(TexUAV.GetVariableType(), AllowedTypeBits) )
+ HandleTexUAV(TexUAV);
+ }
+
+ for(Uint32 n=0; n < GetNumBufSRV(); ++n)
+ {
+ const auto &BufSRV = GetBufSRV(n);
+ if( IsAllowedType(BufSRV.GetVariableType(), AllowedTypeBits) )
+ HandleBufSRV(BufSRV);
+ }
+
+ for(Uint32 n=0; n < GetNumBufUAV(); ++n)
+ {
+ const auto& BufUAV = GetBufUAV(n);
+ if( IsAllowedType(BufUAV.GetVariableType(), AllowedTypeBits) )
+ HandleBufUAV(BufUAV);
+ }
+ }
+
+protected:
+ void Initialize(IMemoryAllocator &Allocator, Uint32 NumCBs, Uint32 NumTexSRVs, Uint32 NumTexUAVs, Uint32 NumBufSRVs, Uint32 NumBufUAVs, Uint32 NumSamplers);
+
+ __forceinline D3DShaderResourceAttribs& GetResAttribs(Uint32 n, Uint32 NumResources, Uint32 Offset)noexcept
+ {
+ VERIFY(n < NumResources, "Resource index (", n, ") is out of range. Max allowed index: ", NumResources-1);
+ VERIFY_EXPR(Offset + n < m_BufferEndOffset);
+ return reinterpret_cast<D3DShaderResourceAttribs*>(m_MemoryBuffer.get())[Offset + n];
+ }
+
+ __forceinline const D3DShaderResourceAttribs& GetResAttribs(Uint32 n, Uint32 NumResources, Uint32 Offset)const noexcept
+ {
+ VERIFY(n < NumResources, "Resource index (", n, ") is out of range. Max allowed index: ", NumResources-1);
+ VERIFY_EXPR(Offset + n < m_BufferEndOffset);
+ return reinterpret_cast<D3DShaderResourceAttribs*>(m_MemoryBuffer.get())[Offset + n];
+ }
+
+ D3DShaderResourceAttribs& GetCB (Uint32 n)noexcept{ return GetResAttribs(n, GetNumCBs(), 0); }
+ D3DShaderResourceAttribs& GetTexSRV (Uint32 n)noexcept{ return GetResAttribs(n, GetNumTexSRV(), m_TexSRVOffset); }
+ D3DShaderResourceAttribs& GetTexUAV (Uint32 n)noexcept{ return GetResAttribs(n, GetNumTexUAV(), m_TexUAVOffset); }
+ D3DShaderResourceAttribs& GetBufSRV (Uint32 n)noexcept{ return GetResAttribs(n, GetNumBufSRV(), m_BufSRVOffset); }
+ D3DShaderResourceAttribs& GetBufUAV (Uint32 n)noexcept{ return GetResAttribs(n, GetNumBufUAV(), m_BufUAVOffset); }
+ D3DShaderResourceAttribs& GetSampler(Uint32 n)noexcept{ return GetResAttribs(n, GetNumSamplers(), m_SamplersOffset); }
+
+ Uint32 FindAssignedSamplerId(const D3DShaderResourceAttribs& TexSRV)const;
+
+private:
+ // Memory buffer that holds all resources as continuous chunk of memory:
+ // | CBs | TexSRVs | TexUAVs | BufSRVs | BufUAVs | Samplers |
+ std::unique_ptr< void, STDDeleterRawMem<void> > m_MemoryBuffer;
+
+ // Offsets in elements of D3DShaderResourceAttribs
+ typedef Uint16 OffsetType;
+ OffsetType m_TexSRVOffset = 0;
+ OffsetType m_TexUAVOffset = 0;
+ OffsetType m_BufSRVOffset = 0;
+ OffsetType m_BufUAVOffset = 0;
+ OffsetType m_SamplersOffset = 0;
+ OffsetType m_BufferEndOffset = 0;
+
+ SHADER_TYPE m_ShaderType = SHADER_TYPE_UNKNOWN;
+};
+
+}
diff --git a/Graphics/GraphicsEngineD3DBase/include/ShaderVariableD3DBase.h b/Graphics/GraphicsEngineD3DBase/include/ShaderVariableD3DBase.h
new file mode 100644
index 00000000..6a8372bb
--- /dev/null
+++ b/Graphics/GraphicsEngineD3DBase/include/ShaderVariableD3DBase.h
@@ -0,0 +1,75 @@
+/* Copyright 2015-2016 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+#include "Shader.h"
+
+/// \file
+/// Declaration of Diligent::ShaderVariableD3DBase class
+
+namespace Diligent
+{
+ template<typename TShaderResourceLayout>
+ struct ShaderVariableD3DBase : public IShaderVariable
+ {
+ ShaderVariableD3DBase(TShaderResourceLayout &ParentResLayout, const D3DShaderResourceAttribs &ResourcesAttribs) :
+ m_ParentResLayout(ParentResLayout),
+ Attribs(ResourcesAttribs)
+ {
+ }
+
+ virtual IReferenceCounters* GetReferenceCounters()const override final
+ {
+ return m_ParentResLayout.GetOwner().GetReferenceCounters();
+ }
+
+ virtual Atomics::Long AddRef()override final
+ {
+ return m_ParentResLayout.GetOwner().AddRef();
+ }
+
+ virtual Atomics::Long Release()override final
+ {
+ return m_ParentResLayout.GetOwner().Release();
+ }
+
+ void QueryInterface( const INTERFACE_ID &IID, IObject **ppInterface )override final
+ {
+ if( ppInterface == nullptr )
+ return;
+
+ *ppInterface = nullptr;
+ if( IID == IID_ShaderVariable || IID == IID_Unknown )
+ {
+ *ppInterface = this;
+ (*ppInterface)->AddRef();
+ }
+ }
+
+ const D3DShaderResourceAttribs &Attribs;
+
+ protected:
+ TShaderResourceLayout &m_ParentResLayout;
+ };
+}
diff --git a/Graphics/GraphicsEngineD3DBase/src/DXGITypeConversions.cpp b/Graphics/GraphicsEngineD3DBase/src/DXGITypeConversions.cpp
new file mode 100644
index 00000000..39c92997
--- /dev/null
+++ b/Graphics/GraphicsEngineD3DBase/src/DXGITypeConversions.cpp
@@ -0,0 +1,406 @@
+/* Copyright 2015-2016 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#include "DXGITypeConversions.h"
+#include "BasicTypes.h"
+#include "DebugUtilities.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_D24_UNORM_S8_UINT:
+ case DXGI_FORMAT_R24_UNORM_X8_TYPELESS:
+ case DXGI_FORMAT_X24_TYPELESS_G8_UINT:
+ DXGIFormat = DXGI_FORMAT_R24G8_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_TYPELESS:
+ case DXGI_FORMAT_R32_FLOAT:
+ DXGIFormat = DXGI_FORMAT_D32_FLOAT;
+ break;
+
+ case DXGI_FORMAT_R24G8_TYPELESS:
+ case DXGI_FORMAT_R24_UNORM_X8_TYPELESS:
+ case DXGI_FORMAT_X24_TYPELESS_G8_UINT:
+ DXGIFormat = DXGI_FORMAT_D24_UNORM_S8_UINT;
+ break;
+
+ case DXGI_FORMAT_R16_TYPELESS:
+ 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_R32_TYPELESS:
+ case DXGI_FORMAT_D32_FLOAT:
+ DXGIFormat = DXGI_FORMAT_R32_FLOAT;
+ break;
+
+ case DXGI_FORMAT_R24G8_TYPELESS:
+ case DXGI_FORMAT_D24_UNORM_S8_UINT:
+ case DXGI_FORMAT_X24_TYPELESS_G8_UINT:
+ DXGIFormat = DXGI_FORMAT_R24_UNORM_X8_TYPELESS;
+ break;
+
+ case DXGI_FORMAT_R16_TYPELESS:
+ 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;
+ }
+}
+
+}
diff --git a/Graphics/GraphicsEngineD3DBase/src/ShaderD3DBase.cpp b/Graphics/GraphicsEngineD3DBase/src/ShaderD3DBase.cpp
new file mode 100644
index 00000000..9650fba3
--- /dev/null
+++ b/Graphics/GraphicsEngineD3DBase/src/ShaderD3DBase.cpp
@@ -0,0 +1,198 @@
+/* Copyright 2015-2016 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#include <unordered_map>
+#include <D3Dcompiler.h>
+
+#include "D3DErrors.h"
+#include "DataBlobImpl.h"
+#include "RefCntAutoPtr.h"
+#include <atlcomcli.h>
+#include "ShaderD3DBase.h"
+
+namespace Diligent
+{
+
+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;
+};
+
+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();
+ OutputDebugStringW( ErrorDesc.c_str() );
+ if( FAILED(hr)
+#ifdef PLATFORM_WIN32
+ && IDRETRY != MessageBoxW( 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)
+{
+ switch(DXProfile)
+ {
+ case SHADER_PROFILE_DX_4_0: return "4_0";
+ case SHADER_PROFILE_DX_5_0: return "5_0";
+ case SHADER_PROFILE_DX_5_1: return "5_1";
+ //default: UNEXPECTED("Unknown DirectX shader profile" ); return "";
+ default: return "5_0";
+ }
+}
+
+ShaderD3DBase::ShaderD3DBase(const ShaderCreationAttribs &CreationAttribs)
+{
+ std::string strShaderProfile;
+ switch(CreationAttribs.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(CreationAttribs.Desc.TargetProfile);
+ strShaderProfile += pProfileSuffix;
+
+ String ShaderSource(g_HLSLDefinitions);
+ if( CreationAttribs.Source )
+ ShaderSource.append( CreationAttribs.Source );
+ else
+ {
+ VERIFY(CreationAttribs.pShaderSourceStreamFactory, "Input stream factory is null");
+ VERIFY(CreationAttribs.FilePath, "File path is null. Either shader source or source file path must be specified.");
+ RefCntAutoPtr<IFileStream> pSourceStream;
+ CreationAttribs.pShaderSourceStreamFactory->CreateInputStream( CreationAttribs.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( CreationAttribs.Macros )
+ {
+ for( auto* pCurrMacro = CreationAttribs.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(), CreationAttribs.EntryPoint, pDefines, CreationAttribs.pShaderSourceStreamFactory, strShaderProfile.c_str(), &m_pShaderByteCode ),
+ "Failed to compile the shader");
+}
+
+}
diff --git a/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp b/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp
new file mode 100644
index 00000000..dd3b691c
--- /dev/null
+++ b/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp
@@ -0,0 +1,219 @@
+/* Copyright 2015-2016 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#include "pch.h"
+#include "StringTools.h"
+#include "ShaderResources.h"
+
+namespace Diligent
+{
+
+ShaderResources::~ShaderResources()
+{
+ for(Uint32 n=0; n < GetNumCBs(); ++n)
+ GetCB(n).~D3DShaderResourceAttribs();
+
+ for(Uint32 n=0; n < GetNumTexSRV(); ++n)
+ GetTexSRV(n).~D3DShaderResourceAttribs();
+
+ for(Uint32 n=0; n < GetNumTexUAV(); ++n)
+ GetTexUAV(n).~D3DShaderResourceAttribs();
+
+ for(Uint32 n=0; n < GetNumBufSRV(); ++n)
+ GetBufSRV(n).~D3DShaderResourceAttribs();
+
+ for(Uint32 n=0; n < GetNumBufUAV(); ++n)
+ GetBufUAV(n).~D3DShaderResourceAttribs();
+
+ for(Uint32 n=0; n < GetNumSamplers(); ++n)
+ GetSampler(n).~D3DShaderResourceAttribs();
+}
+
+void ShaderResources::Initialize(IMemoryAllocator &Allocator, Uint32 NumCBs, Uint32 NumTexSRVs, Uint32 NumTexUAVs, Uint32 NumBufSRVs, Uint32 NumBufUAVs, Uint32 NumSamplers)
+{
+ VERIFY( &m_MemoryBuffer.get_deleter().m_Allocator == &Allocator, "Incosistent allocators provided");
+
+ const auto MaxOffset = static_cast<Uint32>(std::numeric_limits<OffsetType>::max());
+ VERIFY(NumCBs <= MaxOffset, "Max offset exceeded");
+ m_TexSRVOffset = 0 + static_cast<OffsetType>(NumCBs);
+
+ VERIFY(m_TexSRVOffset + NumTexSRVs <= MaxOffset, "Max offset exceeded");
+ m_TexUAVOffset = m_TexSRVOffset + static_cast<OffsetType>(NumTexSRVs);
+
+ VERIFY(m_TexUAVOffset + NumTexUAVs <= MaxOffset, "Max offset exceeded");
+ m_BufSRVOffset = m_TexUAVOffset + static_cast<OffsetType>(NumTexUAVs);
+
+ VERIFY(m_BufSRVOffset + NumBufSRVs <= MaxOffset, "Max offset exceeded");
+ m_BufUAVOffset = m_BufSRVOffset + static_cast<OffsetType>(NumBufSRVs);
+
+ VERIFY(m_BufUAVOffset + NumBufUAVs <= MaxOffset, "Max offset exceeded");
+ m_SamplersOffset = m_BufUAVOffset + static_cast<OffsetType>(NumBufUAVs);
+
+ VERIFY(m_SamplersOffset + NumSamplers<= MaxOffset, "Max offset exceeded");
+ m_BufferEndOffset = m_SamplersOffset + static_cast<OffsetType>(NumSamplers);
+
+ auto MemorySize = m_BufferEndOffset * sizeof(D3DShaderResourceAttribs);
+
+ VERIFY_EXPR(GetNumCBs() == NumCBs);
+ VERIFY_EXPR(GetNumTexSRV() == NumTexSRVs);
+ VERIFY_EXPR(GetNumTexUAV() == NumTexUAVs);
+ VERIFY_EXPR(GetNumBufSRV() == NumBufSRVs);
+ VERIFY_EXPR(GetNumBufUAV() == NumBufUAVs);
+ VERIFY_EXPR(GetNumSamplers()== NumSamplers);
+
+ if( MemorySize )
+ {
+ auto *pRawMem = ALLOCATE(Allocator, "Allocator for shader resources", MemorySize );
+ m_MemoryBuffer.reset(pRawMem);
+ }
+}
+
+ShaderResources::ShaderResources(IMemoryAllocator &Allocator, SHADER_TYPE ShaderType):
+ m_MemoryBuffer(nullptr, STDDeleterRawMem<void>(Allocator)),
+ m_ShaderType(ShaderType)
+{
+}
+
+void ShaderResources::CountResources(const SHADER_VARIABLE_TYPE *AllowedVarTypes, Uint32 NumAllowedTypes,
+ Uint32& NumCBs, Uint32& NumTexSRVs, Uint32& NumTexUAVs,
+ Uint32& NumBufSRVs, Uint32& NumBufUAVs, Uint32& NumSamplers)const noexcept
+{
+ Uint32 AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes);
+
+ NumCBs = 0;
+ NumTexSRVs = 0;
+ NumTexUAVs = 0;
+ NumBufSRVs = 0;
+ NumBufUAVs = 0;
+ NumSamplers = 0;
+ ProcessResources(
+ AllowedVarTypes, NumAllowedTypes,
+
+ [&](const D3DShaderResourceAttribs &CB)
+ {
+ VERIFY_EXPR(IsAllowedType(CB.GetVariableType(), AllowedTypeBits));
+ ++NumCBs;
+ },
+ [&](const D3DShaderResourceAttribs& TexSRV)
+ {
+ VERIFY_EXPR(IsAllowedType(TexSRV.GetVariableType(), AllowedTypeBits));
+ ++NumTexSRVs;
+ NumSamplers += TexSRV.IsValidSampler() ? 1 : 0;
+ },
+ [&](const D3DShaderResourceAttribs &TexUAV)
+ {
+ VERIFY_EXPR(IsAllowedType(TexUAV.GetVariableType(), AllowedTypeBits));
+ ++NumTexUAVs;
+ },
+ [&](const D3DShaderResourceAttribs &BufSRV)
+ {
+ VERIFY_EXPR(IsAllowedType(BufSRV.GetVariableType(), AllowedTypeBits));
+ ++NumBufSRVs;
+ },
+ [&](const D3DShaderResourceAttribs &BufUAV)
+ {
+ VERIFY_EXPR(IsAllowedType(BufUAV.GetVariableType(), AllowedTypeBits));
+ ++NumBufUAVs;
+ }
+ );
+}
+
+ShaderResources::ShaderResources(IMemoryAllocator &Allocator,
+ const ShaderResources& SrcResources,
+ const SHADER_VARIABLE_TYPE *AllowedVarTypes,
+ Uint32 NumAllowedTypes) :
+ m_MemoryBuffer(nullptr, STDDeleterRawMem<void>(Allocator)),
+ m_ShaderType(SrcResources.m_ShaderType)
+{
+ Uint32 NumCBs = 0, NumTexSRVs = 0, NumTexUAVs = 0, NumBufSRVs = 0, NumBufUAVs = 0, NumSamplers = 0;
+ SrcResources.CountResources(AllowedVarTypes, NumAllowedTypes, NumCBs, NumTexSRVs, NumTexUAVs, NumBufSRVs, NumBufUAVs, NumSamplers);
+
+ Initialize(Allocator, NumCBs, NumTexSRVs, NumTexUAVs, NumBufSRVs, NumBufUAVs, NumSamplers);
+
+ Uint32 AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes);
+
+ Uint32 CurrCB = 0, CurrTexSRV = 0, CurrTexUAV = 0, CurrBufSRV = 0, CurrBufUAV = 0, CurrSampler = 0;
+ ProcessResources(
+ AllowedVarTypes, NumAllowedTypes,
+
+ [&](const D3DShaderResourceAttribs &CB)
+ {
+ VERIFY_EXPR( IsAllowedType(CB.GetVariableType(), AllowedTypeBits) );
+ new (&GetCB(CurrCB++)) D3DShaderResourceAttribs(CB);
+ },
+ [&](const D3DShaderResourceAttribs& TexSRV)
+ {
+ VERIFY_EXPR(IsAllowedType(TexSRV.GetVariableType(), AllowedTypeBits));
+
+ auto SamplerId = D3DShaderResourceAttribs::InvalidSamplerId;
+ if (TexSRV.IsValidSampler())
+ {
+ SamplerId = CurrSampler;
+ new (&GetSampler(CurrSampler++)) D3DShaderResourceAttribs(SrcResources.GetSampler(TexSRV.GetSamplerId()));
+ }
+
+ new (&GetTexSRV(CurrTexSRV++)) D3DShaderResourceAttribs(TexSRV, SamplerId);
+ },
+ [&](const D3DShaderResourceAttribs &TexUAV)
+ {
+ VERIFY_EXPR( IsAllowedType(TexUAV.GetVariableType(), AllowedTypeBits) );
+ new (&GetTexUAV(CurrTexUAV++)) D3DShaderResourceAttribs(TexUAV);
+ },
+ [&](const D3DShaderResourceAttribs &BufSRV)
+ {
+ VERIFY_EXPR( IsAllowedType(BufSRV.GetVariableType(), AllowedTypeBits) );
+ new (&GetBufSRV(CurrBufSRV++)) D3DShaderResourceAttribs(BufSRV);
+ },
+ [&](const D3DShaderResourceAttribs &BufUAV)
+ {
+ VERIFY_EXPR( IsAllowedType(BufUAV.GetVariableType(), AllowedTypeBits) );
+ new (&GetBufUAV(CurrBufUAV++)) D3DShaderResourceAttribs(BufUAV);
+ }
+ );
+
+ VERIFY_EXPR(CurrCB == NumCBs);
+ VERIFY_EXPR(CurrTexSRV == NumTexSRVs );
+ VERIFY_EXPR(CurrTexUAV == NumTexUAVs );
+ VERIFY_EXPR(CurrBufSRV == NumBufSRVs );
+ VERIFY_EXPR(CurrBufUAV == NumBufUAVs );
+ VERIFY_EXPR(CurrSampler == NumSamplers );
+}
+
+Uint32 ShaderResources::FindAssignedSamplerId(const D3DShaderResourceAttribs& TexSRV)const
+{
+ VERIFY_EXPR(TexSRV.GetInputType() == D3D_SIT_TEXTURE);
+ auto NumSamplers = GetNumSamplers();
+ for (Uint32 s = 0; s < NumSamplers; ++s)
+ {
+ const auto &Sampler = GetSampler(s);
+ if( StrCmpSuff(Sampler.Name.c_str(), TexSRV.Name.c_str(), D3DSamplerSuffix) )
+ {
+ VERIFY(Sampler.GetVariableType() == TexSRV.GetVariableType(), "Inconsistent texture and sampler variable types")
+ VERIFY(Sampler.BindCount == TexSRV.BindCount || Sampler.BindCount == 1, "Sampler assigned to array \"", TexSRV.Name, "\" is expected to be scalar or have the same dimension (",TexSRV.BindCount,"). Actual sampler array dimension : ", Sampler.BindCount)
+ return s;
+ }
+ }
+ return D3DShaderResourceAttribs::InvalidSamplerId;
+}
+
+}