unsafe void IManagerDevice.OnDeviceInit()
        {
            if (m_markerConstantBuffer == ConstantsBufferId.NULL)
                m_markerConstantBuffer = MyHwBuffers.CreateConstantsBuffer(sizeof(MyMarkerConstants), "MyPostprocessMarkCascades.MarkerConstantBuffer");

            if (m_psMarker == PixelShaderId.NULL)
                m_psMarker = MyShaders.CreatePs("Shadows\\StencilMarker.hlsl");
            if (m_vsMarker == VertexShaderId.NULL)
                m_vsMarker = MyShaders.CreateVs("Shadows\\StencilMarker.hlsl");
            if (m_psDrawCoverage == PixelShaderId.NULL)
                m_psDrawCoverage = MyShaders.CreatePs("Shadows\\CascadeCoverage.hlsl");
            if (m_inputLayout == InputLayoutId.NULL)
                m_inputLayout = MyShaders.CreateIL(m_vsMarker.BytecodeId, MyVertexLayouts.GetLayout(MyVertexInputComponentType.POSITION3));

            m_vertexBuffer = CreateVertexBuffer();
            m_indexBuffer = CreateIndexBuffer();
        }
Пример #2
0
 internal void ReleaseBuffers()
 {
     if(IB != IndexBufferId.NULL)
     {
         MyHwBuffers.Destroy(IB);
         IB = IndexBufferId.NULL;
     }
     if(VB != null)
     {
         foreach(var vb in VB)
         {
             //vb.Dispose();
             MyHwBuffers.Destroy(vb);
         }
         VB = null;
     }
 }
Пример #3
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");
 
            // 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_debugCounterBuffers[0] = new MyReadStructuredBuffer(1, sizeof(uint), "MyGPUParticleRenderer::debugCounterBuffers[0]");
            m_debugCounterBuffers[1] = new MyReadStructuredBuffer(1, sizeof(uint), "MyGPUParticleRenderer::debugCounterBuffers[1]");

            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
        }
Пример #4
0
 internal static void InitIndexBuffer(IndexBufferId id, IntPtr data)
 {
     IBuffersData[id.Index].Buffer = new Buffer(MyRender11.Device, data, IBuffers.Data[id.Index].Description);
     if (IBuffers.Data[id.Index].DebugName != null)
     {
         IBuffersData[id.Index].Buffer.DebugName = IBuffers.Data[id.Index].DebugName;
     }
 }
Пример #5
0
 internal static Format GetIndexBufferFormat(IndexBufferId id)
 {
     return IBuffersData[id.Index].Format;
 }
Пример #6
0
 internal static Buffer GetIndexBuffer(IndexBufferId id)
 {
     return IBuffersData[id.Index].Buffer;
 }
Пример #7
0
 internal static BufferDescription GetBufferDesc(IndexBufferId id)
 {
     return IBuffers.Data[id.Index].Description;
 }
Пример #8
0
 internal static void Destroy(IndexBufferId id)
 {
     IbIndices.Remove(id);
     if (IBuffersData[id.Index].Buffer != null)
     {
         IBuffersData[id.Index].Buffer.Dispose();
         IBuffersData[id.Index].Buffer = null;
     }
     IBuffers.Free(id.Index);
 }
Пример #9
0
 internal static void Destroy(ref IndexBufferId id)
 {
     if (id != IndexBufferId.NULL)
     {
         Destroy(id); id = IndexBufferId.NULL;
     }
 }
Пример #10
0
        internal static IndexBufferId CreateIndexBuffer(BufferDescription description, Format format, IntPtr ? data, string debugName)
        {
            var id = new IndexBufferId { Index = IBuffers.Allocate() };
            MyArrayHelpers.Reserve(ref IBuffersData, id.Index + 1);
            IBuffers.Data[id.Index] = new MyHwBufferDesc { Description = description, DebugName = debugName };
            IBuffersData[id.Index] = new MyIndexBufferData { Format = format };

            IbIndices.Add(id);

            if (!data.HasValue)
            {
                InitIndexBuffer(id);
            }
            else
            {
                InitIndexBuffer(id, data.Value);
            }

            return id;
        }
        void IManagerDevice.OnDeviceReset()
        {
            MyHwBuffers.Destroy(m_vertexBuffer);
            m_vertexBuffer = CreateVertexBuffer();

            MyHwBuffers.Destroy(m_indexBuffer);
            m_indexBuffer = CreateIndexBuffer();
        }
 private void DestroyIndexBuffer()
 {
     if (m_cubeIB != IndexBufferId.NULL)
     {
         MyHwBuffers.Destroy(m_cubeIB);
         m_cubeIB = IndexBufferId.NULL;
     }
 }
        private unsafe void InitIndexBuffer()
        {
            DestroyIndexBuffer();

            const int indexCount = 36;
            ushort* indices = stackalloc ushort[indexCount];
            indices[0] = 0; indices[1] = 1; indices[2] = 2;
            indices[3] = 0; indices[4] = 2; indices[5] = 3;
            indices[6] = 1; indices[7] = 5; indices[8] = 6;
            indices[9] = 1; indices[10] = 6; indices[11] = 2;
            indices[12] = 5; indices[13] = 4; indices[14] = 7;
            indices[15] = 5; indices[16] = 7; indices[17] = 6;
            indices[18] = 4; indices[19] = 0; indices[20] = 3;
            indices[21] = 4; indices[22] = 3; indices[23] = 7;
            indices[24] = 3; indices[25] = 2; indices[26] = 6;
            indices[27] = 3; indices[28] = 6; indices[29] = 7;
            indices[30] = 1; indices[31] = 0; indices[32] = 4;
            indices[33] = 1; indices[34] = 4; indices[35] = 5;

            m_cubeIB = MyHwBuffers.CreateIndexBuffer(indexCount, Format.R16_UInt, BindFlags.IndexBuffer, ResourceUsage.Immutable, new IntPtr(indices), "MyScreenDecals");
        }