Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
GraphicsDeviceFeatures.Direct3D.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 #if SILICONSTUDIO_PARADOX_GRAPHICS_API_DIRECT3D
4 // Copyright (c) 2010-2012 SharpDX - Alexandre Mutel
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to deal
8 // in the Software without restriction, including without limitation the rights
9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 // THE SOFTWARE.
23 
24 using System;
25 using System.Collections.Generic;
26 using SharpDX.DXGI;
27 using SharpDX.Direct3D;
28 using SharpDX.Direct3D11;
29 
30 namespace SiliconStudio.Paradox.Graphics
31 {
32  /// <summary>
33  /// Features supported by a <see cref="GraphicsDevice"/>.
34  /// </summary>
35  /// <remarks>
36  /// This class gives also features for a particular format, using the operator this[dxgiFormat] on this structure.
37  /// </remarks>
38  public partial struct GraphicsDeviceFeatures
39  {
40  private readonly static List<SharpDX.DXGI.Format> ObsoleteFormatToExcludes = new List<SharpDX.DXGI.Format>() { Format.R1_UNorm, Format.B5G6R5_UNorm, Format.B5G5R5A1_UNorm };
41 
42  internal GraphicsDeviceFeatures(GraphicsDevice deviceRoot)
43  {
44  var nativeDevice = deviceRoot.NativeDevice;
45 
46  mapFeaturesPerFormat = new FeaturesPerFormat[256];
47 
48  // Set back the real GraphicsProfile that is used
49  Profile = GraphicsProfileHelper.FromFeatureLevel(nativeDevice.FeatureLevel);
50 
51 #if SILICONSTUDIO_PLATFORM_WINDOWS_DESKTOP
52  IsProfiled = PixHelper.IsCurrentlyProfiled;
53 #else
54  IsProfiled = false;
55 #endif
56 
57  HasComputeShaders = nativeDevice.CheckFeatureSupport(Feature.ComputeShaders);
58  HasDoublePrecision = nativeDevice.CheckFeatureSupport(Feature.ShaderDoubles);
59  nativeDevice.CheckThreadingSupport(out HasMultiThreadingConcurrentResources, out this.HasDriverCommandLists);
60 
61  // Check features for each DXGI.Format
62  foreach (var format in Enum.GetValues(typeof(SharpDX.DXGI.Format)))
63  {
64  var dxgiFormat = (SharpDX.DXGI.Format)format;
65  var maximumMSAA = MSAALevel.None;
66  var computeShaderFormatSupport = ComputeShaderFormatSupport.None;
67  var formatSupport = FormatSupport.None;
68 
69  if (!ObsoleteFormatToExcludes.Contains(dxgiFormat))
70  {
71  maximumMSAA = GetMaximumMSAASampleCount(nativeDevice, dxgiFormat);
72  if (HasComputeShaders)
73  computeShaderFormatSupport = nativeDevice.CheckComputeShaderFormatSupport(dxgiFormat);
74 
75  formatSupport = (FormatSupport)nativeDevice.CheckFormatSupport(dxgiFormat);
76  }
77 
78  //mapFeaturesPerFormat[(int)dxgiFormat] = new FeaturesPerFormat((PixelFormat)dxgiFormat, maximumMSAA, computeShaderFormatSupport, formatSupport);
79  mapFeaturesPerFormat[(int)dxgiFormat] = new FeaturesPerFormat((PixelFormat)dxgiFormat, maximumMSAA, formatSupport);
80  }
81  }
82 
83  /// <summary>
84  /// Gets the maximum MSAA sample count for a particular <see cref="PixelFormat" />.
85  /// </summary>
86  /// <param name="device">The device.</param>
87  /// <param name="pixelFormat">The pixelFormat.</param>
88  /// <returns>The maximum multisample count for this pixel pixelFormat</returns>
89  private static MSAALevel GetMaximumMSAASampleCount(SharpDX.Direct3D11.Device device, SharpDX.DXGI.Format pixelFormat)
90  {
91  int maxCount = 1;
92  for (int i = 1; i <= 8; i *= 2)
93  {
94  if (device.CheckMultisampleQualityLevels(pixelFormat, i) != 0)
95  maxCount = i;
96  }
97  return (MSAALevel)maxCount;
98  }
99  }
100 }
101 #endif
MSAALevel
Multisample count level.
Definition: MSAALevel.cs:29
_In_ size_t _In_ size_t _In_ DXGI_FORMAT format
Definition: DirectXTexP.h:175
PixelFormat
Defines various types of pixel formats.
Definition: PixelFormat.cs:32