Esempio n. 1
0
        public GpuDevice(GpuAdapter adapter)
        {
            //set member to null
            mVertexShader = null;
            mPixelShader  = null;
            mInputLayout  = null;

            //set the adapter
            Adapter = adapter;

#if DEBUG
            //creation flag, we use debug flag
            var creationFlags = SharpDX.Direct3D11.DeviceCreationFlags.Debug;
#else
            var creationFlags = SharpDX.Direct3D11.DeviceCreationFlags.None;
#endif
            //fetuares level: 11_0, 12_0
            var fetuares = new SharpDX.Direct3D.FeatureLevel[2]
            {
                SharpDX.Direct3D.FeatureLevel.Level_11_0,
                SharpDX.Direct3D.FeatureLevel.Level_12_0
            };

            //create device with current adapter
            mDevice           = new SharpDX.Direct3D11.Device(Adapter.Adapter, creationFlags, fetuares);
            mImmediateContext = Device.ImmediateContext;

            LogEmitter.Apply(LogLevel.Information, "[Initialize Graphics Device with {0}]", adapter.Description);
            LogEmitter.Apply(LogLevel.Information, "[Graphics Device Feature Level = {0}]", Device.FeatureLevel);
        }
        private void CreateDevice()
        {
            SharpDX.Direct3D.FeatureLevel[] levels = new SharpDX.Direct3D.FeatureLevel[] {
                SharpDX.Direct3D.FeatureLevel.Level_11_0,
                SharpDX.Direct3D.FeatureLevel.Level_10_1,
                SharpDX.Direct3D.FeatureLevel.Level_10_0,
                SharpDX.Direct3D.FeatureLevel.Level_9_3,
                SharpDX.Direct3D.FeatureLevel.Level_9_2,
                SharpDX.Direct3D.FeatureLevel.Level_9_1
            };
            foreach (var level in levels)
            {
                try
                {
                    this.device = new D3D11.Device(SharpDX.Direct3D.DriverType.Hardware, D3D11.DeviceCreationFlags.BgraSupport, level);
                    break;
                }
                catch
                {
                    continue;
                }
            }
            if (this.device == null)
            {
                throw new PlatformNotSupportedException("DirectXデバイスの作成に失敗しました");
            }

            device_dxgi  = this.device.QueryInterface <DXGI.Device>();
            factory_dxgi = device_dxgi.Adapter.GetParent <DXGI.Factory2>();
        }
Esempio n. 3
0
            public void Run()
            {
                Debug.WriteLine("Run");

                // First, create the Direct3D device.

                // This flag is required in order to enable compatibility with Direct2D.
                var creationFlags = SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport;

#if DEBUG
                // If the project is in a debug build, enable debugging via SDK Layers with this flag.
                creationFlags |= SharpDX.Direct3D11.DeviceCreationFlags.Debug;
#endif

                // This array defines the ordering of feature levels that D3D should attempt to create.
                var featureLevels = new SharpDX.Direct3D.FeatureLevel[]
                {
                    SharpDX.Direct3D.FeatureLevel.Level_11_1,
                    SharpDX.Direct3D.FeatureLevel.Level_11_0,
                };

                using (var d3dDevice = new SharpDX.Direct3D11.Device(SharpDX.Direct3D.DriverType.Hardware
                                                                     , creationFlags, featureLevels))
                {
                    m_d3dDevice = d3dDevice.QueryInterface <SharpDX.Direct3D11.Device1>();
                }
                m_d3dDeviceContext = m_d3dDevice.ImmediateContext1;

                // After the D3D device is created, create additional application resources.
                CreateWindowSizeDependentResources();

                // Enter the render loop.  Note that Windows Store apps should never exit.
                while (true)
                {
                    // Process events incoming to the window.
                    m_window.Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessAllIfPresent);

                    // Specify the render target we created as the output target.
                    m_d3dDeviceContext.OutputMerger.SetRenderTargets(null,
                                                                     m_renderTargetView
                                                                     );

                    // Clear the render target to a solid color.
                    m_d3dDeviceContext.ClearRenderTargetView(
                        m_renderTargetView,
                        new SharpDX.Color4(0.071f, 0.04f, 0.561f, 1.0f)
                        );

                    // Present the rendered image to the window.  Because the maximum frame latency is set to 1,
                    // the render loop will generally be throttled to the screen refresh rate, typically around
                    // 60Hz, by sleeping the application on Present until the screen is refreshed.
                    m_swapChain.Present(1, 0);
                }
            }
