/// <summary>
        /// Initializes a new instance of the <see cref="EngineAdapterInfo" /> class.
        /// </summary>
        internal EngineAdapterInfo(int adapterIndex, IDXGIAdapter1 adapter)
        {
            this.Outputs      = new List <EngineOutputInfo>();
            this.AdapterIndex = adapterIndex;

            _adapterDescription    = adapter.Description;
            this.IsSoftwareAdapter =
                _adapterDescription.Description == "Microsoft Basic Render Driver" ||
                !string.IsNullOrEmpty(_adapterDescription.Description) && _adapterDescription.Description.Contains("Software") ||
                !string.IsNullOrEmpty(_adapterDescription.Description) && _adapterDescription.Description.Contains("Microsoft Basic Render Driver");
            _d3d11FeatureLevel = D3D11.D3D11.GetSupportedFeatureLevel(adapter);

            //Query for output information
            var lastResult = Result.Ok;
            var actIndex   = 0;

            do
            {
                lastResult = adapter.EnumOutputs(actIndex, out var actOutput);
                if (lastResult.Success)
                {
                    this.Outputs.Add(new EngineOutputInfo(adapterIndex, actIndex, actOutput));
                }
                actIndex++;
            }while (lastResult.Success);
        }
Exemple #2
0
        internal GraphicsDevice(DirectX11Proxy proxy, GraphicSurfaceSize size, AdapterDescription adapterDescription)
        {
            resourseHash = new ResourseRegistrHash();
            Compilator   = new D3DShaderCompilator();
            Adapter      = adapterDescription;

            int width  = size.Width;
            int height = size.Height;

            directX = proxy;
            directX.Resize(width, height);
            CreateBuffers(width, height);

            TexturedLoader = new TextureLoader(directX.D3DDevice);
        }
Exemple #3
0
        /// <summary>
        /// Creates a new <see cref="GraphicsDevice"/> instance for the input <see cref="ID3D12Device"/>
        /// </summary>
        /// <param name="device">The <see cref="ID3D12Device"/> to use for the new <see cref="GraphicsDevice"/> instance</param>
        /// <param name="description">The available info for the new <see cref="GraphicsDevice"/> instance</param>
        public GraphicsDevice(ID3D12Device device, AdapterDescription description)
        {
            NativeDevice  = device;
            Description   = description;
            WavefrontSize = 64;

            NativeComputeCommandQueue = NativeDevice.CreateCommandQueue(new CommandQueueDescription(CommandListType.Compute));
            NativeCopyCommandQueue    = NativeDevice.CreateCommandQueue(new CommandQueueDescription(CommandListType.Copy));
            NativeDirectCommandQueue  = NativeDevice.CreateCommandQueue(new CommandQueueDescription(CommandListType.Direct));

            ComputeAllocatorPool = new CommandAllocatorPool(this, CommandListType.Compute);
            CopyAllocatorPool    = new CommandAllocatorPool(this, CommandListType.Copy);
            DirectAllocatorPool  = new CommandAllocatorPool(this, CommandListType.Direct);

            NativeComputeFence = NativeDevice.CreateFence(0);
            NativeCopyFence    = NativeDevice.CreateFence(0);
            NativeDirectFence  = NativeDevice.CreateFence(0);

            ShaderResourceViewAllocator = new DescriptorAllocator(this);
        }
