Exemplo n.º 1
0
        private static int Map(TrackedTile a, TrackedTile b)
        {
            if (a.State == TileState.Loaded && b.State == TileState.Loading) return 1;
            if (a.State == TileState.Loading && b.State == TileState.Loaded) return -1;

            return Load(a, b);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Updates the residency for the provided tile
        /// </summary>
        /// <param name="tile">The tile whose information needs to be updated.</param>
        /// <param name="isMin">Whether to decrease or increase the mip level (for evicted and mapped tiles)</param>
        private static void UpdateResidencyMap(TrackedTile tile, bool isMin)
        {
            var srte1 = tile.ManagedTiledResource.SubresourceTilings[0];
            var srte2 = tile.ManagedTiledResource.SubresourceTilings[tile.Coordinate.Subresource];

            var coveredWidth  = srte1.WidthInTiles / srte2.WidthInTiles;
            var coveredHeight = srte1.HeightInTiles / srte2.HeightInTiles;

            for (var y = 0; y < coveredHeight; y++)
            {
                for (var x = 0; x < coveredWidth; x++)
                {
                    var tileX = tile.Coordinate.X * coveredWidth + x;
                    var tileY = tile.Coordinate.Y * coveredHeight + y;

                    var residency = tile.ManagedTiledResource.Residency[tile.Face];

                    var index = tileY * srte1.WidthInTiles + tileX;

                    var v1 = (byte)((tile.MipLevel + 1) * 16);
                    var v2 = residency[index];
                    residency[index] = isMin ? Math.Min(v1, v2) : Math.Max(v1, v2);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Process decoded samples to determine which tiles are brought into view and need to be loaded
        /// </summary>
        /// <param name="samples">The list of the samples</param>
        public void EnqueueSamples(List <DecodedSample> samples)
        {
            foreach (var sample in samples)
            {
                // iterate trough each managed resource for each sample
                foreach (var resource in _managedTiledResources)
                {
                    var desc = resource.Texture.Description;

                    var mipCount = desc.Format == SharpDX.Toolkit.Graphics.PixelFormat.BC1.UNorm
                                       ? SampleSettings.TerrainAssets.Diffuse.UnpackedMipCount
                                       : SampleSettings.TerrainAssets.Normal.UnpackedMipCount;

                    // determine the available mip level
                    var actualMip = Math.Max(0, Math.Min(mipCount - 1, sample.Mip));

                    // process all mip levels from the current one to the least detailed
                    for (var mip = actualMip; mip < desc.MipLevels; mip++)
                    {
                        var coordinate = new SharpDX.Direct3D11.TiledResourceCoordinate();
                        coordinate.Subresource = mip + sample.Face * desc.MipLevels; // compute subresource index

                        var widthInTiles  = resource.SubresourceTilings[coordinate.Subresource].WidthInTiles;
                        var heightInTiles = resource.SubresourceTilings[coordinate.Subresource].HeightInTiles;

                        // compute tile coordinate in the face texture for the current mip level
                        coordinate.X = (int)Math.Min(widthInTiles - 1, Math.Max(0, widthInTiles * sample.U));
                        coordinate.Y = (int)Math.Min(heightInTiles - 1, Math.Max(0, heightInTiles * sample.V));

                        var         key = new TileKey(coordinate, resource.Texture);
                        TrackedTile trackedTile;
                        // if the tile has not been tracked yet - mark it as seen
                        if (!_trackedTiles.TryGetValue(key, out trackedTile))
                        {
                            trackedTile = new TrackedTile(resource, coordinate, (short)mip, sample.Face)
                            {
                                lastSeen = _frame,
                                State    = TileState.Seen
                            };

                            _trackedTiles[key] = trackedTile;
                            _seenTiles.Add(trackedTile);
                        }
                        else // ... otherwise just update its last seen time
                        {
                            trackedTile.lastSeen = _frame;
                        }
                    }
                }
            }

            _frame++;
        }
Exemplo n.º 4
0
        private static int Map(TrackedTile a, TrackedTile b)
        {
            if (a.State == TileState.Loaded && b.State == TileState.Loading)
            {
                return(1);
            }
            if (a.State == TileState.Loading && b.State == TileState.Loaded)
            {
                return(-1);
            }

            return(Load(a, b));
        }
Exemplo n.º 5
0
 private static int Evict(TrackedTile a, TrackedTile b)
 {
     return -Load(b, a);
 }
Exemplo n.º 6
0
 private static int Load(TrackedTile a, TrackedTile b)
 {
     var result = a.lastSeen.CompareTo(b.lastSeen);
     return result != 0 ? result : a.MipLevel.CompareTo(b.MipLevel);
 }
Exemplo n.º 7
0
 private static int Evict(TrackedTile a, TrackedTile b)
 {
     return(-Load(b, a));
 }
Exemplo n.º 8
0
        private static int Load(TrackedTile a, TrackedTile b)
        {
            var result = a.lastSeen.CompareTo(b.lastSeen);

            return(result != 0 ? result : a.MipLevel.CompareTo(b.MipLevel));
        }