コード例 #1
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) && !Vortice.Direct3D11.D3D11.SdkLayersAvailable())
            {
                flags &= ~DeviceCreationFlags.Debug;
            }

            try
            {
                if (options.AdapterPtr != IntPtr.Zero)
                {
                    _dxgiAdapter = new IDXGIAdapter(options.AdapterPtr);
                    Vortice.Direct3D11.D3D11.D3D11CreateDevice(_dxgiAdapter,
                                                               Vortice.Direct3D.DriverType.Hardware,
                                                               flags,
                                                               new[]
                    {
                        Vortice.Direct3D.FeatureLevel.Level_11_1,
                        Vortice.Direct3D.FeatureLevel.Level_11_0,
                    },
                                                               out _device).CheckError();
                }
                else
                {
                    Vortice.Direct3D11.D3D11.D3D11CreateDevice(null,
                                                               Vortice.Direct3D.DriverType.Hardware,
                                                               flags,
                                                               new[]
                    {
                        Vortice.Direct3D.FeatureLevel.Level_11_1,
                        Vortice.Direct3D.FeatureLevel.Level_11_0,
                    },
                                                               out _device).CheckError();
                }
            }
            catch
            {
                Vortice.Direct3D11.D3D11.D3D11CreateDevice(null,
                                                           Vortice.Direct3D.DriverType.Hardware,
                                                           flags,
                                                           null,
                                                           out _device).CheckError();
            }

            using (var dxgiDevice = _device.QueryInterface <Vortice.DXGI.IDXGIDevice>())
            {
                // 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 >= Vortice.Direct3D.FeatureLevel.Level_11_1,
                bufferRangeBinding: _device.FeatureLevel >= Vortice.Direct3D.FeatureLevel.Level_11_1,
                shaderFloat64: _device.CheckFeatureSupport <FeatureDataDoubles>(Vortice.Direct3D11.Feature.Doubles).DoublePrecisionFloatShaderOps);

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

            PostDeviceCreated();
        }
コード例 #2
0
        public DeviceD3D11(IDXGIFactory1 factory, bool validation)
        {
            DXGIFactory = factory;
            var adapters = DXGIFactory.EnumAdapters1();

            for (var i = 0; i < adapters.Length; i++)
            {
                var adapter = adapters[0];
                var desc    = adapter.Description1;

                // Don't select the Basic Render Driver adapter.
                if ((desc.Flags & AdapterFlags.Software) != AdapterFlags.None)
                {
                    continue;
                }

                var creationFlags = DeviceCreationFlags.BgraSupport /* | DeviceCreationFlags.VideoSupport*/;

                if (validation)
                {
                    creationFlags |= DeviceCreationFlags.Debug;
                }

                if (D3D11CreateDevice(
                        null,
                        DriverType.Hardware,
                        creationFlags,
                        s_featureLevels,
                        out D3D11Device,
                        out FeatureLevel,
                        out D3D11DeviceContext).Failure)
                {
                    // Remove debug flag not being supported.
                    creationFlags &= ~DeviceCreationFlags.Debug;

                    if (D3D11CreateDevice(null, DriverType.Hardware,
                                          creationFlags, s_featureLevels,
                                          out D3D11Device, out FeatureLevel, out D3D11DeviceContext).Failure)
                    {
                        throw new GraphicsException("Cannot create D3D11 Device");
                    }
                }

                DXGIAdapter = adapter;
                break;
            }

            D3D11Device1 = D3D11Device.QueryInterfaceOrNull <ID3D11Device1>();

            // Detect multithreading
            FeatureDataThreading featureDataThreading = default;

            if (D3D11Device.CheckFeatureSupport(DirectX.Direct3D11.Feature.Threading, ref featureDataThreading))
            {
                SupportsConcurrentResources = featureDataThreading.DriverConcurrentCreates;
                SupportsCommandLists        = featureDataThreading.DriverCommandLists;
            }

            // Init device features.
            InitializeFeatures();

            // Create command queue's.
            _graphicsCommandQueue = new CommandQueueD3D11(this, D3D11DeviceContext);
            _computeCommandQueue  = new CommandQueueD3D11(this, CommandQueueType.Compute);
            _copyCommandQueue     = new CommandQueueD3D11(this, CommandQueueType.Copy);
        }