Exemplo n.º 1
0
        public unsafe static Result D3D11On12CreateDevice(
            IUnknown d3d12Device,
            DeviceCreationFlags flags,
            FeatureLevel[] featureLevels,
            IUnknown[] commandQueues,
            int nodeMask,
            out ID3D11Device device,
            out ID3D11DeviceContext immediateContext,
            out FeatureLevel chosenFeatureLevel)
        {
            var result = D3D11On12CreateDevice(d3d12Device,
                                               flags,
                                               featureLevels, featureLevels.Length,
                                               commandQueues, commandQueues.Length,
                                               nodeMask,
                                               out device, out immediateContext, out chosenFeatureLevel);

            if (result.Failure)
            {
                return(result);
            }

            if (immediateContext != null)
            {
                device.AddRef();
                device.ImmediateContext__ = immediateContext;
                immediateContext.Device__ = device;
            }

            return(result);
        }
        /// <summary>
        /// Applies alpha based sprite rendering.
        /// </summary>
        /// <param name="deviceContext">The target device context.</param>
        protected void ApplyAlphaBasedSpriteRendering(D3D11.ID3D11DeviceContext deviceContext)
        {
            deviceContext.VSSetShader(_vertexShader !.VertexShader);

            deviceContext.OMSetDepthStencilState(_defaultResources !.DepthStencilStateAlwaysPassDepth);
            deviceContext.OMSetBlendState(_defaultResources.AlphaBlendingBlendState);
        }
Exemplo n.º 3
0
        public static Result D3D11CreateDevice(IDXGIAdapter adapter,
                                               DriverType driverType,
                                               DeviceCreationFlags flags,
                                               FeatureLevel[] featureLevels,
                                               out ID3D11Device device,
                                               out FeatureLevel featureLevel,
                                               out ID3D11DeviceContext immediateContext)
        {
            var result = D3D11CreateDevice(adapter, driverType, IntPtr.Zero,
                                           (int)flags,
                                           featureLevels,
                                           (featureLevels != null) ? featureLevels.Length : 0,
                                           SdkVersion,
                                           out device,
                                           out featureLevel,
                                           out immediateContext);

            if (result.Failure)
            {
                return(result);
            }

            if (immediateContext != null)
            {
                device.AddRef();
                device.ImmediateContext__ = immediateContext;
                immediateContext.Device__ = device;
            }

            return(result);
        }
        /// <summary>
        /// Sets given content to the constant buffer.
        /// </summary>
        /// <param name="deviceContext">The context used for updating the constant buffer.</param>
        /// <param name="dataToSet">The data to set.</param>
        internal void SetData(D3D11.ID3D11DeviceContext deviceContext, T dataToSet)
        {
            var dataBox = deviceContext.Map(this.ConstantBuffer, 0, D3D11.MapMode.WriteDiscard, D3D11.MapFlags.None);

            SdxUtilities.Write(dataBox.DataPointer, ref dataToSet);
            deviceContext.Unmap(this.ConstantBuffer, 0);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Gets the highest supported hardware feature level of the primary adapter.
        /// </summary>
        /// <param name="adapter">The <see cref="IDXGIAdapter"/>.</param>
        /// <returns>The highest supported hardware feature level.</returns>
        public static FeatureLevel GetSupportedFeatureLevel(IDXGIAdapter adapter)
        {
            var                 featureLevel = FeatureLevel.Level_9_1;
            ID3D11Device        device       = null;
            ID3D11DeviceContext context      = null;

            try
            {
                D3D11CreateDevice(
                    adapter,
                    DriverType.Unknown,
                    IntPtr.Zero,
                    0,
                    null, 0,
                    SdkVersion,
                    out device, out featureLevel, out context);
            }
            finally
            {
                context?.Dispose();
                device?.Dispose();
            }

            return(featureLevel);
        }
Exemplo n.º 6
0
 public static Result D3D11CreateDevice(IDXGIAdapter adapter,
                                        DriverType driverType,
                                        DeviceCreationFlags flags,
                                        FeatureLevel[] featureLevels,
                                        out ID3D11Device device,
                                        out ID3D11DeviceContext immediateContext)
 {
     return(D3D11CreateDevice(adapter, driverType, flags, featureLevels, out device, out var featureLevel, out immediateContext));
 }
        public PipelineStatisticsQueryHelper(EngineDevice device)
        {
            var deviceD3D11 = device.DeviceD3D11_1;

            _deviceContext = device.DeviceImmediateContextD3D11;

            var queryDesc = new D3D11.QueryDescription();

            queryDesc.QueryType = D3D11.QueryType.PipelineStatistics;

            _query = deviceD3D11.CreateQuery(queryDesc);

            _deviceContext.Begin(_query);
        }
Exemplo n.º 8
0
        public static Result D3D11CreateDevice(IDXGIAdapter adapter,
                                               DriverType driverType,
                                               DeviceCreationFlags flags,
                                               FeatureLevel[] featureLevels,
                                               out ID3D11Device device)
        {
            ID3D11DeviceContext context = null;

            try
            {
                return(D3D11CreateDevice(adapter, driverType, flags, featureLevels, out device, out var featureLevel, out context));
            }
            finally
            {
                context?.Dispose();
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Check if a feature level is supported by a particular adapter.
        /// </summary>
        /// <param name="adapter">The adapter.</param>
        /// <param name="featureLevel">The feature level.</param>
        /// <returns><c>true</c> if the specified adapter is supporting this feature level; otherwise, <c>false</c>.</returns>
        public static bool IsSupportedFeatureLevel(IDXGIAdapter adapter, FeatureLevel featureLevel)
        {
            ID3D11Device        device  = null;
            ID3D11DeviceContext context = null;

            try
            {
                var result = D3D11CreateDevice(
                    adapter,
                    DriverType.Unknown,
                    IntPtr.Zero,
                    0,
                    new[] { featureLevel }, 1,
                    SdkVersion,
                    out device, out var outputLevel, out context);
                return(result.Success && outputLevel == featureLevel);
            }
            finally
            {
                context?.Dispose();
                device?.Dispose();
            }
        }
 /// <summary>
 /// Discards alpha based sprite rendering.
 /// </summary>
 /// <param name="deviceContext">The target device context.</param>
 protected void DiscardAlphaBasedSpriteRendering(D3D11.ID3D11DeviceContext deviceContext)
 {
     deviceContext.OMSetBlendState(_defaultResources !.DefaultBlendState);
     deviceContext.OMSetDepthStencilState(_defaultResources !.DepthStencilStateDefault);
 }