Esempio n. 1
0
        internal DeviceFeatures(Device device)
        {
            mapFeaturesPerFormat = new FeaturesPerFormat[256];

            // Check global features
            level              = device.FeatureLevel;
            hasComputeShaders  = device.CheckFeatureSupport(Feature.ComputeShaders);
            hasDoublePrecision = device.CheckFeatureSupport(Feature.ShaderDoubles);
            device.CheckThreadingSupport(out hasMultiThreadingConcurrentResources, out hasDriverCommandLists);

            // Check features for each DXGI.Format
            foreach (var format in Enum.GetValues(typeof(Format)))
            {
                var dxgiFormat  = (Format)format;
                var maximumMSAA = MSAALevel.None;
                var computeShaderFormatSupport = ComputeShaderFormatSupport.None;
                var formatSupport = FormatSupport.None;

                if (!ObsoleteFormatToExcludes.Contains(dxgiFormat))
                {
                    maximumMSAA = GetMaximumMSAASampleCount(device, dxgiFormat);
                    if (hasComputeShaders)
                    {
                        computeShaderFormatSupport = device.CheckComputeShaderFormatSupport(dxgiFormat);
                    }

                    formatSupport = device.CheckFormatSupport(dxgiFormat);
                }

                mapFeaturesPerFormat[(int)dxgiFormat] = new FeaturesPerFormat(dxgiFormat, maximumMSAA, computeShaderFormatSupport, formatSupport);
            }
        }
Esempio n. 2
0
        private Device()
        {
            DeviceCreationFlags flags = DeviceCreationFlags.DisableGpuTimeout;

#if DEBUG
            flags |= DeviceCreationFlags.Debug;
#endif
            // create 11.1 if possible (disable gpu timeout) but 11.0 is also fine
            Handle = new SharpDX.Direct3D11.Device(DriverType.Hardware, flags, new FeatureLevel[] { FeatureLevel.Level_11_1, FeatureLevel.Level_11_0 });

            // obtain the factory that created the device
            var obj     = Handle.QueryInterface <SharpDX.DXGI.Device>();
            var adapter = obj.Adapter;
            FactoryHandle = adapter.GetParent <SharpDX.DXGI.Factory>();
            context       = Handle.ImmediateContext;

            SetDefaults();
            SupportsDouble = Handle.CheckFeatureSupport(SharpDX.Direct3D11.Feature.ShaderDoubles);
        }
Esempio n. 3
0
        public D3D11GraphicsDevice(D3D11DeviceOptions options, SwapchainDescription?swapchainDesc)
        {
            var flags = (DeviceCreationFlags)options.DeviceCreationFlags;

#if DEBUG
            flags |= DeviceCreationFlags.Debug;
#endif
            // If debug flag set but SDK layers aren't available we can't enable debug.
            if (0 != (flags & DeviceCreationFlags.Debug) && !SdkLayersAvailable)
            {
                flags &= ~DeviceCreationFlags.Debug;
            }

            try
            {
                if (options.AdapterPtr != IntPtr.Zero)
                {
                    _dxgiAdapter = new Adapter(options.AdapterPtr);
                    _device      = new SharpDX.Direct3D11.Device(_dxgiAdapter,
                                                                 flags,
                                                                 SharpDX.Direct3D.FeatureLevel.Level_11_1);
                }
                else
                {
                    _device = new SharpDX.Direct3D11.Device(
                        SharpDX.Direct3D.DriverType.Hardware,
                        flags,
                        SharpDX.Direct3D.FeatureLevel.Level_11_1);
                }
            }
            catch (SharpDXException)
            {
                _device = new SharpDX.Direct3D11.Device(SharpDX.Direct3D.DriverType.Hardware, flags);
            }

            using (var dxgiDevice = _device.QueryInterface <SharpDX.DXGI.Device>())
            {
                // Store a pointer to the DXGI adapter.
                // This is for the case of no preferred DXGI adapter, or fallback to WARP.
                _dxgiAdapter = dxgiDevice.Adapter;
            }

            if (swapchainDesc != null)
            {
                SwapchainDescription desc = swapchainDesc.Value;
                _mainSwapchain = new D3D11Swapchain(_device, ref desc);
            }
            _immediateContext = _device.ImmediateContext;
            _device.CheckThreadingSupport(out _supportsConcurrentResources, out _supportsCommandLists);

            Features = new GraphicsDeviceFeatures(
                computeShader: true,
                geometryShader: true,
                tessellationShaders: true,
                multipleViewports: true,
                samplerLodBias: true,
                drawBaseVertex: true,
                drawBaseInstance: true,
                drawIndirect: true,
                drawIndirectBaseInstance: true,
                fillModeWireframe: true,
                samplerAnisotropy: true,
                depthClipDisable: true,
                texture1D: true,
                independentBlend: true,
                structuredBuffer: true,
                subsetTextureView: true,
                commandListDebugMarkers: _device.FeatureLevel >= SharpDX.Direct3D.FeatureLevel.Level_11_1,
                bufferRangeBinding: _device.FeatureLevel >= SharpDX.Direct3D.FeatureLevel.Level_11_1,
                shaderFloat64: _device.CheckFeatureSupport(Feature.ShaderDoubles));

            _d3d11ResourceFactory = new D3D11ResourceFactory(this);
            _d3d11Info            = new BackendInfoD3D11(this);

            PostDeviceCreated();
        }