Esempio n. 4
0
 /// <summary>
 /// <p>Creates a device that represents the display adapter.</p>
 /// </summary>
 /// <param name="adapterRef"><dd>  <p> A reference to the video adapter to use when creating a device. Pass <strong><c>null</c></strong> to use the default adapter, which is the first adapter that is enumerated by <strong>IDXGIFactory1::EnumAdapters</strong>. </p> <strong>Note</strong>?? Do not mix the use of DXGI 1.0 (<strong><see cref="SharpDX.DXGI.Factory"/></strong>) and DXGI 1.1 (<strong><see cref="SharpDX.DXGI.Factory1"/></strong>) in an application. Use <strong><see cref="SharpDX.DXGI.Factory"/></strong> or <strong><see cref="SharpDX.DXGI.Factory1"/></strong>, but not both in an application.  ? </dd></param>
 /// <param name="minimumFeatureLevel"><dd>  <p> The <strong><see cref="SharpDX.Direct3D.DriverType"/></strong>, which represents the driver type to create. </p> </dd></param>
 /// <param name="riid"><dd>  <p> A handle to a DLL that implements a software rasterizer. If <em>DriverType</em> is <em><see cref="SharpDX.Direct3D.DriverType.Software"/></em>, <em>Software</em> must not be <strong><c>null</c></strong>. Get the handle by calling LoadLibrary, LoadLibraryEx , or GetModuleHandle. </p> </dd></param>
 /// <param name="deviceOut"><dd>  <p> Returns the address of a reference to an <strong><see cref="SharpDX.Direct3D11.Device"/></strong> object that represents the device created. If this parameter is <strong><c>null</c></strong>, no <see cref="SharpDX.Direct3D11.Device"/> will be returned. </p> </dd></param>
 /// <returns><p> This method can return one of the Direct3D 11 Return Codes. </p><p> This method returns E_INVALIDARG if you set the <em>pAdapter</em> parameter to a non-<strong><c>null</c></strong> value and the <em>DriverType</em> parameter to the <see cref="SharpDX.Direct3D.DriverType.Hardware"/> value. </p><p> This method returns <strong><see cref="SharpDX.DXGI.ResultCode.SdkComponentMissing"/></strong> if you specify <strong><see cref="SharpDX.Direct3D11.DeviceCreationFlags.Debug"/></strong> in <em>Flags</em> and the incorrect version of the debug layer is installed on your computer. Install the latest Windows SDK to get the correct version. </p></returns>
 /// <remarks>
 /// <p> This entry-point is supported by the Direct3D 11 runtime, which is available on Windows 7, Windows Server 2008 R2, and as an update to Windows Vista (KB971644). </p><p> To create a Direct3D 11.1 device (<strong><see cref="SharpDX.Direct3D11.Device1"/></strong>), which is available on Windows?8, Windows Server?2012, and Windows?7 and Windows Server?2008?R2 with the Platform Update for Windows 7 installed, you first create a <strong><see cref="SharpDX.Direct3D11.Device"/></strong> with this function, and then call the <strong>QueryInterface</strong> method on the <strong><see cref="SharpDX.Direct3D11.Device"/></strong> object to obtain the <strong><see cref="SharpDX.Direct3D11.Device1"/></strong> interface. </p><p> To create a Direct3D 11.2 device (<strong><see cref="SharpDX.Direct3D11.Device2"/></strong>), which is available on Windows?8.1 and Windows Server?2012?R2, you first create a <strong><see cref="SharpDX.Direct3D11.Device"/></strong> with this function, and then call the <strong>QueryInterface</strong> method on the <strong><see cref="SharpDX.Direct3D11.Device"/></strong> object to obtain the <strong><see cref="SharpDX.Direct3D11.Device2"/></strong> interface. </p><p> Set <em>ppDevice</em> and <em>ppImmediateContext</em> to <strong><c>null</c></strong> to determine which feature level is supported by looking at <em>pFeatureLevel</em> without creating a device. </p><p> For an example, see How To: Create a Device and Immediate Context; to create a device and a swap chain at the same time, use <strong>D3D11CreateDeviceAndSwapChain</strong>. </p><p> If you set the <em>pAdapter</em> parameter to a non-<strong><c>null</c></strong> value, you must also set the <em>DriverType</em> parameter to the <see cref="SharpDX.Direct3D.DriverType.Unknown"/> value. If you set the <em>pAdapter</em> parameter to a non-<strong><c>null</c></strong> value and the <em>DriverType</em> parameter to the <see cref="SharpDX.Direct3D.DriverType.Hardware"/> value, <strong><see cref="SharpDX.Direct3D11.D3D11.CreateDevice"/></strong> returns an <strong><see cref="SharpDX.Result"/></strong> of E_INVALIDARG. </p><table> <tr><td> <p>Differences between Direct3D 10 and Direct3D 11:</p> <p> In Direct3D 10, the presence of <em>pAdapter</em> dictated which adapter to use and the <em>DriverType</em> could mismatch what the adapter was. </p> <p> In Direct3D 11, if you are trying to create a hardware or a software device, set <em>pAdapter</em> != <strong><c>null</c></strong> which constrains the other inputs to be: </p> <ul> <li><em>DriverType</em> must be <see cref="SharpDX.Direct3D.DriverType.Unknown"/> </li> <li><em>Software</em> must be <strong><c>null</c></strong>. </li> </ul> <p> On the other hand, if <em>pAdapter</em> == <strong><c>null</c></strong>, the <em>DriverType</em> cannot be set to <see cref="SharpDX.Direct3D.DriverType.Unknown"/>; it can be set to either: </p> <ul> <li> If <em>DriverType</em> == <see cref="SharpDX.Direct3D.DriverType.Software"/>,  <em>Software</em> cannot be <strong><c>null</c></strong>. </li> <li> If <em>DriverType</em> == <see cref="SharpDX.Direct3D.DriverType.Hardware"/>, the adapter used will be the default adapter, which is the first adapter that is enumerated by <strong>IDXGIFactory1::EnumAdapters</strong> </li> </ul> </td></tr> </table><p>?</p><p> The function signature PFN_D3D11_CREATE_DEVICE is provided as a typedef, so that you can use dynamic linking techniques (GetProcAddress) instead of statically linking. </p><p><strong>Windows?Phone?8: </strong> This API is supported. </p><p><strong>Windows Phone 8.1: </strong> This API is supported. </p>
 /// </remarks>
 /// <include file='.\..\Documentation\CodeComments.xml' path="/comments/comment[@id='D3D12CreateDevice']/*"/>
 /// <msdn-id>ff476082</msdn-id>
 /// <unmanaged>HRESULT D3D12CreateDevice([In, Optional] IUnknown* pAdapter,[In] D3D_FEATURE_LEVEL MinimumFeatureLevel,[In] const GUID&amp; riid,[Out, Fast] ID3D12Device** ppDevice)</unmanaged>
 /// <unmanaged-short>D3D12CreateDevice</unmanaged-short>
 public static SharpDX.Result CreateDevice(SharpDX.ComObject adapterRef, SharpDX.Direct3D.FeatureLevel minimumFeatureLevel, System.Guid riid, SharpDX.Direct3D12.Device deviceOut)
 {
     unsafe {
         IntPtr         deviceOut_ = IntPtr.Zero;
         SharpDX.Result __result__;
         __result__ =
             D3D12CreateDevice_((void *)((adapterRef == null)?IntPtr.Zero:adapterRef.NativePointer), unchecked ((int)minimumFeatureLevel), &riid, &deviceOut_);
         ((SharpDX.Direct3D12.Device)deviceOut).NativePointer = deviceOut_;
         return(__result__);
     }
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="dg"></param>
        /// <returns></returns>
        public static Adapter GetBestAdapter(DisposeGroup dg)
        {
            SharpDX.Direct3D.FeatureLevel high = SharpDX.Direct3D.FeatureLevel.Level_9_1;
            Adapter ada = null;

            foreach (var item in GetAdapters(dg))
            {
                var level = SharpDX.Direct3D11.Device.GetSupportedFeatureLevel(item);
                if (ada == null || level > high)
                {
                    ada  = item;
                    high = level;
                }
            }
            return(ada);
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="cFlags"></param>
 /// <param name="minLevel"></param>
 /// <returns></returns>
 public static SharpDX.Direct3D11.Device Create11(
     SharpDX.Direct3D11.DeviceCreationFlags cFlags = SharpDX.Direct3D11.DeviceCreationFlags.None,
     SharpDX.Direct3D.FeatureLevel minLevel        = SharpDX.Direct3D.FeatureLevel.Level_9_1)
 {
     using (var dg = new DisposeGroup())
     {
         var ada = GetBestAdapter(dg);
         if (ada == null)
         {
             return(null);
         }
         var level = SharpDX.Direct3D11.Device.GetSupportedFeatureLevel(ada);
         if (level < minLevel)
         {
             return(null);
         }
         return(new SharpDX.Direct3D11.Device(ada, cFlags, level));
     }
 }
Esempio n. 7
0
        /// <summary>
        ///     Initializes the specified device.
        /// </summary>
        /// <param name="graphicsProfiles">The graphics profiles.</param>
        /// <param name="deviceCreationFlags">The device creation flags.</param>
        /// <param name="windowHandle">The window handle.</param>
        private void InitializePlatformDevice(GraphicsProfile[] graphicsProfiles, DeviceCreationFlags deviceCreationFlags, object windowHandle)
        {
            if (nativeDevice != null)
            {
                // Destroy previous device
                ReleaseDevice();
            }

            rendererName = Adapter.NativeAdapter.Description.Description;

            // Profiling is supported through pix markers
            IsProfilingSupported = true;

            // Command lists are thread-safe and execute deferred
            IsDeferred = true;

            bool isDebug = (deviceCreationFlags & DeviceCreationFlags.Debug) != 0;

            if (isDebug)
            {
                SharpDX.Direct3D12.DebugInterface.Get().EnableDebugLayer();
            }

            // Create Device D3D12 with feature Level based on profile
            for (int index = 0; index < graphicsProfiles.Length; index++)
            {
                var graphicsProfile = graphicsProfiles[index];
                try
                {
                    // D3D12 supports only feature level 11+
                    var level = graphicsProfile.ToFeatureLevel();
                    if (level < SharpDX.Direct3D.FeatureLevel.Level_11_0)
                    {
                        level = SharpDX.Direct3D.FeatureLevel.Level_11_0;
                    }

                    nativeDevice = new SharpDX.Direct3D12.Device(Adapter.NativeAdapter, level);

                    RequestedProfile    = graphicsProfile;
                    CurrentFeatureLevel = level;
                    break;
                }
                catch (Exception)
                {
                    if (index == graphicsProfiles.Length - 1)
                    {
                        throw;
                    }
                }
            }

            // Describe and create the command queue.
            var queueDesc = new SharpDX.Direct3D12.CommandQueueDescription(SharpDX.Direct3D12.CommandListType.Direct);

            NativeCommandQueue = nativeDevice.CreateCommandQueue(queueDesc);
            //queueDesc.Type = CommandListType.Copy;
            NativeCopyCommandQueue = nativeDevice.CreateCommandQueue(queueDesc);
            TimestampFrequency     = NativeCommandQueue.TimestampFrequency;

            SrvHandleIncrementSize     = NativeDevice.GetDescriptorHandleIncrementSize(DescriptorHeapType.ConstantBufferViewShaderResourceViewUnorderedAccessView);
            SamplerHandleIncrementSize = NativeDevice.GetDescriptorHandleIncrementSize(DescriptorHeapType.Sampler);

            if (isDebug)
            {
                var debugDevice = nativeDevice.QueryInterfaceOrNull <DebugDevice>();
                if (debugDevice != null)
                {
                    var infoQueue = debugDevice.QueryInterfaceOrNull <InfoQueue>();
                    if (infoQueue != null)
                    {
                        MessageId[] disabledMessages =
                        {
                            // This happens when render target or depth stencil clear value is diffrent
                            // than provided during resource allocation.
                            MessageId.CleardepthstencilviewMismatchingclearvalue,
                            MessageId.ClearrendertargetviewMismatchingclearvalue,

                            // This occurs when there are uninitialized descriptors in a descriptor table,
                            // even when a shader does not access the missing descriptors.
                            MessageId.InvalidDescriptorHandle,

                            // These happen when capturing with VS diagnostics
                            MessageId.MapInvalidNullRange,
                            MessageId.UnmapInvalidNullRange,
                        };

                        // Disable irrelevant debug layer warnings
                        InfoQueueFilter filter = new InfoQueueFilter
                        {
                            DenyList = new InfoQueueFilterDescription
                            {
                                Ids = disabledMessages
                            }
                        };
                        infoQueue.AddStorageFilterEntries(filter);

                        //infoQueue.SetBreakOnSeverity(MessageSeverity.Error, true);
                        //infoQueue.SetBreakOnSeverity(MessageSeverity.Warning, true);

                        infoQueue.Dispose();
                    }
                    debugDevice.Dispose();
                }
            }

            // Prepare pools
            CommandAllocators = new CommandAllocatorPool(this);
            SrvHeaps          = new HeapPool(this, SrvHeapSize, DescriptorHeapType.ConstantBufferViewShaderResourceViewUnorderedAccessView);
            SamplerHeaps      = new HeapPool(this, SamplerHeapSize, DescriptorHeapType.Sampler);

            // Prepare descriptor allocators
            SamplerAllocator            = new DescriptorAllocator(this, DescriptorHeapType.Sampler);
            ShaderResourceViewAllocator = new DescriptorAllocator(this, DescriptorHeapType.ConstantBufferViewShaderResourceViewUnorderedAccessView);
            DepthStencilViewAllocator   = new DescriptorAllocator(this, DescriptorHeapType.DepthStencilView);
            RenderTargetViewAllocator   = new DescriptorAllocator(this, DescriptorHeapType.RenderTargetView);

            // Prepare copy command list (start it closed, so that every new use start with a Reset)
            NativeCopyCommandAllocator = NativeDevice.CreateCommandAllocator(CommandListType.Direct);
            NativeCopyCommandList      = NativeDevice.CreateCommandList(CommandListType.Direct, NativeCopyCommandAllocator, null);
            NativeCopyCommandList.Close();

            // Fence for next frame and resource cleaning
            nativeFence     = NativeDevice.CreateFence(0, FenceFlags.None);
            nativeCopyFence = NativeDevice.CreateFence(0, FenceFlags.None);
        }
Esempio n. 8
0
        void CreateDevice()
        {
            SharpDX.Direct3D.FeatureLevel[] levels = new SharpDX.Direct3D.FeatureLevel[] {
                SharpDX.Direct3D.FeatureLevel.Level_11_0,
                SharpDX.Direct3D.FeatureLevel.Level_10_1,
                SharpDX.Direct3D.FeatureLevel.Level_10_0,
                SharpDX.Direct3D.FeatureLevel.Level_9_3,
                SharpDX.Direct3D.FeatureLevel.Level_9_2,
                SharpDX.Direct3D.FeatureLevel.Level_9_1
            };
            foreach (var level in levels)
            {
                try
                {
                    this.device = new D3D11.Device(SharpDX.Direct3D.DriverType.Hardware, D3D11.DeviceCreationFlags.BgraSupport, level);
                    break;
                }
                catch
                {
                    continue;
                }
            }
            if (this.device == null)
            {
                throw new PlatformNotSupportedException("DirectX10デバイスの作成に失敗しました");
            }

            var dxgiDevice = this.device.QueryInterface <DXGI.Device>();

            this.device2d = new D2D.Device1(this._factory.D2DFactory, dxgiDevice);
            dxgiDevice.Dispose();

            this.render = new D2D.DeviceContext1(this.device2d, D2D.DeviceContextOptions.None);

            IntPtr DesktopWnd = NativeMethods.GetDesktopWindow();

            D3D9.Direct3DEx d3dex = new D3D9.Direct3DEx();

            D3D9.PresentParameters param = new D3D9.PresentParameters();
            param.Windowed             = true;
            param.SwapEffect           = D3D9.SwapEffect.Discard;
            param.DeviceWindowHandle   = DesktopWnd;
            param.PresentationInterval = D3D9.PresentInterval.Default;

            try
            {
                this.device9 = new D3D9.DeviceEx(
                    d3dex,
                    0,
                    D3D9.DeviceType.Hardware,
                    DesktopWnd,
                    D3D9.CreateFlags.HardwareVertexProcessing | D3D9.CreateFlags.Multithreaded | D3D9.CreateFlags.FpuPreserve,
                    param);
            }
            catch
            {
                try
                {
                    this.device9 = new D3D9.DeviceEx(
                        d3dex,
                        0,
                        D3D9.DeviceType.Hardware,
                        DesktopWnd,
                        D3D9.CreateFlags.SoftwareVertexProcessing | D3D9.CreateFlags.Multithreaded | D3D9.CreateFlags.FpuPreserve,
                        param);
                }
                catch
                {
                    throw new PlatformNotSupportedException("DirectX9デバイスの作成に失敗しました");
                }
            }
            finally
            {
                d3dex.Dispose();
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Creates a context state object that holds all Microsoft Direct3D state and some Direct3D behavior.
        /// </summary>
        /// <typeparam name="T">The type of the emulated interface. This value specifies the behavior of the device when the context state object is active. Valid values are  <see cref="SharpDX.Direct3D10.Device"/>, <see cref="SharpDX.Direct3D10.Device1"/>, <see cref="SharpDX.Direct3D11.Device"/>, and <see cref="SharpDX.Direct3D11.Device1"/>. See Remarks.</typeparam>
        /// <param name="flags"><para>A combination of <see cref="SharpDX.Direct3D11.CreateDeviceContextStateFlags"/> values that are combined by using a bitwise OR operation. The resulting value specifies how to create the context state object. The <see cref="SharpDX.Direct3D11.CreateDeviceContextStateFlags.Singlethreaded"/> flag is currently the only defined flag. If the original device was created with <see cref="SharpDX.Direct3D11.DeviceCreationFlags.SingleThreaded"/>, you must create all context state objects from that device with the <see cref="SharpDX.Direct3D11.CreateDeviceContextStateFlags.Singlethreaded"/> flag. </para> <para>The context state object that  CreateDeviceContextState creates  inherits the threading model of its associated device context. By default the context state object is rent-threaded, so that an application synchronizes access to the device context, typically by use of critical sections. In contrast, the context state object is free-threaded if you used the ID3D10Multithread interface to turn on thread protection for the device context.</para> <para>If you set the single-threaded flag for both the context state object and the device, you guarantee that you will   call the whole set of context methods and device methods only from one thread. You therefore do not need to use critical sections to synchronize access to the device context, and the runtime can avoid working with those processor-intensive critical sections.</para></param>
        /// <param name="featureLevelsRef"><para>A reference to an array of <see cref="SharpDX.Direct3D.FeatureLevel"/> values. The array determines the order of feature levels for which creation is attempted.  To get the greatest feature level available, set pFeatureLevels to <c>null</c>,  so that CreateDeviceContextState uses the following array of feature level values:</para>  <code> { <see cref="SharpDX.Direct3D.FeatureLevel.Level_11_1"/>, <see cref="SharpDX.Direct3D.FeatureLevel.Level_11_0"/>, <see cref="SharpDX.Direct3D.FeatureLevel.Level_10_1"/>, <see cref="SharpDX.Direct3D.FeatureLevel.Level_10_0"/>, <see cref="SharpDX.Direct3D.FeatureLevel.Level_9_3"/>, <see cref="SharpDX.Direct3D.FeatureLevel.Level_9_2"/>, <see cref="SharpDX.Direct3D.FeatureLevel.Level_9_1"/>,}; </code></param>
        /// <param name="chosenFeatureLevelRef"><para>A reference to a variable that receives a <see cref="SharpDX.Direct3D.FeatureLevel"/> value from the pFeatureLevels array. This is the first array value with which CreateDeviceContextState succeeded in creating the context state object. If the call to CreateDeviceContextState fails, the variable pointed to by pChosenFeatureLevel is set to zero.</para></param>
        /// <returns>A <see cref="SharpDX.Direct3D11.DeviceContextState"/> object that represents the state of a Direct3D device.</returns>
        /// <remarks>
        /// The  REFIID value of the emulated interface is a <see cref="System.Guid"/> obtained by use of the __uuidof operator. For example, __uuidof(<see cref="SharpDX.Direct3D11.Device"/>) gets the <see cref="System.Guid"/> of the interface to a Microsoft Direct3D?11 device.Call the <see cref="SharpDX.Direct3D11.DeviceContext1.SwapDeviceContextState"/> method to activate the context state object. When the context state object is active, the device behaviors that are associated with both the context state object's feature level and its compatible interface are activated on the Direct3D device until the next call to SwapDeviceContextState.When a context state object is active, the runtime disables certain methods on the device and context interfaces. For example, a context state object that is created with __uuidof(<see cref="SharpDX.Direct3D11.Device"/>) will cause the runtime to turn off most of the Microsoft Direct3D?10 device interfaces, and a context state object that is created with __uuidof(<see cref="SharpDX.Direct3D10.Device1"/>) or __uuidof(<see cref="SharpDX.Direct3D10.Device"/>) will cause the runtime to turn off most of the <see cref="SharpDX.Direct3D11.DeviceContext"/> methods.
        /// This behavior ensures that a user of either emulated interface cannot set device state that the other emulated interface is unable to express. This restriction helps guarantee that the <see cref="SharpDX.Direct3D10.Device1"/> emulated interface accurately reflects the full state of the pipeline and that the emulated interface will not operate contrary to its original interface definition.For example, suppose the tessellation stage is made active through the <see cref="SharpDX.Direct3D11.DeviceContext"/> interface
        /// when you create the device through <see cref="SharpDX.Direct3D11.D3D11.CreateDevice"/> or D3D11CreateDeviceAndSwapChain,  instead of through the Direct3D?10 equivalents. Because  the Direct3D?11 context is active, a Direct3D?10 interface is inactive when you first retrieve it via QueryInterface. This means that you cannot  immediately pass a Direct3D?10 interface that you retrieved from a Direct3D?11 device to a function. You must first call SwapDeviceContextState to activate a Direct3D?10-compatible context state object.The following table shows the methods that are active and inactive for each emulated interface.Emulated interface Active device or immediate context  interfaces Inactive device or immediate context  interfaces  <para> <see cref="SharpDX.Direct3D11.Device"/> or</para>
        ///  <para> <see cref="SharpDX.Direct3D11.Device1"/> </para>
        ///  <para> <see cref="SharpDX.Direct3D11.Device"/> </para>
        ///  <para> <see cref="SharpDX.DXGI.Device"/> +</para>
        ///  <para> <see cref="SharpDX.DXGI.Device1"/> +</para>
        ///  <para> <see cref="SharpDX.DXGI.Device2"/> </para>
        ///  <para> ID3D10Multithread </para>
        ///   <see cref="SharpDX.Direct3D10.Device"/>   <para> <see cref="SharpDX.Direct3D10.Device1"/> or</para>
        ///  <para> <see cref="SharpDX.Direct3D10.Device"/> </para>
        ///  <para> <see cref="SharpDX.Direct3D10.Device"/> </para>
        ///  <para> <see cref="SharpDX.Direct3D10.Device1"/> </para>
        ///  <para> <see cref="SharpDX.DXGI.Device"/> +</para>
        ///  <para> <see cref="SharpDX.DXGI.Device1"/> </para>
        ///  <para> ID3D10Multithread </para>
        ///  <para> <see cref="SharpDX.Direct3D11.Device"/> </para>
        ///  <para> <see cref="SharpDX.Direct3D11.DeviceContext"/> (As published by the immediate context. The Direct3D?10 or Microsoft Direct3D?10.1 emulated interface has no effect on deferred contexts.)</para>?The following table shows the immediate context methods that the runtime disables when the indicated context state objects are active.Methods of <see cref="SharpDX.Direct3D11.DeviceContext"/> when __uuidof(<see cref="SharpDX.Direct3D10.Device1"/>) or __uuidof(<see cref="SharpDX.Direct3D10.Device"/>) is active Methods of <see cref="SharpDX.Direct3D10.Device"/> when __uuidof(<see cref="SharpDX.Direct3D11.Device"/>) is active    <para> Begin </para>
        ///  <para> ClearDepthStencilView </para>
        ///  <para> ClearDepthStencilView </para>
        ///  <para> ClearRenderTargetView </para>
        ///  <para> ClearRenderTargetView </para>
        ///  <para> ClearState </para>
        ///  <para> ClearState </para>
        ///  <para> ClearUnorderedAccessViewUint </para>
        ///  <para> ClearUnorderedAccessViewFloat </para>
        ///  <para> CopyResource </para>
        ///  <para> CopyResource </para>
        ///  <para> CopyStructureCount </para>
        ///  <para> CopySubresourceRegion </para>
        ///  <para> CopySubresourceRegion </para>
        ///  <para> CSGetConstantBuffers </para>
        ///  <para> CSGetSamplers </para>
        ///  <para> CSGetShader </para>
        ///  <para> CSGetShaderResources </para>
        ///  <para> CSGetUnorderedAccessViews </para>
        ///  <para> CSSetConstantBuffers </para>
        ///  <para> CSSetSamplers </para>
        ///  <para> CSSetShader </para>
        ///  <para> CSSetShaderResources </para>
        ///  <para> CSSetUnorderedAccessViews </para>
        ///  <para> Dispatch </para>
        ///  <para> DispatchIndirect </para>
        ///  <para> CreateBlendState </para>
        ///  <para> Draw </para>
        ///  <para> Draw </para>
        ///  <para> DrawAuto </para>
        ///  <para> DrawAuto </para>
        ///  <para> DrawIndexed </para>
        ///  <para> DrawIndexed </para>
        ///  <para> DrawIndexedInstanced </para>
        ///  <para> DrawIndexedInstanced </para>
        ///  <para> DrawIndexedInstancedIndirect </para>
        ///  <para> DrawInstanced </para>
        ///  <para> DrawInstanced </para>
        ///  <para> DrawInstancedIndirect </para>
        ///  <para> DSGetConstantBuffers </para>
        ///  <para> DSGetSamplers </para>
        ///  <para> DSGetShader </para>
        ///  <para> DSGetShaderResources </para>
        ///  <para> DSSetConstantBuffers </para>
        ///  <para> DSSetSamplers </para>
        ///  <para> DSSetShader </para>
        ///  <para> DSSetShaderResources </para>
        ///  <para> End </para>
        ///  <para> ExecuteCommandList </para>
        ///  <para> FinishCommandList </para>
        ///  <para> Flush </para>
        ///  <para> Flush </para>
        ///  <para> GenerateMips </para>
        ///  <para> GenerateMips </para>
        ///  <para> GetData </para>
        ///  <para> GetPredication </para>
        ///  <para> GetPredication </para>
        ///  <para> GetResourceMinLOD </para>
        ///  <para> GetType </para>
        ///  <para> GetTextFilterSize </para>
        ///  <para> GSGetConstantBuffers </para>
        ///  <para> GSGetConstantBuffers </para>
        ///  <para> GSGetSamplers </para>
        ///  <para> GSGetSamplers </para>
        ///  <para> GSGetShader </para>
        ///  <para> GSGetShader </para>
        ///  <para> GSGetShaderResources </para>
        ///  <para> GSGetShaderResources </para>
        ///  <para> GSSetConstantBuffers </para>
        ///  <para> GSSetConstantBuffers </para>
        ///  <para> GSSetSamplers </para>
        ///  <para> GSSetSamplers </para>
        ///  <para> GSSetShader </para>
        ///  <para> GSSetShader </para>
        ///  <para> GSSetShaderResources </para>
        ///  <para> GSSetShaderResources </para>
        ///  <para> HSGetConstantBuffers </para>
        ///  <para> HSGetSamplers </para>
        ///  <para> HSGetShader </para>
        ///  <para> HSGetShaderResources </para>
        ///  <para> HSSetConstantBuffers </para>
        ///  <para> HSSetSamplers </para>
        ///  <para> HSSetShader </para>
        ///  <para> HSSetShaderResources </para>
        ///  <para> IAGetIndexBuffer </para>
        ///  <para> IAGetIndexBuffer </para>
        ///  <para> IAGetInputLayout </para>
        ///  <para> IAGetInputLayout </para>
        ///  <para> IAGetPrimitiveTopology </para>
        ///  <para> IAGetPrimitiveTopology </para>
        ///  <para> IAGetVertexBuffers </para>
        ///  <para> IASetIndexBuffer </para>
        ///  <para> IASetInputLayout </para>
        ///  <para> IASetPrimitiveTopology </para>
        ///  <para> IASetVertexBuffers </para>
        ///  <para> OMGetBlendState </para>
        ///  <para> OMGetBlendState </para>
        ///  <para> OMGetDepthStencilState </para>
        ///  <para> OMGetDepthStencilState </para>
        ///  <para> OMGetRenderTargets </para>
        ///  <para> OMGetRenderTargets </para>
        ///  <para> OMGetRenderTargetsAndUnorderedAccessViews </para>
        ///  <para> OMSetBlendState </para>
        ///  <para> OMSetBlendState </para>
        ///  <para> OMSetDepthStencilState </para>
        ///  <para> OMSetDepthStencilState </para>
        ///  <para> OMSetRenderTargets </para>
        ///  <para> OMSetRenderTargets </para>
        ///  <para> OMSetRenderTargetsAndUnorderedAccessViews </para>
        ///  <para> PSGetConstantBuffers </para>
        ///  <para> PSGetConstantBuffers </para>
        ///  <para> PSGetSamplers </para>
        ///  <para> PSGetSamplers </para>
        ///  <para> PSGetShader </para>
        ///  <para> PSGetShader </para>
        ///  <para> PSGetShaderResources </para>
        ///  <para> PSGetShaderResources </para>
        ///  <para> PSSetConstantBuffers </para>
        ///  <para> PSSetConstantBuffers </para>
        ///  <para> PSSetSamplers </para>
        ///  <para> PSSetSamplers </para>
        ///  <para> PSSetShader </para>
        ///  <para> PSSetShader </para>
        ///  <para> PSSetShaderResources </para>
        ///  <para> PSSetShaderResources </para>
        ///  <para> ResolveSubresource </para>
        ///  <para> ResolveSubresource </para>
        ///  <para> RSGetScissorRects </para>
        ///  <para> RSGetScissorRects </para>
        ///  <para> RSGetState </para>
        ///  <para> RSGetState </para>
        ///  <para> RSGetViewports </para>
        ///  <para> RSGetViewports </para>
        ///  <para> RSSetScissorRects </para>
        ///  <para> RSSetScissorRects </para>
        ///  <para> RSSetState </para>
        ///  <para> RSSetState </para>
        ///  <para> RSSetViewports </para>
        ///  <para> RSSetViewports </para>
        ///  <para> SetPredication </para>
        ///  <para> SetPredication </para>
        ///  <para> SetResourceMinLOD </para>
        ///  <para> SetTextFilterSize </para>
        ///  <para> SOGetTargets </para>
        ///  <para> SOGetTargets </para>
        ///  <para> SOSetTargets </para>
        ///  <para> SOSetTargets </para>
        ///  <para> UpdateSubresource </para>
        ///  <para> UpdateSubresource </para>
        ///  <para> VSGetConstantBuffers </para>
        ///  <para> VSGetConstantBuffers </para>
        ///  <para> VSGetSamplers </para>
        ///  <para> VSGetSamplers </para>
        ///  <para> VSGetShader </para>
        ///  <para> VSGetShader </para>
        ///  <para> VSGetShaderResources </para>
        ///  <para> VSGetShaderResources </para>
        ///  <para> VSSetConstantBuffers </para>
        ///  <para> VSSetConstantBuffers </para>
        ///  <para> VSSetSamplers </para>
        ///  <para> VSSetSamplers </para>
        ///  <para> VSSetShader </para>
        ///  <para> VSSetShader </para>
        ///  <para> VSSetShaderResources </para>
        ///  <para> VSSetShaderResources </para>?The following table shows the immediate context methods that the runtime does not disable when the indicated context state objects are active.Methods of <see cref="SharpDX.Direct3D11.DeviceContext"/> when __uuidof(<see cref="SharpDX.Direct3D10.Device1"/>) or __uuidof(<see cref="SharpDX.Direct3D10.Device"/>) is active Methods of <see cref="SharpDX.Direct3D10.Device"/> when __uuidof(<see cref="SharpDX.Direct3D11.Device"/>) is active   <para> GetCreationFlags </para>
        ///  <para> GetPrivateData </para>
        ///  <para> GetContextFlags </para>
        ///  <para> Map </para>
        ///  <para> Unmap </para>?The following table shows the <see cref="SharpDX.Direct3D10.Device"/> interface methods that the runtime does not disable because they are not immediate context methods.Methods of <see cref="SharpDX.Direct3D10.Device"/>   <para> CheckCounter </para>
        ///  <para> CheckCounterInfo </para>
        ///  <para>Create*, like CreateQuery </para>
        ///  <para> GetDeviceRemovedReason </para>
        ///  <para> GetExceptionMode </para>
        ///  <para> OpenSharedResource </para>
        ///  <para> SetExceptionMode </para>
        ///  <para> SetPrivateData </para>
        ///  <para> SetPrivateDataInterface </para>?
        /// </remarks>
        /// <unmanaged>HRESULT ID3D11Device1::CreateDeviceContextState([In] D3D11_1_CREATE_DEVICE_CONTEXT_STATE_FLAG Flags,[In, Buffer] const D3D_FEATURE_LEVEL* pFeatureLevels,[In] unsigned int FeatureLevels,[In] unsigned int SDKVersion,[In] const GUID&amp; EmulatedInterface,[Out, Optional] D3D_FEATURE_LEVEL* pChosenFeatureLevel,[Out, Fast] ID3DDeviceContextState** ppContextState)</unmanaged>
        public SharpDX.Direct3D11.DeviceContextState CreateDeviceContextState <T>(SharpDX.Direct3D11.CreateDeviceContextStateFlags flags, SharpDX.Direct3D.FeatureLevel[] featureLevelsRef, out SharpDX.Direct3D.FeatureLevel chosenFeatureLevelRef) where T : ComObject
        {
            var deviceContextState = new SharpDX.Direct3D11.DeviceContextState(IntPtr.Zero);

            CreateDeviceContextState(flags, featureLevelsRef, featureLevelsRef.Length, D3D11.SdkVersion, Utilities.GetGuidFromType(typeof(T)), out chosenFeatureLevelRef, deviceContextState);
            return(deviceContextState);
        }
Esempio n. 10
0
        public void ShaderReflectionMatchesDirect3DReflection(string relPath)
        {
            // Arrange.
            var file            = $"{ShaderDirectory}/{relPath}";
            var binaryFileBytes = File.ReadAllBytes(file + ".o");

            // Act.
            if (binaryFileBytes[0] == 0x01 &&
                binaryFileBytes[1] == 0x20 &&
                binaryFileBytes[2] == 0xFF &&
                binaryFileBytes[3] == 0xFE)
            {
                Effects11.CompareEffect(null, binaryFileBytes, Path.GetFileNameWithoutExtension(relPath));
                return;
            }
            var container = BytecodeContainer.Parse(binaryFileBytes);

            if (container.Chunks.OfType <LibHeaderChunk>().Any())
            {
                CompareLibrary(container, binaryFileBytes);
                return;
            }
            if (container.Chunks.OfType <EffectChunk>().Any())
            {
                Effects10.CompareEffect(container, binaryFileBytes, Path.GetFileNameWithoutExtension(relPath));
                return;
            }
            using (var shaderBytecode = ShaderBytecode.FromStream(new MemoryStream(binaryFileBytes)))
                using (var shaderReflection = new ShaderReflection(shaderBytecode))
                {
                    var desc = shaderReflection.Description;

                    // Assert.
                    Assert.AreEqual(shaderReflection.BitwiseInstructionCount, 0);             // TODO
                    Assert.AreEqual(shaderReflection.ConditionalMoveInstructionCount, container.Statistics.MovCInstructionCount);
                    Assert.AreEqual(shaderReflection.ConversionInstructionCount, container.Statistics.ConversionInstructionCount);
                    Assert.AreEqual((int)shaderReflection.GeometryShaderSInputPrimitive, (int)container.Statistics.InputPrimitive);
                    Assert.AreEqual(shaderReflection.InterfaceSlotCount, container.ResourceDefinition.InterfaceSlotCount);
                    Assert.AreEqual((bool)shaderReflection.IsSampleFrequencyShader, container.Statistics.IsSampleFrequencyShader);
                    Assert.AreEqual(shaderReflection.MoveInstructionCount, container.Statistics.MovInstructionCount);

                    var flags = ShaderRequiresFlags.None;
                    if (container.Version.MajorVersion >= 5)
                    {
                        if (container.Sfi0 != null)
                        {
                            flags = (ShaderRequiresFlags)container.Sfi0.Flags;
                        }
                        else
                        {
                            var dcl = container.Shader.DeclarationTokens
                                      .OfType <GlobalFlagsDeclarationToken>()
                                      .FirstOrDefault();
                            var globals = dcl?.Flags ?? 0;
                            flags = (ShaderRequiresFlags)Chunks.Sfi0.Sfi0Chunk.GlobalFlagsToRequireFlags(globals);
                        }
                    }
                    Assert.AreEqual(shaderReflection.RequiresFlags, flags);

                    int  expectedSizeX, expectedSizeY, expectedSizeZ;
                    uint actualSizeX, actualSizeY, actualSizeZ;
                    shaderReflection.GetThreadGroupSize(out expectedSizeX, out expectedSizeY, out expectedSizeZ);
                    container.Shader.GetThreadGroupSize(out actualSizeX, out actualSizeY, out actualSizeZ);
                    Assert.AreEqual(expectedSizeX, actualSizeX);
                    Assert.AreEqual(expectedSizeY, actualSizeY);
                    Assert.AreEqual(expectedSizeZ, actualSizeZ);


                    SharpDX.Direct3D.FeatureLevel featureLevel = 0;
                    if (container.Chunks.OfType <Chunks.Aon9.Level9ShaderChunk>().Any())
                    {
                        var level9Chunk = container.Chunks
                                          .OfType <Chunks.Aon9.Level9ShaderChunk>()
                                          .First();
                        featureLevel = level9Chunk.ShaderModel.MinorVersion == 1
                                                ? SharpDX.Direct3D.FeatureLevel.Level_9_3 :
                                       SharpDX.Direct3D.FeatureLevel.Level_9_1;
                    }
                    else if (container.Version.MajorVersion == 4 && container.Version.MinorVersion == 0)
                    {
                        featureLevel = SharpDX.Direct3D.FeatureLevel.Level_10_0;
                    }
                    else if (container.Version.MajorVersion == 4 && container.Version.MinorVersion == 1)
                    {
                        featureLevel = SharpDX.Direct3D.FeatureLevel.Level_10_1;
                    }
                    else if (container.Version.MajorVersion == 5)
                    {
                        featureLevel = SharpDX.Direct3D.FeatureLevel.Level_11_0;
                        if (flags.HasFlag(ShaderRequiresFlags.ShaderRequires64UnorderedAccessViews))
                        {
                            featureLevel = SharpDX.Direct3D.FeatureLevel.Level_11_1;
                        }
                    }

                    Assert.AreEqual(shaderReflection.MinFeatureLevel, featureLevel);             // TODO

                    Assert.AreEqual(desc.ArrayInstructionCount, container.Statistics.ArrayInstructionCount);
                    Assert.AreEqual(desc.BarrierInstructions, container.Statistics.BarrierInstructions);
                    Assert.AreEqual(desc.BoundResources, container.ResourceDefinition.ResourceBindings.Count);
                    Assert.AreEqual(desc.ConstantBuffers, container.ResourceDefinition.ConstantBuffers.Count);
                    Assert.AreEqual(desc.ControlPoints, container.Statistics.ControlPoints);
                    Assert.AreEqual(desc.Creator, container.ResourceDefinition.Creator);
                    Assert.AreEqual(desc.CutInstructionCount, container.Statistics.CutInstructionCount);
                    Assert.AreEqual(desc.DeclarationCount, container.Statistics.DeclarationCount);
                    Assert.AreEqual(desc.DefineCount, container.Statistics.DefineCount);
                    Assert.AreEqual(desc.DynamicFlowControlCount, container.Statistics.DynamicFlowControlCount);
                    Assert.AreEqual(desc.EmitInstructionCount, container.Statistics.EmitInstructionCount);
                    Assert.AreEqual((int)desc.Flags, (int)container.ResourceDefinition.Flags);
                    Assert.AreEqual(desc.FloatInstructionCount, container.Statistics.FloatInstructionCount);
                    Assert.AreEqual(desc.GeometryShaderInstanceCount, container.Statistics.GeometryShaderInstanceCount);
                    Assert.AreEqual(desc.GeometryShaderMaxOutputVertexCount, container.Statistics.GeometryShaderMaxOutputVertexCount);
                    Assert.AreEqual((int)desc.GeometryShaderOutputTopology, (int)container.Statistics.GeometryShaderOutputTopology);
                    Assert.AreEqual((int)desc.HullShaderOutputPrimitive, (int)container.Statistics.HullShaderOutputPrimitive);
                    Assert.AreEqual((int)desc.HullShaderPartitioning, (int)container.Statistics.HullShaderPartitioning);
                    Assert.AreEqual(desc.InputParameters, container.InputSignature.Parameters.Count);
                    Assert.AreEqual((int)desc.InputPrimitive, (int)container.Statistics.InputPrimitive);
                    Assert.AreEqual(desc.InstructionCount, container.Statistics.InstructionCount);
                    Assert.AreEqual(desc.InterlockedInstructions, container.Statistics.InterlockedInstructions);
                    Assert.AreEqual(desc.IntInstructionCount, container.Statistics.IntInstructionCount);
                    Assert.AreEqual(desc.MacroInstructionCount, container.Statistics.MacroInstructionCount);
                    Assert.AreEqual(desc.OutputParameters, container.OutputSignature.Parameters.Count);
                    Assert.AreEqual(desc.PatchConstantParameters, (container.PatchConstantSignature != null)
                                        ? container.PatchConstantSignature.Parameters.Count
                                        : 0);
                    Assert.AreEqual(desc.StaticFlowControlCount, container.Statistics.StaticFlowControlCount);
                    Assert.AreEqual(desc.TempArrayCount, container.Statistics.TempArrayCount);
                    Assert.AreEqual(desc.TempRegisterCount, container.Statistics.TempRegisterCount);
                    Assert.AreEqual((int)desc.TessellatorDomain, (int)container.Statistics.TessellatorDomain);
                    Assert.AreEqual(desc.TextureBiasInstructions, container.Statistics.TextureBiasInstructions);
                    Assert.AreEqual(desc.TextureCompInstructions, container.Statistics.TextureCompInstructions);
                    Assert.AreEqual(desc.TextureGradientInstructions, container.Statistics.TextureGradientInstructions);
                    Assert.AreEqual(desc.TextureLoadInstructions, container.Statistics.TextureLoadInstructions);
                    Assert.AreEqual(desc.TextureNormalInstructions, container.Statistics.TextureNormalInstructions);
                    Assert.AreEqual(desc.TextureStoreInstructions, container.Statistics.TextureStoreInstructions);
                    Assert.AreEqual(desc.UintInstructionCount, container.Statistics.UIntInstructionCount);

                    var version = Chunks.Common.ShaderVersion.FromShexToken((uint)desc.Version);
                    Assert.AreEqual(version.ToString(), container.ResourceDefinition.Target.ToString());

                    for (int i = 0; i < shaderReflection.Description.ConstantBuffers; i++)
                    {
                        CompareConstantBuffer(shaderReflection.GetConstantBuffer(i),
                                              container.ResourceDefinition.ConstantBuffers[i]);
                    }

                    for (int i = 0; i < shaderReflection.Description.BoundResources; i++)
                    {
                        CompareResourceBinding(shaderReflection.GetResourceBindingDescription(i),
                                               container.ResourceDefinition.ResourceBindings[i]);
                    }

                    for (int i = 0; i < shaderReflection.Description.InputParameters; i++)
                    {
                        CompareParameter(shaderReflection.GetInputParameterDescription(i),
                                         container.InputSignature.Parameters[i]);
                    }

                    for (int i = 0; i < shaderReflection.Description.OutputParameters; i++)
                    {
                        CompareParameter(shaderReflection.GetOutputParameterDescription(i),
                                         container.OutputSignature.Parameters[i]);
                    }

                    for (int i = 0; i < shaderReflection.Description.PatchConstantParameters; i++)
                    {
                        CompareParameter(shaderReflection.GetPatchConstantParameterDescription(i),
                                         container.PatchConstantSignature.Parameters[i]);
                    }
                }
        }
        /// <summary>
        ///     Initializes the specified device.
        /// </summary>
        /// <param name="graphicsProfiles">The graphics profiles.</param>
        /// <param name="deviceCreationFlags">The device creation flags.</param>
        /// <param name="windowHandle">The window handle.</param>
        private void InitializePlatformDevice(GraphicsProfile[] graphicsProfiles, DeviceCreationFlags deviceCreationFlags, object windowHandle)
        {
            if (nativeDevice != null)
            {
                // Destroy previous device
                ReleaseDevice();
            }

            rendererName = Adapter.NativeAdapter.Description.Description;

            // Profiling is supported through pix markers
            IsProfilingSupported = true;

            if ((deviceCreationFlags & DeviceCreationFlags.Debug) != 0)
            {
                SharpDX.Direct3D12.DebugInterface.Get().EnableDebugLayer();
            }

            // Default fallback
            if (graphicsProfiles.Length == 0)
            {
                graphicsProfiles = new[] { GraphicsProfile.Level_11_0 }
            }
            ;

            // Create Device D3D12 with feature Level based on profile
            for (int index = 0; index < graphicsProfiles.Length; index++)
            {
                var graphicsProfile = graphicsProfiles[index];
                try
                {
                    // D3D12 supports only feature level 11+
                    var level = graphicsProfile.ToFeatureLevel();
                    if (level < SharpDX.Direct3D.FeatureLevel.Level_11_0)
                    {
                        level = SharpDX.Direct3D.FeatureLevel.Level_11_0;
                    }

                    nativeDevice = new SharpDX.Direct3D12.Device(Adapter.NativeAdapter, level);

                    RequestedProfile    = graphicsProfile;
                    CurrentFeatureLevel = level;
                    break;
                }
                catch (Exception)
                {
                    if (index == graphicsProfiles.Length - 1)
                    {
                        throw;
                    }
                }
            }

            // Describe and create the command queue.
            var queueDesc = new SharpDX.Direct3D12.CommandQueueDescription(SharpDX.Direct3D12.CommandListType.Direct);

            NativeCommandQueue = nativeDevice.CreateCommandQueue(queueDesc);
            //queueDesc.Type = CommandListType.Copy;
            NativeCopyCommandQueue = nativeDevice.CreateCommandQueue(queueDesc);

            SrvHandleIncrementSize     = NativeDevice.GetDescriptorHandleIncrementSize(DescriptorHeapType.ConstantBufferViewShaderResourceViewUnorderedAccessView);
            SamplerHandleIncrementSize = NativeDevice.GetDescriptorHandleIncrementSize(DescriptorHeapType.Sampler);

            // Prepare pools
            CommandAllocators = new CommandAllocatorPool(this);
            SrvHeaps          = new HeapPool(this, SrvHeapSize, DescriptorHeapType.ConstantBufferViewShaderResourceViewUnorderedAccessView);
            SamplerHeaps      = new HeapPool(this, SamplerHeapSize, DescriptorHeapType.Sampler);

            // Prepare descriptor allocators
            SamplerAllocator            = new DescriptorAllocator(this, DescriptorHeapType.Sampler);
            ShaderResourceViewAllocator = new DescriptorAllocator(this, DescriptorHeapType.ConstantBufferViewShaderResourceViewUnorderedAccessView);
            DepthStencilViewAllocator   = new DescriptorAllocator(this, DescriptorHeapType.DepthStencilView);
            RenderTargetViewAllocator   = new DescriptorAllocator(this, DescriptorHeapType.RenderTargetView);

            // Prepare copy command list (start it closed, so that every new use start with a Reset)
            NativeCopyCommandAllocator = NativeDevice.CreateCommandAllocator(CommandListType.Direct);
            NativeCopyCommandList      = NativeDevice.CreateCommandList(CommandListType.Direct, NativeCopyCommandAllocator, null);
            NativeCopyCommandList.Close();

            // Fence for next frame and resource cleaning
            nativeFence     = NativeDevice.CreateFence(0, FenceFlags.None);
            nativeCopyFence = NativeDevice.CreateFence(0, FenceFlags.None);
        }
Esempio n. 12
0
        /// <summary>
        /// <p>Creates a new composition surface object that can be bound to a
        /// Microsoft DirectX swap chain or swap buffer and associated
        /// with a visual.</p>
        /// </summary>
        /// <param name="statistics"><dd>  <p>The requested access to the composition surface object. It can be one of the following values:</p> <table> <tr><th>Value</th><th>Meaning</th></tr> <tr><td><dl> <dt><strong></strong></dt> <dt>0x0000L</dt> </dl> </td><td> <p>No access.</p> </td></tr> <tr><td><dl> <dt><strong>COMPOSITIONSURFACE_READ</strong></dt> <dt>0x0001L</dt> </dl> </td><td> <p>Read access. For internal use only.</p> </td></tr> <tr><td><dl> <dt><strong>COMPOSITIONSURFACE_WRITE</strong></dt> <dt>0x0002L</dt> </dl> </td><td> <p>Write access. For internal use only.</p> </td></tr> <tr><td><dl> <dt><strong>COMPOSITIONSURFACE_ALL_ACCESS</strong></dt> <dt>0x0003L</dt> </dl> </td><td> <p>Read/write access. Always specify this flag except when duplicating a surface in another process, in which case set <em>desiredAccess</em> to 0.</p> </td></tr> </table> <p>?</p> </dd></param>
        /// <param name="minSafeFeaturelLevel"><dd>  <p>Contains the security descriptor for the composition surface object, and specifies whether the handle of the composition surface object is inheritable when a child process is created. If this parameter is <c>null</c>, the composition surface object is created with default security attributes  that grant read and write access to the current process,  but do not enable child processes to  inherit the handle.</p> </dd></param>
        /// <param name="maxHardwareFeaturelLevel"><dd>  <p>The handle of the new composition surface object. This parameter must not be <c>null</c>.</p> </dd></param>
        /// <returns><p>If the function succeeds, it returns <see cref="SharpDX.Result.Ok"/>. Otherwise, it returns an <strong><see cref="SharpDX.Result"/></strong> error code. See DirectComposition Error Codes for a list of error codes.  </p></returns>
        /// <include file='.\..\Documentation\CodeComments.xml' path="/comments/comment[@id='DCompositionGetFrameStatistics']/*"/>
        /// <msdn-id>hh437360</msdn-id>
        /// <unmanaged>HRESULT DCompositionGetFrameStatistics([Out] DCOMPOSITION_FRAME_STATISTICS* statistics,[Out, Optional] D3D_FEATURE_LEVEL* minSafeFeaturelLevel,[Out, Optional] D3D_FEATURE_LEVEL* maxHardwareFeaturelLevel)</unmanaged>
        /// <unmanaged-short>DCompositionGetFrameStatistics</unmanaged-short>
        internal static void GetFrameStatistics(out SharpDX.DirectComposition.FrameStatistics statistics, out SharpDX.Direct3D.FeatureLevel minSafeFeaturelLevel, out SharpDX.Direct3D.FeatureLevel maxHardwareFeaturelLevel)
        {
            unsafe {
                statistics = new SharpDX.DirectComposition.FrameStatistics();
                SharpDX.Result __result__;

                fixed(void *statistics_ = &statistics)
                fixed(void *minSafeFeaturelLevel_     = &minSafeFeaturelLevel)
                fixed(void *maxHardwareFeaturelLevel_ = &maxHardwareFeaturelLevel)
                __result__ =
                    DCompositionGetFrameStatistics_(statistics_, minSafeFeaturelLevel_, maxHardwareFeaturelLevel_);

                __result__.CheckError();
            }
        }
Esempio n. 13
0
        protected virtual void InternalInitialize()
        {
            dpiScale      = GetDpiScale();
            SurfaceWidth  = (int)(ActualWidth < 0 ? 0 : Math.Ceiling(ActualWidth * dpiScale));
            SurfaceHeight = (int)(ActualHeight < 0 ? 0 : Math.Ceiling(ActualHeight * dpiScale));

            var swapChainDescription = new DXGI.SwapChainDescription {
                OutputHandle      = Hwnd,
                BufferCount       = 2,
                Flags             = DXGI.SwapChainFlags.AllowModeSwitch,
                IsWindowed        = true,
                ModeDescription   = new DXGI.ModeDescription(SurfaceWidth, SurfaceHeight, new DXGI.Rational(60, 1), DXGI.Format.B8G8R8A8_UNorm),
                SampleDescription = new DXGI.SampleDescription(1, 0),
                SwapEffect        = DXGI.SwapEffect.Discard,
                Usage             = DXGI.Usage.RenderTargetOutput | DXGI.Usage.Shared
            };

            SharpDX.Direct3D.FeatureLevel[] featureLevels = null;

            if (VersionHelper.IsWindows10OrGreater())
            {
                featureLevels = new SharpDX.Direct3D.FeatureLevel[]
                {
                    SharpDX.Direct3D.FeatureLevel.Level_12_1,
                    SharpDX.Direct3D.FeatureLevel.Level_12_0,
                    SharpDX.Direct3D.FeatureLevel.Level_11_1,
                    SharpDX.Direct3D.FeatureLevel.Level_11_0,
                    SharpDX.Direct3D.FeatureLevel.Level_10_1,
                    SharpDX.Direct3D.FeatureLevel.Level_10_0,
                    SharpDX.Direct3D.FeatureLevel.Level_9_3,
                    SharpDX.Direct3D.FeatureLevel.Level_9_2,
                    SharpDX.Direct3D.FeatureLevel.Level_9_1
                };
            }
            else if (VersionHelper.IsWindows7SP1OrGreater())
            {
                featureLevels = new SharpDX.Direct3D.FeatureLevel[]
                {
                    SharpDX.Direct3D.FeatureLevel.Level_11_1,
                    SharpDX.Direct3D.FeatureLevel.Level_11_0,
                    SharpDX.Direct3D.FeatureLevel.Level_10_1,
                    SharpDX.Direct3D.FeatureLevel.Level_10_0,
                    SharpDX.Direct3D.FeatureLevel.Level_9_3,
                    SharpDX.Direct3D.FeatureLevel.Level_9_2,
                    SharpDX.Direct3D.FeatureLevel.Level_9_1
                };
            }

            try {
                Device.CreateWithSwapChain(SharpDX.Direct3D.DriverType.Hardware,
                                           DeviceCreationFlags.BgraSupport, featureLevels,
                                           swapChainDescription,
                                           out device, out swapChain);
            } catch (Exception e) {
                MessageBox.Show(e.ToString());
            }

            using (var factory = swapChain.GetParent <DXGI.Factory>()) {
                factory.MakeWindowAssociation(Hwnd, DXGI.WindowAssociationFlags.IgnoreAll);
            }

            backBuffer = swapChain.GetBackBuffer <Texture2D>(0);

            Console.WriteLine(SupportLevel);

            //backBuffer = D3D11.Resource.FromSwapChain<D3D11.Texture2D>(swapChain, 0);
            //renderTargetView = new D3D11.RenderTargetView(device, backBuffer);
        }
Esempio n. 14
0
        /// <summary>
        /// <p> Creates a device that uses Direct3D 11 functionality in Direct3D 12, specifying a pre-existing D3D12 device to use for D3D11 interop. </p>
        /// </summary>
        /// <param name="deviceRef"><dd>  <p> Specifies a pre-existing D3D12 device to use for D3D11 interop. May not be <c>null</c>. </p> </dd></param>
        /// <param name="flags"><dd>  <p> Any of those documented for <strong>D3D11CreateDeviceAndSwapChain</strong>. Specifies which runtime layers to enable (see the <strong><see cref="SharpDX.Direct3D11.DeviceCreationFlags"/></strong> enumeration); values can be bitwise OR'd together. <em>Flags</em> must be compatible with device flags, and its <em>NodeMask</em> must be a subset of the <em>NodeMask</em> provided to the present API. </p> </dd></param>
        /// <param name="featureLevelsRef"><dd>  <p> An array of any of the following: </p> <ul> <li><see cref="SharpDX.Direct3D.FeatureLevel.Level_12_1"/></li> <li><see cref="SharpDX.Direct3D.FeatureLevel.Level_12_0"/></li> <li><see cref="SharpDX.Direct3D.FeatureLevel.Level_11_1"/></li> <li><see cref="SharpDX.Direct3D.FeatureLevel.Level_11_0"/></li> <li><see cref="SharpDX.Direct3D.FeatureLevel.Level_10_1"/></li> <li><see cref="SharpDX.Direct3D.FeatureLevel.Level_10_0"/></li> <li><see cref="SharpDX.Direct3D.FeatureLevel.Level_9_3"/></li> <li><see cref="SharpDX.Direct3D.FeatureLevel.Level_9_2"/></li> <li><see cref="SharpDX.Direct3D.FeatureLevel.Level_9_1"/></li> </ul> <p> The first feature level which is less than or equal to the D3D12 device's feature level will be used to perform D3D11 validation. Creation will fail if no acceptable feature levels are provided. Providing <c>null</c> will default to the D3D12 device's feature level. </p> </dd></param>
        /// <param name="featureLevels"><dd>  <p> The size of the feature levels array, in bytes. </p> </dd></param>
        /// <param name="commandQueuesOut"><dd>  <p> An array of unique queues for D3D11On12 to use. Valid queue types: 3D command queue. </p> </dd></param>
        /// <param name="numQueues"><dd>  <p> The size of the command queue array, in bytes. </p> </dd></param>
        /// <param name="nodeMask"><dd>  <p> Which node of the D3D12 device to use. Only 1 bit may be set. </p> </dd></param>
        /// <param name="deviceOut"><dd>  <p> Pointer to the returned <strong><see cref="SharpDX.Direct3D11.Device"/></strong>. May be <c>null</c>. </p> </dd></param>
        /// <param name="immediateContextOut"><dd>  <p> A reference to the returned <strong><see cref="SharpDX.Direct3D11.DeviceContext"/></strong>. May be <c>null</c>. </p> </dd></param>
        /// <param name="chosenFeatureLevelRef"><dd>  <p> A reference to the returned feature level. May be <c>null</c>. </p> </dd></param>
        /// <returns><p> This method returns one of the Direct3D 12 Return Codes that are documented for <strong><see cref="SharpDX.Direct3D11.D3D11.CreateDevice"/></strong>. See Direct3D 12 Return Codes. </p><p> This method returns <strong><see cref="SharpDX.DXGI.ResultCode.SdkComponentMissing"/></strong> if you specify <strong><see cref="SharpDX.Direct3D11.DeviceCreationFlags.Debug"/></strong> in <em>Flags</em> and the incorrect version of the debug layer is installed on your computer. Install the latest Windows SDK to get the correct version. </p></returns>
        /// <remarks>
        /// <p> The function signature PFN_D3D11ON12_CREATE_DEVICE is provided as a typedef, so that you can use dynamic linking techniques (GetProcAddress) instead of statically linking. </p>
        /// </remarks>
        /// <include file='.\..\Documentation\CodeComments.xml' path="/comments/comment[@id='D3D11On12CreateDevice']/*"/>
        /// <msdn-id>dn933209</msdn-id>
        /// <unmanaged>HRESULT D3D11On12CreateDevice([In] IUnknown* pDevice,[In] D3D11_CREATE_DEVICE_FLAG Flags,[In, Buffer, Optional] const D3D_FEATURE_LEVEL* pFeatureLevels,[In] unsigned int FeatureLevels,[In, Buffer, Optional] const IUnknown** ppCommandQueues,[In] unsigned int NumQueues,[In] unsigned int NodeMask,[Out] ID3D11Device** ppDevice,[Out, Optional] ID3D11DeviceContext** ppImmediateContext,[Out, Optional] D3D_FEATURE_LEVEL* pChosenFeatureLevel)</unmanaged>
        /// <unmanaged-short>D3D11On12CreateDevice</unmanaged-short>
        public static void On12CreateDevice(SharpDX.ComObject deviceRef, SharpDX.Direct3D11.DeviceCreationFlags flags, SharpDX.Direct3D.FeatureLevel[] featureLevelsRef, int featureLevels, SharpDX.ComObject[] commandQueuesOut, int numQueues, int nodeMask, out SharpDX.Direct3D11.Device deviceOut, out SharpDX.Direct3D11.DeviceContext immediateContextOut, out SharpDX.Direct3D.FeatureLevel chosenFeatureLevelRef)
        {
            unsafe {
                SharpDX.Direct3D.FeatureLevel[] featureLevelsRef__ = featureLevelsRef;
                IntPtr *commandQueuesOut_ = (IntPtr *)0;
                if (commandQueuesOut != null)
                {
                    IntPtr *commandQueuesOut__ = stackalloc IntPtr[commandQueuesOut.Length];
                    commandQueuesOut_ = commandQueuesOut__;
                    for (int i = 0; i < commandQueuesOut.Length; i++)
                    {
                        commandQueuesOut_[i] = (commandQueuesOut[i] == null)? IntPtr.Zero : commandQueuesOut[i].NativePointer;
                    }
                }
                IntPtr         deviceOut_           = IntPtr.Zero;
                IntPtr         immediateContextOut_ = IntPtr.Zero;
                SharpDX.Result __result__;

                fixed(void *featureLevelsRef_ = featureLevelsRef__)
                fixed(void *chosenFeatureLevelRef_ = &chosenFeatureLevelRef)
                __result__ =
                    D3D11On12CreateDevice_((void *)((deviceRef == null)?IntPtr.Zero:deviceRef.NativePointer), unchecked ((int)flags), featureLevelsRef_, featureLevels, commandQueuesOut_, numQueues, nodeMask, &deviceOut_, &immediateContextOut_, chosenFeatureLevelRef_);

                deviceOut           = (deviceOut_ == IntPtr.Zero)?null:new SharpDX.Direct3D11.Device(deviceOut_);
                immediateContextOut = (immediateContextOut_ == IntPtr.Zero)?null:new SharpDX.Direct3D11.DeviceContext(immediateContextOut_);
                __result__.CheckError();
            }
        }
Esempio n. 15
0
        /// <summary>
        /// <p>Creates a device that represents the display adapter.</p>
        /// </summary>
        /// <param name="adapterRef"><dd>  <p>A reference to the video adapter to use when creating a device. Pass <strong><c>null</c></strong> to use the default adapter, which is the first adapter that is enumerated by <strong>IDXGIFactory1::EnumAdapters</strong>. </p> <p><strong>Note</strong>??Do not mix the use of DXGI 1.0 (<strong><see cref="SharpDX.DXGI.Factory"/></strong>) and DXGI 1.1 (<strong><see cref="SharpDX.DXGI.Factory1"/></strong>) in an application. Use <strong><see cref="SharpDX.DXGI.Factory"/></strong> or <strong><see cref="SharpDX.DXGI.Factory1"/></strong>, but not both in an application.</p> </dd></param>
        /// <param name="driverType"><dd>  <p>The <strong><see cref="SharpDX.Direct3D.DriverType"/></strong>, which represents the driver type to create.</p> </dd></param>
        /// <param name="software"><dd>  <p>A handle to a DLL that implements a software rasterizer.  If <em>DriverType</em> is <em><see cref="SharpDX.Direct3D.DriverType.Software"/></em>,  <em>Software</em> must not be <strong><c>null</c></strong>. Get the handle by  calling LoadLibrary,  LoadLibraryEx ,  or GetModuleHandle.</p> </dd></param>
        /// <param name="flags"><dd>  <p>The runtime layers to enable (see <strong><see cref="SharpDX.Direct3D11.DeviceCreationFlags"/></strong>);  values can be bitwise OR'd together.</p> </dd></param>
        /// <param name="featureLevelsRef"><dd>  <p>A reference to an array of <strong><see cref="SharpDX.Direct3D.FeatureLevel"/></strong>s, which determine the order of feature levels to attempt to create.  If <em>pFeatureLevels</em> is set to <strong><c>null</c></strong>,  this function uses the following array of feature levels:</p>  <pre> { <see cref="SharpDX.Direct3D.FeatureLevel.Level_11_0"/>, <see cref="SharpDX.Direct3D.FeatureLevel.Level_10_1"/>, <see cref="SharpDX.Direct3D.FeatureLevel.Level_10_0"/>, <see cref="SharpDX.Direct3D.FeatureLevel.Level_9_3"/>, <see cref="SharpDX.Direct3D.FeatureLevel.Level_9_2"/>, <see cref="SharpDX.Direct3D.FeatureLevel.Level_9_1"/>,}; </pre>  <p><strong>Note</strong>??If the Direct3D 11.1 runtime is present on the computer and <em>pFeatureLevels</em> is set to <strong><c>null</c></strong>, this function won't create a <strong><see cref="SharpDX.Direct3D.FeatureLevel.Level_11_1"/></strong> device. To create a <strong><see cref="SharpDX.Direct3D.FeatureLevel.Level_11_1"/></strong> device, you must explicitly provide a <strong><see cref="SharpDX.Direct3D.FeatureLevel"/></strong> array that includes <strong><see cref="SharpDX.Direct3D.FeatureLevel.Level_11_1"/></strong>. If you provide a <strong><see cref="SharpDX.Direct3D.FeatureLevel"/></strong> array that contains <strong><see cref="SharpDX.Direct3D.FeatureLevel.Level_11_1"/></strong> on a computer that doesn't have the Direct3D 11.1 runtime installed, this function immediately fails with E_INVALIDARG.</p> </dd></param>
        /// <param name="featureLevels"><dd>  <p>The number of elements in <em>pFeatureLevels</em>.</p> </dd></param>
        /// <param name="sDKVersion"><dd>  <p>The SDK version; use <em><see cref="SharpDX.Direct3D11.D3D11.SdkVersion"/></em>.</p> </dd></param>
        /// <param name="deviceOut"><dd>  <p>Returns the address of a reference to an <strong><see cref="SharpDX.Direct3D11.Device"/></strong> object that represents the device created.</p> </dd></param>
        /// <param name="featureLevelRef"><dd>  <p>If successful, returns the first <strong><see cref="SharpDX.Direct3D.FeatureLevel"/></strong> from the <em>pFeatureLevels</em> array which succeeded. Otherwise, returns 0.</p> </dd></param>
        /// <param name="immediateContextOut"><dd>  <p>Returns the address of a reference to an <strong><see cref="SharpDX.Direct3D11.DeviceContext"/></strong> object that represents the device context.</p> </dd></param>
        /// <returns><p>This method can return one of the Direct3D 11 Return Codes.</p><p>This method returns E_INVALIDARG if you set the <em>pAdapter</em> parameter to a non-<strong><c>null</c></strong> value and the <em>DriverType</em> parameter to the <see cref="SharpDX.Direct3D.DriverType.Hardware"/> value.</p></returns>
        /// <remarks>
        /// <p>This entry-point is supported by the Direct3D 11 runtime, which is available on Windows 7, Windows Server 2008 R2, and as an update to  Windows Vista (KB971644).</p><p>To create a Direct3D 11.1 device (<strong><see cref="SharpDX.Direct3D11.Device1"/></strong>), which is available on Windows?8, Windows Server?2012, and Windows?7 and Windows Server?2008?R2 with the Platform Update for Windows 7 installed, you first create a <strong><see cref="SharpDX.Direct3D11.Device"/></strong> with this function, and then call the <strong>QueryInterface</strong> method on the <strong><see cref="SharpDX.Direct3D11.Device"/></strong> object to obtain the <strong><see cref="SharpDX.Direct3D11.Device1"/></strong> interface.
        /// </p><p>To create a Direct3D 11.2 device (<strong><see cref="SharpDX.Direct3D11.Device2"/></strong>), which is available on Windows?8.1 and Windows Server?2012?R2, you first create a <strong><see cref="SharpDX.Direct3D11.Device"/></strong> with this function, and then call the <strong>QueryInterface</strong> method on the <strong><see cref="SharpDX.Direct3D11.Device"/></strong> object to obtain the <strong><see cref="SharpDX.Direct3D11.Device2"/></strong> interface.
        /// </p><p>Set <em>ppDevice</em> and <em>ppImmediateContext</em> to <strong><c>null</c></strong> to determine which feature level is supported by looking  at pFeatureLevel without creating a device.</p><p>For an example, see How To: Create a Device and Immediate Context; to create a device and a swap chain at the same time,  use <strong>D3D11CreateDeviceAndSwapChain</strong>.</p><p>If you set the <em>pAdapter</em> parameter to a non-<strong><c>null</c></strong> value, you must also set the <em>DriverType</em> parameter to the <see cref="SharpDX.Direct3D.DriverType.Unknown"/> value. If you set the <em>pAdapter</em> parameter to a non-<strong><c>null</c></strong> value and the <em>DriverType</em> parameter to the <see cref="SharpDX.Direct3D.DriverType.Hardware"/> value, <strong><see cref="SharpDX.Direct3D11.D3D11.CreateDevice"/></strong> returns an <strong><see cref="SharpDX.Result"/></strong> of E_INVALIDARG.</p><table> <tr><td> <p>Differences between Direct3D 10 and Direct3D 11:</p> <p>In Direct3D 10, the presence of <em>pAdapter</em> dictated which adapter to use and the <em>DriverType</em> could  mismatch what the adapter was.</p> <p>In Direct3D 11, if you are trying to create a hardware or a software device, set <em>pAdapter</em> != <strong><c>null</c></strong> which constrains  the other inputs to be:</p> <ul> <li><em>DriverType</em> must be <see cref="SharpDX.Direct3D.DriverType.Unknown"/></li> <li><em>Software</em> must be <strong><c>null</c></strong>.</li> </ul> <p>On the other hand, if <em>pAdapter</em> == <strong><c>null</c></strong>, the <em>DriverType</em> cannot be set to <see cref="SharpDX.Direct3D.DriverType.Unknown"/>; it can be set to either:</p> <ul> <li>If <em>DriverType</em> == <see cref="SharpDX.Direct3D.DriverType.Software"/>,  <em>Software</em> cannot be <strong><c>null</c></strong>.</li> <li>If <em>DriverType</em> == <see cref="SharpDX.Direct3D.DriverType.Hardware"/>, the adapter used will be the default adapter, which is the first adapter that is enumerated by <strong>IDXGIFactory1::EnumAdapters</strong> </li> </ul> </td></tr> </table><p>?</p><p><strong>Windows?Phone?8:</strong> This API is supported.</p><p><strong>Windows Phone 8.1:</strong> This API is supported.</p>
        /// </remarks>
        /// <include file='.\..\Documentation\CodeComments.xml' path="/comments/comment[@id='D3D11CreateDevice']/*"/>
        /// <msdn-id>ff476082</msdn-id>
        /// <unmanaged>HRESULT D3D11CreateDevice([In, Optional] IDXGIAdapter* pAdapter,[In] D3D_DRIVER_TYPE DriverType,[In] HINSTANCE Software,[In] D3D11_CREATE_DEVICE_FLAG Flags,[In, Buffer, Optional] const D3D_FEATURE_LEVEL* pFeatureLevels,[In] unsigned int FeatureLevels,[In] unsigned int SDKVersion,[Out, Fast] ID3D11Device** ppDevice,[Out, Optional] D3D_FEATURE_LEVEL* pFeatureLevel,[Out, Optional] ID3D11DeviceContext** ppImmediateContext)</unmanaged>
        /// <unmanaged-short>D3D11CreateDevice</unmanaged-short>
        public static SharpDX.Result CreateDevice(SharpDX.DXGI.Adapter adapterRef, SharpDX.Direct3D.DriverType driverType, System.IntPtr software, SharpDX.Direct3D11.DeviceCreationFlags flags, SharpDX.Direct3D.FeatureLevel[] featureLevelsRef, int featureLevels, int sDKVersion, SharpDX.Direct3D11.Device deviceOut, out SharpDX.Direct3D.FeatureLevel featureLevelRef, out SharpDX.Direct3D11.DeviceContext immediateContextOut)
        {
            unsafe {
                SharpDX.Direct3D.FeatureLevel[] featureLevelsRef__ = featureLevelsRef;
                IntPtr         deviceOut_           = IntPtr.Zero;
                IntPtr         immediateContextOut_ = IntPtr.Zero;
                SharpDX.Result __result__;

                fixed(void *featureLevelsRef_ = featureLevelsRef__)
                fixed(void *featureLevelRef_ = &featureLevelRef)
                __result__ =
                    D3D11CreateDevice_((void *)((adapterRef == null)?IntPtr.Zero:adapterRef.NativePointer), unchecked ((int)driverType), (void *)software, unchecked ((int)flags), featureLevelsRef_, featureLevels, sDKVersion, &deviceOut_, featureLevelRef_, &immediateContextOut_);

                ((SharpDX.Direct3D11.Device)deviceOut).NativePointer = deviceOut_;
                immediateContextOut = (immediateContextOut_ == IntPtr.Zero)?null:new SharpDX.Direct3D11.DeviceContext(immediateContextOut_);
                return(__result__);
            }
        }
Esempio n. 16
0
 /// <summary>
 /// No documentation.
 /// </summary>
 /// <param name = "adapterRef">No documentation.</param>
 /// <param name = "minimumFeatureLevel">No documentation.</param>
 /// <param name = "riid">No documentation.</param>
 /// <param name = "deviceOut">No documentation.</param>
 /// <returns>No documentation.</returns>
 /// <unmanaged>HRESULT D3D12CreateDevice([In, Optional] IUnknown* pAdapter,[In] D3D_FEATURE_LEVEL MinimumFeatureLevel,[In] const GUID&amp; riid,[Out, Fast] void** ppDevice)</unmanaged>
 /// <unmanaged-short>D3D12CreateDevice</unmanaged-short>
 public static unsafe SharpDX.Result CreateDevice(SharpDX.IUnknown adapterRef, SharpDX.Direct3D.FeatureLevel minimumFeatureLevel, System.Guid riid, SharpDX.Direct3D12.Device deviceOut)
 {
     System.IntPtr  adapterRef_ = System.IntPtr.Zero;
     System.IntPtr  deviceOut_  = System.IntPtr.Zero;
     SharpDX.Result __result__;
     adapterRef_ = SharpDX.CppObject.ToCallbackPtr <SharpDX.IUnknown>(adapterRef);
     __result__  = D3D12CreateDevice_((void *)adapterRef_, unchecked ((System.Int32)minimumFeatureLevel), &riid, &deviceOut_);
     (deviceOut).NativePointer = deviceOut_;
     return(__result__);
 }
Esempio n. 17
0
        /// <summary>
        /// <p> Creates a device that uses Direct3D 11 functionality in Direct3D 12, specifying a pre-existing D3D12 device to use for D3D11 interop. </p>
        /// </summary>
        /// <param name = "deviceRef"><dd>  <p> Specifies a pre-existing D3D12 device to use for D3D11 interop. May not be <c>null</c>. </p> </dd></param>
        /// <param name = "flags"><dd>  <p> One or more bitwise OR'ed flags from <strong><see cref = "SharpDX.Direct3D11.DeviceCreationFlags"/></strong>. These are the same flags as those used by <strong>D3D11CreateDeviceAndSwapChain</strong>. Specifies which runtime layers to enable. <em>Flags</em> must be compatible with device flags, and its <em>NodeMask</em> must be a subset of the <em>NodeMask</em> provided to the present API. </p> </dd></param>
        /// <param name = "featureLevelsRef"><dd>  <p> An array of any of the following: </p> <ul> <li>D3D_FEATURE_LEVEL_12_1</li> <li>D3D_FEATURE_LEVEL_12_0</li> <li>D3D_FEATURE_LEVEL_11_1</li> <li>D3D_FEATURE_LEVEL_11_0</li> <li>D3D_FEATURE_LEVEL_10_1</li> <li>D3D_FEATURE_LEVEL_10_0</li> <li>D3D_FEATURE_LEVEL_9_3</li> <li>D3D_FEATURE_LEVEL_9_2</li> <li>D3D_FEATURE_LEVEL_9_1</li> </ul> <p> The first feature level which is less than or equal to the D3D12 device's feature level will be used to perform D3D11 validation. Creation will fail if no acceptable feature levels are provided. Providing <c>null</c> will default to the D3D12 device's feature level. </p> </dd></param>
        /// <param name = "featureLevels"><dd>  <p> The size of the feature levels array, in bytes. </p> </dd></param>
        /// <param name = "commandQueuesOut"><dd>  <p> An array of unique queues for D3D11On12 to use. Valid queue types: 3D command queue. </p> </dd></param>
        /// <param name = "numQueues"><dd>  <p> The size of the command queue array, in bytes. </p> </dd></param>
        /// <param name = "nodeMask"><dd>  <p> Which node of the D3D12 device to use. Only 1 bit may be set. </p> </dd></param>
        /// <param name = "deviceOut"><dd>  <p> Pointer to the returned <strong><see cref = "SharpDX.Direct3D11.Device"/></strong>. May be <c>null</c>. </p> </dd></param>
        /// <param name = "immediateContextOut"><dd>  <p> A reference to the returned <strong><see cref = "SharpDX.Direct3D11.DeviceContext"/></strong>. May be <c>null</c>. </p> </dd></param>
        /// <param name = "chosenFeatureLevelRef"><dd>  <p> A reference to the returned feature level. May be <c>null</c>. </p> </dd></param>
        /// <returns><p> This method returns one of the Direct3D 12 Return Codes that are documented for <strong>D3D11CreateDevice</strong>. See Direct3D 12 Return Codes. </p><p> This method returns <strong><see cref = "SdkComponentMissing"/></strong> if you specify <strong>D3D11_CREATE_DEVICE_DEBUG</strong> in <em>Flags</em> and the incorrect version of the debug layer is installed on your computer. Install the latest Windows SDK to get the correct version. </p></returns>
        /// <remarks>
        /// <p> The function signature PFN_D3D11ON12_CREATE_DEVICE is provided as a typedef, so that you can use dynamic linking techniques (GetProcAddress) instead of statically linking. </p>
        /// </remarks>
        /// <doc-id>dn933209</doc-id>
        /// <unmanaged>HRESULT D3D11On12CreateDevice([In] IUnknown* pDevice,[In] unsigned int Flags,[In, Buffer, Optional] const D3D_FEATURE_LEVEL* pFeatureLevels,[In] unsigned int FeatureLevels,[In, Buffer, Optional] const IUnknown** ppCommandQueues,[In] unsigned int NumQueues,[In] unsigned int NodeMask,[Out] ID3D11Device** ppDevice,[Out, Optional] ID3D11DeviceContext** ppImmediateContext,[Out, Optional] D3D_FEATURE_LEVEL* pChosenFeatureLevel)</unmanaged>
        /// <unmanaged-short>D3D11On12CreateDevice</unmanaged-short>
        public static unsafe void On12CreateDevice(SharpDX.IUnknown deviceRef, SharpDX.Direct3D11.DeviceCreationFlags flags, SharpDX.Direct3D.FeatureLevel[] featureLevelsRef, System.Int32 featureLevels, SharpDX.IUnknown[] commandQueuesOut, System.Int32 numQueues, System.Int32 nodeMask, out SharpDX.Direct3D11.Device deviceOut, out SharpDX.Direct3D11.DeviceContext immediateContextOut, out SharpDX.Direct3D.FeatureLevel chosenFeatureLevelRef)
        {
            System.IntPtr  deviceRef_ = System.IntPtr.Zero;
            System.IntPtr *commandQueuesOut_;
            commandQueuesOut_ = (System.IntPtr *) 0;
            if (commandQueuesOut != null)
            {
                System.IntPtr *_commandQueuesOut = stackalloc System.IntPtr[commandQueuesOut.Length];
                commandQueuesOut_ = _commandQueuesOut;
            }

            System.IntPtr  deviceOut_           = System.IntPtr.Zero;
            System.IntPtr  immediateContextOut_ = System.IntPtr.Zero;
            SharpDX.Result __result__;
            deviceRef_ = SharpDX.CppObject.ToCallbackPtr <SharpDX.IUnknown>(deviceRef);
            if (commandQueuesOut != null)
            {
                for (int i = 0; i < commandQueuesOut.Length; ++i)
                {
                    (commandQueuesOut_)[i] = SharpDX.CppObject.ToCallbackPtr <SharpDX.IUnknown>(commandQueuesOut[i]);
                }
                fixed(void *chosenFeatureLevelRef_ = &chosenFeatureLevelRef)
                fixed(void *featureLevelsRef_ = featureLevelsRef)
                __result__ = D3D11On12CreateDevice_((void *)deviceRef_, unchecked ((System.Int32)flags), featureLevelsRef_, featureLevels, (void *)commandQueuesOut_, numQueues, nodeMask, &deviceOut_, &immediateContextOut_, chosenFeatureLevelRef_);

                if (deviceOut_ != System.IntPtr.Zero)
                {
                    deviceOut = new SharpDX.Direct3D11.Device(deviceOut_);
                }
                else
                {
                    deviceOut = null;
                }
                if (immediateContextOut_ != System.IntPtr.Zero)
                    immediateContextOut = new SharpDX.Direct3D11.DeviceContext(immediateContextOut_); }
                else
                {
                    immediateContextOut = null;
                }
                __result__.CheckError();
        }
Esempio n. 18
0
        /// <summary>
        /// <p>Creates a device that represents the display adapter.</p>
        /// </summary>
        /// <param name = "adapterRef"><dd>  <p> A reference to the video adapter to use when creating a device. Pass <strong><c>null</c></strong> to use the default adapter, which is the first adapter that is enumerated by <strong>IDXGIFactory1::EnumAdapters</strong>. </p> <strong>Note</strong>?? Do not mix the use of DXGI 1.0 (<strong><see cref = "SharpDX.DXGI.Factory"/></strong>) and DXGI 1.1 (<strong><see cref = "SharpDX.DXGI.Factory1"/></strong>) in an application. Use <strong><see cref = "SharpDX.DXGI.Factory"/></strong> or <strong><see cref = "SharpDX.DXGI.Factory1"/></strong>, but not both in an application.  ? </dd></param>
        /// <param name = "driverType"><dd>  <p> The <strong><see cref = "SharpDX.Direct3D.DriverType"/></strong>, which represents the driver type to create. </p> </dd></param>
        /// <param name = "software"><dd>  <p> A handle to a DLL that implements a software rasterizer. If <em>DriverType</em> is <em>D3D_DRIVER_TYPE_SOFTWARE</em>, <em>Software</em> must not be <strong><c>null</c></strong>. Get the handle by calling LoadLibrary, LoadLibraryEx , or GetModuleHandle. </p> </dd></param>
        /// <param name = "flags"><dd>  <p> The runtime layers to enable (see <strong><see cref = "SharpDX.Direct3D11.DeviceCreationFlags"/></strong>); values can be bitwise OR'd together. </p> </dd></param>
        /// <param name = "featureLevelsRef"><dd>  <p> A reference to an array of <strong><see cref = "SharpDX.Direct3D.FeatureLevel"/></strong>s, which determine the order of feature levels to attempt to create. If <em>pFeatureLevels</em> is set to <strong><c>null</c></strong>, this function uses the following array of feature levels: </p>  <pre>{ D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_9_3, D3D_FEATURE_LEVEL_9_2, D3D_FEATURE_LEVEL_9_1,};</pre>  <strong>Note</strong>?? If the Direct3D 11.1 runtime is present on the computer and <em>pFeatureLevels</em> is set to <strong><c>null</c></strong>, this function won't create a <strong>D3D_FEATURE_LEVEL_11_1</strong> device. To create a <strong>D3D_FEATURE_LEVEL_11_1</strong> device, you must explicitly provide a <strong><see cref = "SharpDX.Direct3D.FeatureLevel"/></strong> array that includes <strong>D3D_FEATURE_LEVEL_11_1</strong>. If you provide a <strong><see cref = "SharpDX.Direct3D.FeatureLevel"/></strong> array that contains <strong>D3D_FEATURE_LEVEL_11_1</strong> on a computer that doesn't have the Direct3D 11.1 runtime installed, this function immediately fails with E_INVALIDARG.  ? </dd></param>
        /// <param name = "featureLevels"><dd>  <p> The number of elements in <em>pFeatureLevels</em>. </p> </dd></param>
        /// <param name = "sDKVersion"><dd>  <p> The SDK version; use <em><see cref = "SdkVersion"/></em>. </p> </dd></param>
        /// <param name = "deviceOut"><dd>  <p> Returns the address of a reference to an <strong><see cref = "SharpDX.Direct3D11.Device"/></strong> object that represents the device created. If this parameter is <strong><c>null</c></strong>, no <see cref = "SharpDX.Direct3D11.Device"/> will be returned. </p> </dd></param>
        /// <param name = "featureLevelRef"><dd>  <p> If successful, returns the first <strong><see cref = "SharpDX.Direct3D.FeatureLevel"/></strong> from the <em>pFeatureLevels</em> array which succeeded. Supply <strong><c>null</c></strong> as an input if you don't need to determine which feature level is supported. </p> </dd></param>
        /// <param name = "immediateContextOut"><dd>  <p> Returns the address of a reference to an <strong><see cref = "SharpDX.Direct3D11.DeviceContext"/></strong> object that represents the device context. If this parameter is <strong><c>null</c></strong>, no <see cref = "SharpDX.Direct3D11.DeviceContext"/> will be returned. </p> </dd></param>
        /// <returns><p> This method can return one of the Direct3D 11 Return Codes. </p><p> This method returns E_INVALIDARG if you set the <em>pAdapter</em> parameter to a non-<strong><c>null</c></strong> value and the <em>DriverType</em> parameter to the D3D_DRIVER_TYPE_HARDWARE value. </p><p> This method returns <strong><see cref = "SdkComponentMissing"/></strong> if you specify <strong>D3D11_CREATE_DEVICE_DEBUG</strong> in <em>Flags</em> and the incorrect version of the debug layer is installed on your computer. Install the latest Windows SDK to get the correct version. </p></returns>
        /// <remarks>
        /// <p> This entry-point is supported by the Direct3D 11 runtime, which is available on Windows 7, Windows Server 2008 R2, and as an update to Windows Vista (KB971644). </p><p> To create a Direct3D 11.1 device (<strong><see cref = "SharpDX.Direct3D11.Device1"/></strong>), which is available on Windows?8, Windows Server?2012, and Windows?7 and Windows Server?2008?R2 with the Platform Update for Windows 7 installed, you first create a <strong><see cref = "SharpDX.Direct3D11.Device"/></strong> with this function, and then call the <strong>QueryInterface</strong> method on the <strong><see cref = "SharpDX.Direct3D11.Device"/></strong> object to obtain the <strong><see cref = "SharpDX.Direct3D11.Device1"/></strong> interface. </p><p> To create a Direct3D 11.2 device (<strong><see cref = "SharpDX.Direct3D11.Device2"/></strong>), which is available on Windows?8.1 and Windows Server?2012?R2, you first create a <strong><see cref = "SharpDX.Direct3D11.Device"/></strong> with this function, and then call the <strong>QueryInterface</strong> method on the <strong><see cref = "SharpDX.Direct3D11.Device"/></strong> object to obtain the <strong><see cref = "SharpDX.Direct3D11.Device2"/></strong> interface. </p><p> Set <em>ppDevice</em> and <em>ppImmediateContext</em> to <strong><c>null</c></strong> to determine which feature level is supported by looking at <em>pFeatureLevel</em> without creating a device. </p><p> For an example, see How To: Create a Device and Immediate Context; to create a device and a swap chain at the same time, use <strong>D3D11CreateDeviceAndSwapChain</strong>. </p><p> If you set the <em>pAdapter</em> parameter to a non-<strong><c>null</c></strong> value, you must also set the <em>DriverType</em> parameter to the D3D_DRIVER_TYPE_UNKNOWN value. If you set the <em>pAdapter</em> parameter to a non-<strong><c>null</c></strong> value and the <em>DriverType</em> parameter to the D3D_DRIVER_TYPE_HARDWARE value, <strong>D3D11CreateDevice</strong> returns an <strong><see cref = "SharpDX.Result"/></strong> of E_INVALIDARG. </p><table> <tr><td> <p>Differences between Direct3D 10 and Direct3D 11:</p> <p> In Direct3D 10, the presence of <em>pAdapter</em> dictated which adapter to use and the <em>DriverType</em> could mismatch what the adapter was. </p> <p> In Direct3D 11, if you are trying to create a hardware or a software device, set <em>pAdapter</em> != <strong><c>null</c></strong> which constrains the other inputs to be: </p> <ul> <li><em>DriverType</em> must be D3D_DRIVER_TYPE_UNKNOWN </li> <li><em>Software</em> must be <strong><c>null</c></strong>. </li> </ul> <p> On the other hand, if <em>pAdapter</em> == <strong><c>null</c></strong>, the <em>DriverType</em> cannot be set to D3D_DRIVER_TYPE_UNKNOWN; it can be set to either: </p> <ul> <li> If <em>DriverType</em> == D3D_DRIVER_TYPE_SOFTWARE,  <em>Software</em> cannot be <strong><c>null</c></strong>. </li> <li> If <em>DriverType</em> == D3D_DRIVER_TYPE_HARDWARE, the adapter used will be the default adapter, which is the first adapter that is enumerated by <strong>IDXGIFactory1::EnumAdapters</strong> </li> </ul> </td></tr> </table><p>?</p><p> The function signature PFN_D3D11_CREATE_DEVICE is provided as a typedef, so that you can use dynamic linking techniques (GetProcAddress) instead of statically linking. </p><p><strong>Windows?Phone?8: </strong> This API is supported. </p><p><strong>Windows Phone 8.1: </strong> This API is supported. </p>
        /// </remarks>
        /// <doc-id>ff476082</doc-id>
        /// <unmanaged>HRESULT D3D11CreateDevice([In, Optional] IDXGIAdapter* pAdapter,[In] D3D_DRIVER_TYPE DriverType,[In] HINSTANCE Software,[In] unsigned int Flags,[In, Buffer, Optional] const D3D_FEATURE_LEVEL* pFeatureLevels,[In] unsigned int FeatureLevels,[In] unsigned int SDKVersion,[Out, Fast] ID3D11Device** ppDevice,[Out, Optional] D3D_FEATURE_LEVEL* pFeatureLevel,[Out, Optional] ID3D11DeviceContext** ppImmediateContext)</unmanaged>
        /// <unmanaged-short>D3D11CreateDevice</unmanaged-short>
        public static unsafe SharpDX.Result CreateDevice(SharpDX.DXGI.Adapter adapterRef, SharpDX.Direct3D.DriverType driverType, System.IntPtr software, SharpDX.Direct3D11.DeviceCreationFlags flags, SharpDX.Direct3D.FeatureLevel[] featureLevelsRef, System.Int32 featureLevels, System.Int32 sDKVersion, SharpDX.Direct3D11.Device deviceOut, out SharpDX.Direct3D.FeatureLevel featureLevelRef, out SharpDX.Direct3D11.DeviceContext immediateContextOut)
        {
            System.IntPtr  adapterRef_          = System.IntPtr.Zero;
            System.IntPtr  deviceOut_           = System.IntPtr.Zero;
            System.IntPtr  immediateContextOut_ = System.IntPtr.Zero;
            SharpDX.Result __result__;
            adapterRef_ = SharpDX.CppObject.ToCallbackPtr <SharpDX.DXGI.Adapter>(adapterRef);

            fixed(void *featureLevelRef_ = &featureLevelRef)
            fixed(void *featureLevelsRef_ = featureLevelsRef)
            __result__ = D3D11CreateDevice_((void *)adapterRef_, unchecked ((System.Int32)driverType), (void *)software, unchecked ((System.Int32)flags), featureLevelsRef_, featureLevels, sDKVersion, &deviceOut_, featureLevelRef_, &immediateContextOut_);

            (deviceOut).NativePointer = deviceOut_;
            if (immediateContextOut_ != System.IntPtr.Zero)
            {
                immediateContextOut = new SharpDX.Direct3D11.DeviceContext(immediateContextOut_);
            }
            else
            {
                immediateContextOut = null;
            }
            return(__result__);
        }