示例#1
0
        internal void TagResource(GraphicsResourceLink resourceLink)
        {
            switch (resourceLink.Resource)
            {
            case Texture texture:
                if (texture.Usage == GraphicsResourceUsage.Dynamic)
                {
                    // Increase the reference count until GPU is done with the resource
                    resourceLink.ReferenceCount++;
                    graphicsResourceLinkCollector.Add(NextFenceValue, resourceLink);
                }
                break;

            case Buffer buffer:
                if (buffer.Usage == GraphicsResourceUsage.Dynamic)
                {
                    // Increase the reference count until GPU is done with the resource
                    resourceLink.ReferenceCount++;
                    graphicsResourceLinkCollector.Add(NextFenceValue, resourceLink);
                }
                break;

            case QueryPool _:
                resourceLink.ReferenceCount++;
                graphicsResourceLinkCollector.Add(NextFenceValue, resourceLink);
                break;
            }
        }
 internal void TagResource(GraphicsResourceLink resourceLink)
 {
     if (resourceLink.Resource is GraphicsResource resource)
     {
         resource.DiscardNextMap = true;
     }
 }
示例#3
0
        private TResource GetTemporaryResource <TResource, TKey>(Dictionary <TKey, List <GraphicsResourceLink> > cache, TKey description, Func <TKey, PixelFormat, TResource> creator, Func <TResource, TKey> getDefinition, PixelFormat viewFormat)
            where TResource : GraphicsResourceBase
            where TKey : struct
        {
            // For a specific description, get allocated textures
            List <GraphicsResourceLink> resourceLinks;

            if (!cache.TryGetValue(description, out resourceLinks))
            {
                resourceLinks = new List <GraphicsResourceLink>();
                cache.Add(description, resourceLinks);
            }

            // Find a texture available
            foreach (var resourceLink in resourceLinks)
            {
                if (resourceLink.ReferenceCount == 0)
                {
                    UpdateCounter(resourceLink, 1);
                    return((TResource)resourceLink.Resource);
                }
            }

            // If no texture available, then creates a new one
            var newResource = creator(description, viewFormat);

            newResource.Name = string.Format("{0}{1}-{2}", Name == null ? string.Empty : string.Format("{0}-", Name), newResource.Name == null ? newResource.GetType().Name : Name, resourceLinks.Count);

            // Description may be altered when creating a resource (based on HW limitations...etc.) so we get the actual description
            var realDescription = getDefinition(newResource);

            // For a specific description, get allocated textures
            if (!cache.TryGetValue(realDescription, out resourceLinks))
            {
                resourceLinks = new List <GraphicsResourceLink>();
                cache.Add(description, resourceLinks);
            }

            // Add the texture to the allocated textures
            // Start RefCount == 1, because we don't want this texture to be available if a post FxProcessor is calling
            // several times this GetTemporaryTexture method.
            var newResourceLink = new GraphicsResourceLink(newResource)
            {
                ReferenceCount = 1
            };

            resourceLinks.Add(newResourceLink);

            return(newResource);
        }
示例#4
0
        private void UpdateCounter(GraphicsResourceLink resourceLink, int deltaCount)
        {
            if ((resourceLink.ReferenceCount + deltaCount) < 0)
            {
                throw new InvalidOperationException("Invalid decrement on reference count (must be >=0 after decrement). Current reference count: [{0}] Decrement: [{1}]".ToFormat(resourceLink.ReferenceCount, deltaCount));
            }

            resourceLink.ReferenceCount += deltaCount;
            resourceLink.AccessTotalCount++;
            resourceLink.AccessCountSinceLastRecycle++;
            resourceLink.LastAccessTime = DateTime.Now;

            if (resourceLink.ReferenceCount == 0)
            {
                GraphicsDevice.TagResource(resourceLink);
            }
        }
示例#5
0
        internal void TagResource(GraphicsResourceLink resourceLink)
        {
            var texture = resourceLink.Resource as Texture;

            if (texture != null && texture.Usage == GraphicsResourceUsage.Dynamic)
            {
                // Increase the reference count until GPU is done with the resource
                resourceLink.ReferenceCount++;
                TemporaryResources.Enqueue(new KeyValuePair <long, object>(NextFenceValue, resourceLink));
            }

            var buffer = resourceLink.Resource as Buffer;

            if (buffer != null && buffer.Usage == GraphicsResourceUsage.Dynamic)
            {
                // Increase the reference count until GPU is done with the resource
                resourceLink.ReferenceCount++;
                TemporaryResources.Enqueue(new KeyValuePair <long, object>(NextFenceValue, resourceLink));
            }
        }
示例#6
0
 /// <summary>
 /// The default recycle policy is always going to remove all allocated textures.
 /// </summary>
 /// <param name="resourceLink">The resource link.</param>
 /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
 private static bool DefaultRecyclePolicy(GraphicsResourceLink resourceLink)
 {
     return(true);
 }
 /// <summary>
 ///   Default recycle policy. Always remove all allocated resources.
 /// </summary>
 /// <param name="resourceLink">The resource link.</param>
 private static bool DefaultRecyclePolicy(GraphicsResourceLink resourceLink) => true;