Ejemplo n.º 1
0
 private void PlatformInitialize()
 {
     // Allocate the hardware constant buffer.
     var desc = new SharpDX.Direct3D11.BufferDescription();
     desc.SizeInBytes = _buffer.Length;
     desc.Usage = SharpDX.Direct3D11.ResourceUsage.Default;
     desc.BindFlags = SharpDX.Direct3D11.BindFlags.ConstantBuffer;
     desc.CpuAccessFlags = SharpDX.Direct3D11.CpuAccessFlags.None;
     lock (GraphicsDevice._d3dContext)
         _cbuffer = new SharpDX.Direct3D11.Buffer(GraphicsDevice._d3dDevice, desc);
 }
Ejemplo n.º 2
0
        private void PlatformInitialize()
        {
            // Allocate the hardware constant buffer.
            var desc = new SharpDX.Direct3D11.BufferDescription();

            desc.SizeInBytes    = _buffer.Length;
            desc.Usage          = SharpDX.Direct3D11.ResourceUsage.Default;
            desc.BindFlags      = SharpDX.Direct3D11.BindFlags.ConstantBuffer;
            desc.CpuAccessFlags = SharpDX.Direct3D11.CpuAccessFlags.None;
            lock (GraphicsDevice._d3dContext)
                _cbuffer = new SharpDX.Direct3D11.Buffer(GraphicsDevice._d3dDevice, desc);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Loads all needed GPU structures
        /// </summary>
        private void LoadStructures()
        {
            var device = _graphicsDeviceManager.GraphicsDevice;

            var vertexBufferData = new[]
            {
                new ResidencyVertex(-1.0f, 0.5f, 1.0f, -1.0f, 1.0f, 0.0f),
                new ResidencyVertex(-0.5f, 1.0f, -1.0f, -1.0f, 1.0f, 0.0f),
                new ResidencyVertex(0.0f, 0.5f, -1.0f, 1.0f, 1.0f, 0.0f),
                new ResidencyVertex(0.5f, 1.0f, -1.0f, -1.0f, 1.0f, 0.0f),
                new ResidencyVertex(1.0f, 0.5f, 1.0f, -1.0f, 1.0f, 0.0f),
                new ResidencyVertex(1.0f, -0.5f, 1.0f, -1.0f, -1.0f, 0.0f),
                new ResidencyVertex(0.5f, -1.0f, 1.0f, 1.0f, -1.0f, 0.0f),
                new ResidencyVertex(0.0f, -0.5f, -1.0f, 1.0f, -1.0f, 0.0f),
                new ResidencyVertex(-0.5f, -1.0f, 1.0f, 1.0f, -1.0f, 0.0f),
                new ResidencyVertex(-1.0f, -0.5f, 1.0f, -1.0f, -1.0f, 0.0f),
                new ResidencyVertex(-0.5f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f),
                new ResidencyVertex(0.5f, 0.0f, -1.0f, -1.0f, -1.0f, 0.0f)
            };

            var indexBufferData = new[]
            {
                0, 1, 10,
                1, 2, 10,
                2, 7, 10,
                7, 8, 10,
                8, 9, 10,
                9, 0, 10,
                2, 3, 11,
                3, 4, 11,
                4, 5, 11,
                5, 6, 11,
                6, 7, 11,
                7, 2, 11
            };

            _viewerGeometry = ToDispose(new SharpDX.Toolkit.Graphics.GeometricPrimitive <ResidencyVertex>(_graphicsDeviceManager.GraphicsDevice,
                                                                                                          vertexBufferData,
                                                                                                          indexBufferData,
                                                                                                          false));

            _viewerEffect = _contentManager.Load <ResidencyViewerEffect>("ResidencyViewer");

            var tilePoolDescription = new SharpDX.Direct3D11.BufferDescription
            {
                SizeInBytes = SampleSettings.TileSizeInBytes * SampleSettings.TileResidency.PoolSizeInTiles,
                Usage       = SharpDX.Direct3D11.ResourceUsage.Default,
                OptionFlags = SharpDX.Direct3D11.ResourceOptionFlags.TilePool
            };

            _tilePool = ToDispose(SharpDX.Toolkit.Graphics.Buffer.New(device, tilePoolDescription));
        }
Ejemplo n.º 4
0
        private static void InitDevice()
        {
            m_particleBuffer             = new MyRWStructuredBuffer(MyGPUEmitters.MAX_PARTICLES, PARTICLE_STRIDE, MyRWStructuredBuffer.UAVType.Default, true, "MyGPUParticleRenderer::particleBuffer");
            m_deadListBuffer             = new MyRWStructuredBuffer(MyGPUEmitters.MAX_PARTICLES, sizeof(uint), MyRWStructuredBuffer.UAVType.Append, false, "MyGPUParticleRenderer::deadListBuffer");
            m_skippedParticleCountBuffer = new MyRWStructuredBuffer(1, sizeof(uint), MyRWStructuredBuffer.UAVType.Counter, true, "MyGPUParticleRenderer::skippedParticleCountBuffer");
#if DEBUG
            // Create a staging buffer that is used to read GPU atomic counter into that can then be mapped for reading
            // back to the CPU for debugging purposes
            m_debugCounterBuffer = new MyReadStructuredBuffer(1, sizeof(uint), "MyGPUParticleRenderer::debugCounterBuffer");
#endif
            var description = new SharpDX.Direct3D11.BufferDescription(4 * sizeof(uint),
                                                                       SharpDX.Direct3D11.ResourceUsage.Default, SharpDX.Direct3D11.BindFlags.ConstantBuffer, SharpDX.Direct3D11.CpuAccessFlags.None,
                                                                       SharpDX.Direct3D11.ResourceOptionFlags.None, sizeof(uint));
            m_activeListConstantBuffer = MyHwBuffers.CreateConstantsBuffer(description, "MyGPUParticleRenderer::activeListConstantBuffer");

            m_emitterConstantBuffer   = MyHwBuffers.CreateConstantsBuffer(EMITTERCONSTANTBUFFER_SIZE, "MyGPUParticleRenderer::emitterConstantBuffer");
            m_emitterStructuredBuffer = MyHwBuffers.CreateStructuredBuffer(MyGPUEmitters.MAX_LIVE_EMITTERS, EMITTERDATA_SIZE, true, null,
                                                                           "MyGPUParticleRenderer::emitterStructuredBuffer");

            m_aliveIndexBuffer = new MyRWStructuredBuffer(MyGPUEmitters.MAX_PARTICLES, sizeof(float), MyRWStructuredBuffer.UAVType.Counter, true,
                                                          "MyGPUParticleRenderer::aliveIndexBuffer");

            m_indirectDrawArgsBuffer = new MyIndirectArgsBuffer(5, sizeof(uint), "MyGPUParticleRenderer::indirectDrawArgsBuffer");

            unsafe
            {
                uint[] indices = new uint[MyGPUEmitters.MAX_PARTICLES * 6];
                for (uint i = 0, index = 0, vertex = 0; i < MyGPUEmitters.MAX_PARTICLES; i++)
                {
                    indices[index + 0] = vertex + 0;
                    indices[index + 1] = vertex + 1;
                    indices[index + 2] = vertex + 2;

                    indices[index + 3] = vertex + 2;
                    indices[index + 4] = vertex + 1;
                    indices[index + 5] = vertex + 3;

                    vertex += 4;
                    index  += 6;
                }

                fixed(uint *ptr = indices)
                {
                    m_ib = MyHwBuffers.CreateIndexBuffer(MyGPUEmitters.MAX_PARTICLES * 6, SharpDX.DXGI.Format.R32_UInt,
                                                         SharpDX.Direct3D11.BindFlags.IndexBuffer, SharpDX.Direct3D11.ResourceUsage.Immutable, new IntPtr(ptr), "MyGPUParticleRenderer::indexBuffer");
                }
            }

            //MyRender11.BlendAlphaPremult
        }
Ejemplo n.º 5
0
        private void Initialize()
        {
#if DIRECTX
            // Allocate the hardware constant buffer.
            var desc = new SharpDX.Direct3D11.BufferDescription();
            desc.SizeInBytes    = _buffer.Length;
            desc.Usage          = SharpDX.Direct3D11.ResourceUsage.Default;
            desc.BindFlags      = SharpDX.Direct3D11.BindFlags.ConstantBuffer;
            desc.CpuAccessFlags = SharpDX.Direct3D11.CpuAccessFlags.None;
            _cbuffer            = new SharpDX.Direct3D11.Buffer(graphicsDevice._d3dDevice, desc);
#elif OPENGL
            var data = new byte[_parameters.Length];
            for (var i = 0; i < _parameters.Length; i++)
            {
                data[i] = (byte)(_parameters[i] | _offsets[i]);
            }

            HashKey = MonoGame.Utilities.Hash.ComputeHash(data);
#endif
        }
Ejemplo n.º 6
0
        public static Buffer NewStreamOutBuffer(GraphicsDevice graphicsDevice, int sizeInBytes)
        {
            var b = (Buffer)bufferCi.Invoke(new[] { graphicsDevice });

            var bd = new BufferDescription(sizeInBytes, BufferFlags.VertexBuffer, GraphicsResourceUsage.Default);

            var nbd = new SharpDX.Direct3D11.BufferDescription()
            {
                SizeInBytes         = bd.SizeInBytes,
                StructureByteStride = 0,
                CpuAccessFlags      = SharpDX.Direct3D11.CpuAccessFlags.None,
                BindFlags           = SharpDX.Direct3D11.BindFlags.VertexBuffer | SharpDX.Direct3D11.BindFlags.StreamOutput,
                OptionFlags         = SharpDX.Direct3D11.ResourceOptionFlags.None,
                Usage = SharpDX.Direct3D11.ResourceUsage.Default
            };

            //set fields
            bufferDescriptionFi.SetValue(b, bd);
            nativeDescriptionFi.SetValue(b, nbd);
            elementCountFi.SetValue(b, 1);

            //set properties
            viewFlagsPi.SetMethod.InvokeMethod(b, bd.BufferFlags);
            viewFormatPi.SetMethod.InvokeMethod(b, PixelFormat.None);

            //set native device child
            var nb = new SharpDX.Direct3D11.Buffer(graphicsDevice.GetNativeDevice(), nbd);

            nativeDeviceChildFi.SetValue(b, nb);

            initializeViewsMi.Invoke(b, new object[0]);

            registerBufferMemoryUsageMi.InvokeMethod(graphicsDevice, b.SizeInBytes);

            return(b);
        }
Ejemplo n.º 7
0
        private void Initialize()
        {
#if DIRECTX

            // Allocate the hardware constant buffer.
            var desc = new SharpDX.Direct3D11.BufferDescription();
            desc.SizeInBytes = _buffer.Length;
            desc.Usage = SharpDX.Direct3D11.ResourceUsage.Default;
            desc.BindFlags = SharpDX.Direct3D11.BindFlags.ConstantBuffer;
            desc.CpuAccessFlags = SharpDX.Direct3D11.CpuAccessFlags.None;
            lock (GraphicsDevice._d3dContext)
                _cbuffer = new SharpDX.Direct3D11.Buffer(GraphicsDevice._d3dDevice, desc);

#elif OPENGL 

            var data = new byte[_parameters.Length];
            for (var i = 0; i < _parameters.Length; i++)
            {
                data[i] = (byte)(_parameters[i] | _offsets[i]);
            }

            HashKey = MonoGame.Utilities.Hash.ComputeHash(data);

#endif
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Resets the state of the current residency manager
        /// </summary>
        public void Reset()
        {
            _trackedTiles.Clear();
            _seenTiles.Clear();
            _loadingTiles.Clear();
            _mappedTiles.Clear();

            foreach (var resource in _managedTiledResources)
            {
                var tilings = resource.SubresourceTilings[0];

                for (var face = 0; face < 6; face++)
                {
                    resource.Residency[face] = new byte[tilings.WidthInTiles * tilings.HeightInTiles];
                    Set(resource.Residency[face], (byte)0xff);
                }
            }

            var flags = new[] { SharpDX.Direct3D11.TileRangeFlags.Null };

            var context = _graphicsDeviceManager.GetContext2();

            // mark all tiles as null
            foreach (var resource in _managedTiledResources)
            {
                context.UpdateTileMappings(resource.Texture, 1, null, null, null, 1, flags, null, null, 0);
            }

            //if (_graphicsDeviceManager.IsTier2()) return;

            // On Tier-1 devices, applications must ensure that NULL-mapped tiles are never accessed.
            // Because the mapping heuristic in this sample is only approximate, it is safest to map
            // all tiles to a dummy tile that will serve as the NULL tile.

            var device = _graphicsDeviceManager.GraphicsDevice;

            // Create a temporary buffer to clear the dummy tile to zero.
            var tempBufferDescription = new SharpDX.Direct3D11.BufferDescription
            {
                SizeInBytes = SampleSettings.TileSizeInBytes,
                OptionFlags = SharpDX.Direct3D11.ResourceOptionFlags.Tiled,
                Usage       = SharpDX.Direct3D11.ResourceUsage.Default
            };

            var defaultTileData = new byte[SampleSettings.TileSizeInBytes];
            var coordinate      = new[] { new SharpDX.Direct3D11.TiledResourceCoordinate() };
            var regionSize      = new[] { new SharpDX.Direct3D11.TileRegionSize {
                                              TileCount = 1
                                          } };
            var rangeFlags = new[] { SharpDX.Direct3D11.TileRangeFlags.ReuseSingleTile };

            using (var tempBuffer = SharpDX.Toolkit.Graphics.Buffer.New(device, tempBufferDescription))
            {
                _defaultTileIndex = _reservedTiles++;

                context.UpdateTileMappings(tempBuffer, 1, coordinate, regionSize, _tilePool, 1, rangeFlags, new[] { _defaultTileIndex }, null, 0);

                unsafe
                {
                    // Map the single tile in the buffer to physical tile 0.
                    fixed(void *pdata = &defaultTileData[0])
                    context.UpdateTiles(tempBuffer, coordinate[0], regionSize[0], new IntPtr(pdata), 0);
                }
            }

            // Map all tiles to the dummy physical tile.
            foreach (var resource in _managedTiledResources)
            {
                regionSize[0].TileCount = resource.TotalTiles;
                context.UpdateTileMappings(resource.Texture, 1, coordinate, regionSize, _tilePool, 1, rangeFlags, new[] { _defaultTileIndex }, null, 0);
                context.TiledResourceBarrier(null, (SharpDX.Direct3D11.Resource)resource.Texture);
            }
        }
        private static void InitDevice()
        {
            m_particleBuffer = new MyRWStructuredBuffer(MyGPUEmitters.MAX_PARTICLES, PARTICLE_STRIDE, MyRWStructuredBuffer.UAVType.Default, true, "MyGPUParticleRenderer::particleBuffer");
            m_deadListBuffer = new MyRWStructuredBuffer(MyGPUEmitters.MAX_PARTICLES, sizeof(uint), MyRWStructuredBuffer.UAVType.Append, false, "MyGPUParticleRenderer::deadListBuffer");
            m_skippedParticleCountBuffer = new MyRWStructuredBuffer(1, sizeof(uint), MyRWStructuredBuffer.UAVType.Counter, true, "MyGPUParticleRenderer::skippedParticleCountBuffer");
#if DEBUG
            // Create a staging buffer that is used to read GPU atomic counter into that can then be mapped for reading 
            // back to the CPU for debugging purposes
            m_debugCounterBuffer = new MyReadStructuredBuffer(1, sizeof(uint), "MyGPUParticleRenderer::debugCounterBuffer");
#endif
            var description = new SharpDX.Direct3D11.BufferDescription(4 * sizeof(uint),
                SharpDX.Direct3D11.ResourceUsage.Default, SharpDX.Direct3D11.BindFlags.ConstantBuffer, SharpDX.Direct3D11.CpuAccessFlags.None, 
                SharpDX.Direct3D11.ResourceOptionFlags.None, sizeof(uint));
            m_activeListConstantBuffer = MyHwBuffers.CreateConstantsBuffer(description, "MyGPUParticleRenderer::activeListConstantBuffer");

            m_emitterConstantBuffer = MyHwBuffers.CreateConstantsBuffer(EMITTERCONSTANTBUFFER_SIZE, "MyGPUParticleRenderer::emitterConstantBuffer");
            m_emitterStructuredBuffer = MyHwBuffers.CreateStructuredBuffer(MyGPUEmitters.MAX_LIVE_EMITTERS, EMITTERDATA_SIZE, true, null, 
                "MyGPUParticleRenderer::emitterStructuredBuffer");

            m_aliveIndexBuffer = new MyRWStructuredBuffer(MyGPUEmitters.MAX_PARTICLES, sizeof(float), MyRWStructuredBuffer.UAVType.Counter, true,
                "MyGPUParticleRenderer::aliveIndexBuffer");

            m_indirectDrawArgsBuffer = new MyIndirectArgsBuffer(5, sizeof(uint), "MyGPUParticleRenderer::indirectDrawArgsBuffer");

            unsafe
            {
                uint[] indices = new uint[MyGPUEmitters.MAX_PARTICLES * 6];
                for (uint i = 0, index = 0, vertex = 0; i < MyGPUEmitters.MAX_PARTICLES; i++)
                {
                    indices[index + 0] = vertex + 0;
                    indices[index + 1] = vertex + 1;
                    indices[index + 2] = vertex + 2;

                    indices[index + 3] = vertex + 2;
                    indices[index + 4] = vertex + 1;
                    indices[index + 5] = vertex + 3;

                    vertex += 4;
                    index += 6;
                }
                fixed (uint* ptr = indices)
                {
                    m_ib = MyHwBuffers.CreateIndexBuffer(MyGPUEmitters.MAX_PARTICLES * 6, SharpDX.DXGI.Format.R32_UInt,
                        SharpDX.Direct3D11.BindFlags.IndexBuffer, SharpDX.Direct3D11.ResourceUsage.Immutable, new IntPtr(ptr), "MyGPUParticleRenderer::indexBuffer");
                }
            }

            //MyRender11.BlendAlphaPremult
        }