Example #1
0
        private void UpdateReference(GraphicsResourceBase resource, int referenceDelta)
        {
            if (resource == null)
            {
                return;
            }

            bool resourceFound = false;

            switch (resource)
            {
            case Texture texture:
                resourceFound = UpdateReferenceCount(textureCache, texture, getTextureDefinitionDelegate, referenceDelta);
                break;

            case Buffer buffer:
                resourceFound = UpdateReferenceCount(bufferCache, buffer, getBufferDescriptionDelegate, referenceDelta);
                break;

            case QueryPool queryPool:
                resourceFound = UpdateReferenceCount(queryPoolCache, queryPool, getQueryPoolDescriptionDelegate, referenceDelta);
                break;

            default:
                throw new ArgumentException("Unsupported graphics resource. Only Textures, Buffers and QueryPools are supported", nameof(resource));
            }

            if (!resourceFound)
            {
                throw new ArgumentException("The resource was not allocated by this allocator");
            }
        }
Example #2
0
 /// <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);
     }
 }
        /// <summary>
        ///   Initializes the device for the specified profile.
        /// </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;

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

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

                    RequestedProfile = graphicsProfile;
                    break;
                }
                catch
                {
                    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");
            }
        }
        /// <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;

            // 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;
                        }
                    }

                    if (Core.Platform.Type == PlatformType.Windows &&
                        GetModuleHandle("renderdoc.dll") != IntPtr.Zero)
                    {
                        if (level < SharpDX.Direct3D.FeatureLevel.Level_11_0)
                        {
                            level = SharpDX.Direct3D.FeatureLevel.Level_11_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");
            }
        }
 /// <summary>
 ///   Initializes a new instance of the <see cref="GraphicsResourceLink"/> class.
 /// </summary>
 /// <param name="resource">The graphics resource.</param>
 /// <exception cref="ArgumentNullException"><paramref name="resource"/> is a <c>null</c> reference.</exception>
 internal GraphicsResourceLink(GraphicsResourceBase resource)
 {
     Resource = resource ?? throw new ArgumentNullException(nameof(resource));
 }