Exemple #4
0
        static void Main(string[] args)
        {
            Factory1 factory = Factory1.Create();

            Console.WriteLine("Adapter(s) Information:");
            foreach (Adapter1 adapter in factory.Adapters)
            {
                AdapterDescription   description = adapter.Description;
                AdapterDriverVersion?version;

                Console.WriteLine("Description: {0} ", description.Description);
                Console.WriteLine("\tDedicated System Memory: {0} ", description.DedicatedSystemMemory);
                Console.WriteLine("\tDedicated Video Memory: {0} ", description.DedicatedVideoMemory);
                Console.WriteLine("\tLuid: {0:X}:{1:X} ", description.AdapterLuid.HighPart, description.AdapterLuid.LowPart);
                Console.WriteLine("\tDevice Id: {0:X} ", description.DeviceId);
                Console.WriteLine("\tRevision: {0:X} ", description.Revision);

                Console.WriteLine();
                version = adapter.CheckDeviceSupport(DeviceType.Direct3D11);
                Console.WriteLine("\tSupports Direct3D 11.0 Device: {0}", version != null);
                version = adapter.CheckDeviceSupport(DeviceType.Direct3D10Point1);
                Console.WriteLine("\tSupports Direct3D 10.1 Device: {0}", version != null);
                version = adapter.CheckDeviceSupport(DeviceType.Direct3D10);
                Console.WriteLine("\tSupports Direct3D 10.0 Device: {0}", version != null);
                Console.WriteLine();

                Console.WriteLine("\tMonitor(s) Information:");
                foreach (Output output in adapter.Outputs)
                {
                    OutputDescription outDesc = output.Description;

                    Console.WriteLine("\tDevice Name: {0} ", outDesc.DeviceName);
                    Console.WriteLine("\t\tAttached To Desktop: {0} ", outDesc.AttachedToDesktop);
                    Console.WriteLine("\t\tRotation Mode: {0} ", outDesc.Rotation);
                    Console.WriteLine("\t\tMonitor Coordinates: Top: {0}, Left: {1}, Right: {2}, Bottom: {3} ", outDesc.Monitor.MonitorCoordinates.Top, outDesc.Monitor.MonitorCoordinates.Left, outDesc.Monitor.MonitorCoordinates.Right, outDesc.Monitor.MonitorCoordinates.Bottom);
                    Console.WriteLine("\t\tWorking Coordinates: Top: {0}, left: {1}, Right: {2}, Bottom: {3} ", outDesc.Monitor.WorkCoordinates.Top, outDesc.Monitor.WorkCoordinates.Left, outDesc.Monitor.WorkCoordinates.Right, outDesc.Monitor.WorkCoordinates.Bottom);
                }
            }
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
        /// <summary>
        /// Creates a new <see cref="GraphicsDevice"/> instance for the input <see cref="ID3D12Device"/>
        /// </summary>
        /// <param name="device">The <see cref="ID3D12Device"/> to use for the new <see cref="GraphicsDevice"/> instance</param>
        /// <param name="description">The available info for the new <see cref="GraphicsDevice"/> instance</param>
        public GraphicsDevice(ID3D12Device device, AdapterDescription description)
        {
            NativeDevice  = device;
            Name          = description.Description;
            MemorySize    = description.DedicatedVideoMemory;
            ComputeUnits  = device.Options1.TotalLaneCount;
            WavefrontSize = device.Options1.WaveLaneCountMin;

            NativeComputeCommandQueue = NativeDevice.CreateCommandQueue(new CommandQueueDescription(CommandListType.Compute));
            NativeCopyCommandQueue    = NativeDevice.CreateCommandQueue(new CommandQueueDescription(CommandListType.Copy));
            NativeDirectCommandQueue  = NativeDevice.CreateCommandQueue(new CommandQueueDescription(CommandListType.Direct));

            ComputeAllocatorPool = new CommandAllocatorPool(this, CommandListType.Compute);
            CopyAllocatorPool    = new CommandAllocatorPool(this, CommandListType.Copy);
            DirectAllocatorPool  = new CommandAllocatorPool(this, CommandListType.Direct);

            NativeComputeFence = NativeDevice.CreateFence(0);
            NativeCopyFence    = NativeDevice.CreateFence(0);
            NativeDirectFence  = NativeDevice.CreateFence(0);

            ShaderResourceViewAllocator = new DescriptorAllocator(NativeDevice);
        }
Exemple #6
0
 private static string CreateString(AdapterDescription description)
 {
     return($"{new string(description.Description.TakeWhile(c => c != 0).ToArray())}");
 }
Exemple #7
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)
                {
                    VorticeD3D11.D3D11CreateDevice(options.AdapterPtr,
                                                   Vortice.Direct3D.DriverType.Hardware,
                                                   flags,
                                                   new[]
                    {
                        Vortice.Direct3D.FeatureLevel.Level_11_1,
                        Vortice.Direct3D.FeatureLevel.Level_11_0,
                    },
                                                   out _device).CheckError();
                }
                else
                {
                    VorticeD3D11.D3D11CreateDevice(IntPtr.Zero,
                                                   Vortice.Direct3D.DriverType.Hardware,
                                                   flags,
                                                   new[]
                    {
                        Vortice.Direct3D.FeatureLevel.Level_11_1,
                        Vortice.Direct3D.FeatureLevel.Level_11_0,
                    },
                                                   out _device).CheckError();
                }
            }
            catch
            {
                VorticeD3D11.D3D11CreateDevice(IntPtr.Zero,
                                               Vortice.Direct3D.DriverType.Hardware,
                                               flags,
                                               null,
                                               out _device).CheckError();
            }

            using (IDXGIDevice dxgiDevice = _device.QueryInterface <IDXGIDevice>())
            {
                // Store a pointer to the DXGI adapter.
                // This is for the case of no preferred DXGI adapter, or fallback to WARP.
                dxgiDevice.GetAdapter(out _dxgiAdapter).CheckError();

                AdapterDescription desc = _dxgiAdapter.Description;
                _deviceName = desc.Description;
                _vendorName = "id:" + ((uint)desc.VendorId).ToString("x8");
                _deviceId   = desc.DeviceId;
            }

            switch (_device.FeatureLevel)
            {
            case Vortice.Direct3D.FeatureLevel.Level_10_0:
                _apiVersion = new GraphicsApiVersion(10, 0, 0, 0);
                break;

            case Vortice.Direct3D.FeatureLevel.Level_10_1:
                _apiVersion = new GraphicsApiVersion(10, 1, 0, 0);
                break;

            case Vortice.Direct3D.FeatureLevel.Level_11_0:
                _apiVersion = new GraphicsApiVersion(11, 0, 0, 0);
                break;

            case Vortice.Direct3D.FeatureLevel.Level_11_1:
                _apiVersion = new GraphicsApiVersion(11, 1, 0, 0);
                break;

            case Vortice.Direct3D.FeatureLevel.Level_12_0:
                _apiVersion = new GraphicsApiVersion(12, 0, 0, 0);
                break;

            case Vortice.Direct3D.FeatureLevel.Level_12_1:
                _apiVersion = new GraphicsApiVersion(12, 1, 0, 0);
                break;

            case Vortice.Direct3D.FeatureLevel.Level_12_2:
                _apiVersion = new GraphicsApiVersion(12, 2, 0, 0);
                break;
            }

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

            IsDebugEnabled = (flags & DeviceCreationFlags.Debug) != 0;

            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();
        }
Exemple #8
0
 /// <summary>
 /// Registers the given adapter at the plugin
 /// </summary>
 /// <param name="description">adapter description</param>
 protected void RegisterAdapter <T>(AdapterDescription description) where T : IAdapter
 {
     _adapterDescriptions.Add(description);
     _adapterTypeMapping.Add(description.Key, typeof(T));
 }