/// <summary>
 /// Decrements the reference to a temporary resource.
 /// </summary>
 /// <param name="resource"></param>
 public void ReleaseReference(GraphicsResourceBase resource)
 {
     // Global lock to be threadsafe.
     lock (thisLock)
     {
         UpdateReference(resource, -1);
     }
 }
Esempio n. 2
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;

            // Map GraphicsProfile to D3D11 FeatureLevel
            creationFlags = (SharpDX.Direct3D11.DeviceCreationFlags)deviceCreationFlags;

            // Default fallback
            if (graphicsProfiles.Length == 0)
            {
                graphicsProfiles = new[] { GraphicsProfile.Level_11_0, GraphicsProfile.Level_10_1, GraphicsProfile.Level_10_0, GraphicsProfile.Level_9_3, GraphicsProfile.Level_9_2, GraphicsProfile.Level_9_1 }
            }
            ;

            // Create Device D3D11 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();

                    // INTEL workaround: it seems Intel driver doesn't support properly feature level 9.x. Fallback to 10.
                    if (Adapter.VendorId == 0x8086)
                    {
                        if (level < SharpDX.Direct3D.FeatureLevel.Level_10_0)
                        {
                            level = SharpDX.Direct3D.FeatureLevel.Level_10_0;
                        }
                    }

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

                    // INTEL workaround: force ShaderProfile to be 10+ as well
                    if (Adapter.VendorId == 0x8086)
                    {
                        if (graphicsProfile < GraphicsProfile.Level_10_0 && (!ShaderProfile.HasValue || ShaderProfile.Value < GraphicsProfile.Level_10_0))
                        {
                            ShaderProfile = GraphicsProfile.Level_10_0;
                        }
                    }

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

            nativeDeviceContext = nativeDevice.ImmediateContext;
            // We keep one reference so that it doesn't disappear with InternalMainCommandList
            ((IUnknown)nativeDeviceContext).AddReference();
            if (IsDebugMode)
            {
                GraphicsResourceBase.SetDebugName(this, nativeDeviceContext, "ImmediateContext");
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GraphicsResourceLink"/> class.
 /// </summary>
 /// <param name="resource">The graphics resource.</param>
 /// <exception cref="System.ArgumentNullException">resource</exception>
 internal GraphicsResourceLink(GraphicsResourceBase resource)
 {
     Resource = resource ?? throw new ArgumentNullException(nameof(resource));
 }
Esempio n. 4
0
 /// <summary>
 /// Decrements the reference to a temporary resource.
 /// </summary>
 /// <param name="resource"></param>
 public void ReleaseReference(GraphicsResourceBase resource)
 {
     UpdateReference(resource, -1);
 }