Beispiel #1
0
 internal static void ResizeAndUpdateStaticStructuredBuffer(ref StructuredBufferId id, int capacity, int stride, IntPtr data, string debugName, DeviceContext context = null)
 {
     if (id == StructuredBufferId.NULL)
     {
         id = CreateStructuredBuffer(capacity, stride, false, data, debugName);
     }
     else
     {
         Debug.Assert(stride == id.Stride);
         Debug.Assert(false == id.Dynamic);
         if (id.Capacity < capacity)
         {
             SBuffersData[id.Index].Buffer.Dispose();
             SBuffers.Data[id.Index].Description.SizeInBytes = stride * capacity;
             InitStructuredBuffer(id, data);
         }
         else
         {
             if (context == null)
             {
                 context = MyRender11.DeviceContext;
             }
             context.UpdateSubresource(new DataBox(data, stride * capacity, 0), id.Buffer);
         }
     }
 }
Beispiel #2
0
        internal static StructuredBufferId CreateStructuredBuffer(BufferDescription description, IntPtr?data, string debugName)
        {
            var id = new StructuredBufferId {
                Index = SBuffers.Allocate()
            };

            MyArrayHelpers.Reserve(ref SBuffersData, id.Index + 1);
            SBuffers.Data[id.Index] = new MyHwBufferDesc {
                Description = description, DebugName = debugName
            };
            SBuffersData[id.Index] = new MyStructuredBufferData {
            };

            SbIndices.Add(id);

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

            return(id);
        }
Beispiel #3
0
 internal static void Destroy(ref StructuredBufferId id)
 {
     if (id != StructuredBufferId.NULL)
     {
         Destroy(id); id = StructuredBufferId.NULL;
     }
 }
Beispiel #4
0
        internal unsafe static void Init()
        {
            m_cbCustomProjections = MyHwBuffers.CreateConstantsBuffer(sizeof(Matrix) * MAX_CUSTOM_PROJECTIONS_SIZE, "BilloardCustomProjections");

            m_vs          = MyShaders.CreateVs("Transparent/Billboards.hlsl");
            m_vsDepthOnly = MyShaders.CreateVs("Transparent/BillboardsDepthOnly.hlsl");
            m_ps          = MyShaders.CreatePs("Transparent/Billboards.hlsl");
            m_psDepthOnly = MyShaders.CreatePs("Transparent/BillboardsDepthOnly.hlsl");
            m_psOIT       = MyShaders.CreatePs("Transparent/Billboards.hlsl", new[] { new ShaderMacro("OIT", null) });
            m_vsLit       = MyShaders.CreateVs("Transparent/Billboards.hlsl", new[] { new ShaderMacro("LIT_PARTICLE", null) });
            m_psLit       = MyShaders.CreatePs("Transparent/Billboards.hlsl", new[] { new ShaderMacro("LIT_PARTICLE", null) });
            m_psLitOIT    = MyShaders.CreatePs("Transparent/Billboards.hlsl", new[] { new ShaderMacro("LIT_PARTICLE", null), new ShaderMacro("OIT", null) });

            m_psAlphaCutout       = MyShaders.CreatePs("Transparent/Billboards.hlsl", new[] { new ShaderMacro("ALPHA_CUTOUT", null) });
            m_psAlphaCutoutAndLit = MyShaders.CreatePs("Transparent/Billboards.hlsl",
                                                       new[] { new ShaderMacro("ALPHA_CUTOUT", null), new ShaderMacro("LIT_PARTICLE", null) });
            m_psAlphaCutoutOIT = MyShaders.CreatePs("Transparent/Billboards.hlsl",
                                                    new[] { new ShaderMacro("ALPHA_CUTOUT", null), new ShaderMacro("OIT", null) });
            m_psAlphaCutoutAndLitOIT = MyShaders.CreatePs("Transparent/Billboards.hlsl",
                                                          new[] { new ShaderMacro("ALPHA_CUTOUT", null), new ShaderMacro("LIT_PARTICLE", null), new ShaderMacro("OIT", null) });

            m_psDebugUniformAccum    = MyShaders.CreatePs("Transparent/Billboards.hlsl", new[] { new ShaderMacro("DEBUG_UNIFORM_ACCUM", null) });
            m_psDebugUniformAccumOIT = MyShaders.CreatePs("Transparent/Billboards.hlsl", new[] { new ShaderMacro("DEBUG_UNIFORM_ACCUM", null), new ShaderMacro("OIT", null) });

            m_inputLayout = MyShaders.CreateIL(m_vs.BytecodeId, MyVertexLayouts.GetLayout(MyVertexInputComponentType.POSITION3, MyVertexInputComponentType.TEXCOORD0_H));

            InitBillboardsIndexBuffer();

            m_VB = MyHwBuffers.CreateVertexBuffer(MAX_BILLBOARDS_SIZE * 4, sizeof(MyVertexFormatPositionTextureH), BindFlags.VertexBuffer, ResourceUsage.Dynamic, null, "MyBillboardRenderer");

            var stride = sizeof(MyBillboardData);

            m_SB    = MyHwBuffers.CreateStructuredBuffer(MAX_BILLBOARDS_SIZE, stride, true, null, "MyBillboardRenderer");
            m_atlas = new MyTextureAtlas("Textures\\Particles\\", "Textures\\Particles\\ParticlesAtlas.tai");
        }
Beispiel #5
0
 internal static void OnDeviceReset()
 {
     if (m_buffer != StructuredBufferId.NULL)
     {
         MyHwBuffers.Destroy(m_buffer);
         m_buffer = StructuredBufferId.NULL;
     }
     Init();
 }
 internal static void OnDeviceReset()
 {
     if (m_buffer != StructuredBufferId.NULL)
     {
         MyHwBuffers.Destroy(m_buffer);
         m_buffer = StructuredBufferId.NULL;
     }
     Init();
 }
Beispiel #7
0
 internal static void InitStructuredBuffer(StructuredBufferId id, IntPtr data)
 {
     SBuffersData[id.Index].Buffer = new Buffer(MyRender11.Device, data, SBuffers.Data[id.Index].Description);
     SBuffersData[id.Index].Srv    = new ShaderResourceView(MyRender11.Device, SBuffersData[id.Index].Buffer);
     if (SBuffers.Data[id.Index].DebugName != null)
     {
         SBuffersData[id.Index].Buffer.DebugName = SBuffers.Data[id.Index].DebugName;
         SBuffersData[id.Index].Srv.DebugName    = SBuffers.Data[id.Index].DebugName;
     }
 }
        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
        }
Beispiel #9
0
        internal void Release()
        {
            if (m_VB_positions != StructuredBufferId.NULL)
            {
                MyHwBuffers.Destroy(m_VB_positions);
                MyHwBuffers.Destroy(m_VB_rest);
                MyHwBuffers.Destroy(m_IB);
            }

            m_VB_positions = StructuredBufferId.NULL;
            m_VB_rest      = StructuredBufferId.NULL;
            m_IB           = StructuredBufferId.NULL;
        }
        internal unsafe void MoveToGPU()
        {
            var context = MyImmediateRC.RC.DeviceContext;

            if (m_tableDirty)
            {
                var array = m_instancingTable.Data;

                fixed(void *ptr = array)
                {
                    var intPtr = new IntPtr(ptr);

                    MyHwBuffers.ResizeAndUpdateStaticStructuredBuffer(ref m_indirectionBuffer, array.Length, sizeof(MyInstancingTableEntry), intPtr,
                                                                      "MyMergeInstancing/Tables", context);
                    m_SRVs[0] = m_indirectionBuffer.Srv;
                }

                m_tableDirty = false;
            }

            if (m_instancesDataDirty)
            {
                var array = m_perInstance.Data;

                fixed(void *ptr = array)
                {
                    var intPtr = new IntPtr(ptr);

                    if (m_instanceBuffer != StructuredBufferId.NULL && m_instanceBuffer.Capacity < array.Length)
                    {
                        MyHwBuffers.Destroy(m_instanceBuffer);
                        m_instanceBuffer = StructuredBufferId.NULL;
                        m_SRVs[1]        = null;
                    }
                    if (m_instanceBuffer == StructuredBufferId.NULL)
                    {
                        m_instanceBuffer = MyHwBuffers.CreateStructuredBuffer(array.Length, sizeof(MyPerInstanceData), true, intPtr, "MyMergeInstancing instances");
                        m_SRVs[1]        = m_instanceBuffer.Srv;
                    }
                    else
                    {
                        var mapping = MyMapping.MapDiscard(context, m_instanceBuffer.Buffer);
                        mapping.WriteAndPosition(array, 0, array.Length);
                        mapping.Unmap();
                    }
                }

                m_instancesDataDirty = false;
            }
        }
Beispiel #11
0
 internal static void Destroy(StructuredBufferId id)
 {
     SbIndices.Remove(id);
     if (SBuffersData[id.Index].Buffer != null)
     {
         SBuffersData[id.Index].Buffer.Dispose();
         SBuffersData[id.Index].Buffer = null;
     }
     if (SBuffersData[id.Index].Srv != null)
     {
         SBuffersData[id.Index].Srv.Dispose();
         SBuffersData[id.Index].Srv = null;
     }
     SBuffers.Free(id.Index);
 }
        internal void OnDeviceReset()
        {
            if (m_indirectionBuffer != StructuredBufferId.NULL)
            {
                MyHwBuffers.Destroy(m_indirectionBuffer);
                MyHwBuffers.Destroy(m_instanceBuffer);
            }

            m_indirectionBuffer = StructuredBufferId.NULL;
            m_instanceBuffer    = StructuredBufferId.NULL;
            Array.Clear(m_SRVs, 0, m_SRVs.Length);

            m_tableDirty         = true;
            m_instancesDataDirty = true;
        }
        internal unsafe static void Init()
        {
            m_vs          = MyShaders.CreateVs("billboard.hlsl", "vs");
            m_ps          = MyShaders.CreatePs("billboard.hlsl", "ps");
            m_vsLit       = MyShaders.CreateVs("billboard.hlsl", "vs", MyShaderHelpers.FormatMacros("LIT_PARTICLE"));
            m_psLit       = MyShaders.CreatePs("billboard.hlsl", "ps", MyShaderHelpers.FormatMacros("LIT_PARTICLE"));
            m_inputLayout = MyShaders.CreateIL(m_vs.BytecodeId, MyVertexLayouts.GetLayout(MyVertexInputComponentType.POSITION3, MyVertexInputComponentType.TEXCOORD0_H));

            //MyCallbacks.RegisterDeviceResetListener(new OnDeviceResetDelegate(OnDeviceRestart));

            InitBillboardsIndexBuffer(MaxBillboards);

            m_VB = MyHwBuffers.CreateVertexBuffer(MaxBillboards * 4, sizeof(MyVertexFormatPositionTextureH), BindFlags.VertexBuffer, ResourceUsage.Dynamic);

            var stride = sizeof(MyBillboardData);

            m_SB = MyHwBuffers.CreateStructuredBuffer(MaxBillboards, stride, true);

            MyTextureAtlas.ParseAtlasDescription("Textures\\Particles\\", "Textures\\Particles\\ParticlesAtlas.tai", m_atlasedTextures);
        }
        internal unsafe static void Init()
        {
            m_vs    = MyShaders.CreateVs("billboard.hlsl");
            m_ps    = MyShaders.CreatePs("billboard.hlsl");
            m_vsLit = MyShaders.CreateVs("billboard.hlsl", new [] { new ShaderMacro("LIT_PARTICLE", null) });
            m_psLit = MyShaders.CreatePs("billboard.hlsl", new[] { new ShaderMacro("LIT_PARTICLE", null) });

            m_psAlphaCutout       = MyShaders.CreatePs("billboard.hlsl", new[] { new ShaderMacro("ALPHA_CUTOUT", null) });
            m_psAlphaCutoutAndLit = MyShaders.CreatePs("billboard.hlsl", new[] { new ShaderMacro("ALPHA_CUTOUT", null), new ShaderMacro("LIT_PARTICLE", null) });

            m_inputLayout = MyShaders.CreateIL(m_vs.BytecodeId, MyVertexLayouts.GetLayout(MyVertexInputComponentType.POSITION3, MyVertexInputComponentType.TEXCOORD0_H));

            //MyCallbacks.RegisterDeviceResetListener(new OnDeviceResetDelegate(OnDeviceRestart));

            InitBillboardsIndexBuffer(MaxBillboards);

            m_VB = MyHwBuffers.CreateVertexBuffer(MaxBillboards * 4, sizeof(MyVertexFormatPositionTextureH), BindFlags.VertexBuffer, ResourceUsage.Dynamic, null, "MyBillboardRenderer");

            var stride = sizeof(MyBillboardData);

            m_SB    = MyHwBuffers.CreateStructuredBuffer(MaxBillboards, stride, true, null, "MyBillboardRenderer");
            m_atlas = new MyTextureAtlas("Textures\\Particles\\", "Textures\\Particles\\ParticlesAtlas.tai");
        }
Beispiel #15
0
        internal unsafe void MoveToGPU()
        {
            if (m_dirty)
            {
                Release();

                fixed(void *ptr = m_vertexStream0)
                {
                    m_VB_positions = MyHwBuffers.CreateStructuredBuffer(m_vertices, Stride0, false, new IntPtr(ptr), "MyMergeInstancing positions");
                }

                fixed(void *ptr = m_vertexStream1)
                {
                    m_VB_rest = MyHwBuffers.CreateStructuredBuffer(m_vertices, Stride1, false, new IntPtr(ptr), "MyMergeInstancing rest");
                }

                fixed(void *ptr = m_indexStream)
                {
                    m_IB = MyHwBuffers.CreateStructuredBuffer(m_indices, IndexStride, false, new IntPtr(ptr), "MyMergeInstancing");
                }

                m_dirty = false;
            }
        }
        internal unsafe void MoveToGPU()
        {
            var context = MyImmediateRC.RC.DeviceContext;

            if (m_tablesDirty)
            {
                var array = m_instancingTable.Data;

                fixed (void* ptr = array)
                {
                    var intPtr = new IntPtr(ptr);
                    MyHwBuffers.ResizeAndUpdateStaticStructuredBuffer(ref m_indirectionBuffer, array.Length, sizeof(MyInstancingTableEntry), intPtr, 
                        "MyMergeInstancing/Tables", context);
                    m_SRVs[0] = m_indirectionBuffer.Srv;
                }

                m_tablesDirty = false;
            }

            if (m_instancesDataDirty)
            {
                var array = m_perInstance.Data;

                fixed (void* ptr = array)
                {
                    var intPtr = new IntPtr(ptr);

                    if (m_instanceBuffer != StructuredBufferId.NULL && m_instanceBuffer.Capacity < array.Length)
                    {
                        MyHwBuffers.Destroy(m_instanceBuffer);
                        m_instanceBuffer = StructuredBufferId.NULL;
                        m_SRVs[1] = null;
                    }
                    if (m_instanceBuffer == StructuredBufferId.NULL)
                    {
                        m_instanceBuffer = MyHwBuffers.CreateStructuredBuffer(array.Length, sizeof(MyPerInstanceData), true, intPtr);
                        m_SRVs[1] = m_instanceBuffer.Srv;
                    }
                    else
                    {
                        var mapping = MyMapping.MapDiscard(context, m_instanceBuffer.Buffer);
                        mapping.WriteAndPosition(array, 0, array.Length);
                        mapping.Unmap();
                    }
                }

                m_instancesDataDirty = false;
            }
        }
        internal void OnDeviceReset()
        {
            if (m_indirectionBuffer != StructuredBufferId.NULL)
            {
                MyHwBuffers.Destroy(m_indirectionBuffer);
                MyHwBuffers.Destroy(m_instanceBuffer);
            }

            m_indirectionBuffer = StructuredBufferId.NULL;
            m_instanceBuffer = StructuredBufferId.NULL;
            Array.Clear(m_SRVs, 0, m_SRVs.Length);

            m_tablesDirty = true;
            m_instancesDataDirty = true;
        }
Beispiel #18
0
 internal static void Destroy(StructuredBufferId id)
 {
     SbIndices.Remove(id);
     if (SBuffersData[id.Index].Buffer != null)
     {
         SBuffersData[id.Index].Buffer.Dispose();
         SBuffersData[id.Index].Buffer = null;
     }
     if (SBuffersData[id.Index].Srv != null)
     {
         SBuffersData[id.Index].Srv.Dispose();
         SBuffersData[id.Index].Srv = null;
     }
     SBuffers.Free(id.Index);
 }
Beispiel #19
0
        internal static StructuredBufferId CreateStructuredBuffer(BufferDescription description, IntPtr? data = null, string debugName = null)
        {
            var id = new StructuredBufferId { Index = SBuffers.Allocate() };
            MyArrayHelpers.Reserve(ref SBuffersData, id.Index + 1);
            SBuffers.Data[id.Index] = new MyHwBufferDesc { Description = description, DebugName = debugName };
            SBuffersData[id.Index] = new MyStructuredBufferData { };

            SbIndices.Add(id);

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

            return id;
        }
 internal unsafe static void Init()
 {
     m_buffer = MyHwBuffers.CreateStructuredBuffer(4096, sizeof(MyPerMaterialData), true);
 }
Beispiel #21
0
 internal static void ResizeAndUpdateStaticStructuredBuffer(ref StructuredBufferId id, int capacity, int stride, IntPtr data, string debugName, DeviceContext context = null)
 {
     if (id == StructuredBufferId.NULL)
     {
         id = CreateStructuredBuffer(capacity, stride, false, data, debugName);
     }
     else 
     {
         Debug.Assert(stride == id.Stride);
         Debug.Assert(false == id.Dynamic);
         if (id.Capacity < capacity)
         {
             SBuffersData[id.Index].Buffer.Dispose();
             SBuffers.Data[id.Index].Description.SizeInBytes = stride * capacity;
             InitStructuredBuffer(id, data);
         }
         else
         {
             if (context == null)
                 context = MyRender11.DeviceContext;
             context.UpdateSubresource(new DataBox(data, stride * capacity, 0), id.Buffer);
         }
     }
 }
Beispiel #22
0
 internal static ShaderResourceView GetView(StructuredBufferId id)
 {
     return id != StructuredBufferId.NULL ? SBuffersData[id.Index].Srv : null;
 }
        internal unsafe static void Init()
        {
            m_cbCustomProjections = MyHwBuffers.CreateConstantsBuffer(sizeof(Matrix) * MAX_CUSTOM_PROJECTIONS_SIZE, "BilloardCustomProjections");

            m_vs = MyShaders.CreateVs("billboard.hlsl");
            m_vsDepthOnly = MyShaders.CreateVs("billboard_depth_only.hlsl"); 
            m_ps = MyShaders.CreatePs("billboard.hlsl");
            m_psDepthOnly = MyShaders.CreatePs("billboard_depth_only.hlsl"); 
            m_psOIT = MyShaders.CreatePs("billboard.hlsl", new[] { new ShaderMacro("OIT", null) });
            m_vsLit = MyShaders.CreateVs("billboard.hlsl", new[] { new ShaderMacro("LIT_PARTICLE", null) });
            m_psLit = MyShaders.CreatePs("billboard.hlsl", new[] { new ShaderMacro("LIT_PARTICLE", null) });
            m_psLitOIT = MyShaders.CreatePs("billboard.hlsl", new[] { new ShaderMacro("LIT_PARTICLE", null), new ShaderMacro("OIT", null) });

            m_psAlphaCutout = MyShaders.CreatePs("billboard.hlsl", new[] { new ShaderMacro("ALPHA_CUTOUT", null) });
            m_psAlphaCutoutAndLit = MyShaders.CreatePs("billboard.hlsl", 
                new[] { new ShaderMacro("ALPHA_CUTOUT", null), new ShaderMacro("LIT_PARTICLE", null) });
            m_psAlphaCutoutOIT = MyShaders.CreatePs("billboard.hlsl", 
                new[] { new ShaderMacro("ALPHA_CUTOUT", null), new ShaderMacro("OIT", null) });
            m_psAlphaCutoutAndLitOIT = MyShaders.CreatePs("billboard.hlsl", 
                new[] { new ShaderMacro("ALPHA_CUTOUT", null), new ShaderMacro("LIT_PARTICLE", null), new ShaderMacro("OIT", null) });

            m_inputLayout = MyShaders.CreateIL(m_vs.BytecodeId, MyVertexLayouts.GetLayout(MyVertexInputComponentType.POSITION3, MyVertexInputComponentType.TEXCOORD0_H));

            InitBillboardsIndexBuffer();

            m_VB = MyHwBuffers.CreateVertexBuffer(MAX_BILLBOARDS_SIZE * 4, sizeof(MyVertexFormatPositionTextureH), BindFlags.VertexBuffer, ResourceUsage.Dynamic, null, "MyBillboardRenderer");

            var stride = sizeof(MyBillboardData);
            m_SB = MyHwBuffers.CreateStructuredBuffer(MAX_BILLBOARDS_SIZE, stride, true, null, "MyBillboardRenderer");
            m_atlas = new MyTextureAtlas("Textures\\Particles\\", "Textures\\Particles\\ParticlesAtlas.tai");
        }
Beispiel #24
0
 internal unsafe static void Init()
 {
     m_buffer = MyHwBuffers.CreateStructuredBuffer(4096, sizeof(MyPerMaterialData), true, null, "MySceneMaterials");
 }
        internal unsafe void MoveToGPU()
        {
            var context = MyImmediateRC.RC.Context;

            if (m_tablesDirty)
            {
                var array = m_instancingTable.Data;

                fixed (void* ptr = array)
                {
                    var intPtr = new IntPtr(ptr);

                    if (m_indirectionBuffer != StructuredBufferId.NULL && m_indirectionBuffer.Capacity < array.Length)
                    {
                        MyHwBuffers.Destroy(m_indirectionBuffer);
                        m_indirectionBuffer = StructuredBufferId.NULL;
                        m_SRVs[0] = null;
                    }
                    if (m_indirectionBuffer == StructuredBufferId.NULL)
                    {
                        m_indirectionBuffer = MyHwBuffers.CreateStructuredBuffer(array.Length, sizeof(MyInstancingTableEntry), false, intPtr);
                        m_SRVs[0] = m_indirectionBuffer.Srv;
                    }
                    else
                    {
                        context.UpdateSubresource(new DataBox(intPtr, array.Length * sizeof(MyInstancingTableEntry), 0), m_indirectionBuffer.Buffer);
                    }
                }

                m_tablesDirty = false;
            }

            if (m_instancesDataDirty)
            {
                var array = m_perInstance.Data;

                fixed (void* ptr = array)
                {
                    var intPtr = new IntPtr(ptr);

                    if (m_instanceBuffer != StructuredBufferId.NULL && m_instanceBuffer.Capacity < array.Length)
                    {
                        MyHwBuffers.Destroy(m_instanceBuffer);
                        m_instanceBuffer = StructuredBufferId.NULL;
                        m_SRVs[1] = null;
                    }
                    if (m_instanceBuffer == StructuredBufferId.NULL)
                    {
                        m_instanceBuffer = MyHwBuffers.CreateStructuredBuffer(array.Length, sizeof(MyPerInstanceData), true, intPtr);
                        m_SRVs[1] = m_instanceBuffer.Srv;
                    }
                    else
                    {
                        var mapping = MyMapping.MapDiscard(context, m_instanceBuffer.Buffer);
                        mapping.stream.Write(intPtr, 0, array.Length * sizeof(MyPerInstanceData));
                        mapping.Unmap();
                    }
                }

                m_instancesDataDirty = false;
            }
        }
Beispiel #26
0
        internal unsafe void MoveToGPU()
        {
            var context = MyImmediateRC.RC.Context;

            if (m_tablesDirty)
            {
                var array = m_instancingTable.Data;

                fixed(void *ptr = array)
                {
                    var intPtr = new IntPtr(ptr);

                    if (m_indirectionBuffer != StructuredBufferId.NULL && m_indirectionBuffer.Capacity < array.Length)
                    {
                        MyHwBuffers.Destroy(m_indirectionBuffer);
                        m_indirectionBuffer = StructuredBufferId.NULL;
                        m_SRVs[0]           = null;
                    }
                    if (m_indirectionBuffer == StructuredBufferId.NULL)
                    {
                        m_indirectionBuffer = MyHwBuffers.CreateStructuredBuffer(array.Length, sizeof(MyInstancingTableEntry), false, intPtr);
                        m_SRVs[0]           = m_indirectionBuffer.Srv;
                    }
                    else
                    {
                        context.UpdateSubresource(new DataBox(intPtr, array.Length * sizeof(MyInstancingTableEntry), 0), m_indirectionBuffer.Buffer);
                    }
                }

                m_tablesDirty = false;
            }

            if (m_instancesDataDirty)
            {
                var array = m_perInstance.Data;

                fixed(void *ptr = array)
                {
                    var intPtr = new IntPtr(ptr);

                    if (m_instanceBuffer != StructuredBufferId.NULL && m_instanceBuffer.Capacity < array.Length)
                    {
                        MyHwBuffers.Destroy(m_instanceBuffer);
                        m_instanceBuffer = StructuredBufferId.NULL;
                        m_SRVs[1]        = null;
                    }
                    if (m_instanceBuffer == StructuredBufferId.NULL)
                    {
                        m_instanceBuffer = MyHwBuffers.CreateStructuredBuffer(array.Length, sizeof(MyPerInstanceData), true, intPtr);
                        m_SRVs[1]        = m_instanceBuffer.Srv;
                    }
                    else
                    {
                        var mapping = MyMapping.MapDiscard(context, m_instanceBuffer.Buffer);
                        mapping.stream.Write(intPtr, 0, array.Length * sizeof(MyPerInstanceData));
                        mapping.Unmap();
                    }
                }

                m_instancesDataDirty = false;
            }
        }
        internal unsafe static void Init()
        {
            m_vs = MyShaders.CreateVs("billboard.hlsl");
            m_ps = MyShaders.CreatePs("billboard.hlsl");
            m_vsLit = MyShaders.CreateVs("billboard.hlsl", new [] {new ShaderMacro("LIT_PARTICLE", null)});
            m_psLit = MyShaders.CreatePs("billboard.hlsl", new[] { new ShaderMacro("LIT_PARTICLE", null) });
            
            m_psAlphaCutout = MyShaders.CreatePs("billboard.hlsl", new[] { new ShaderMacro("ALPHA_CUTOUT", null) });
            m_psAlphaCutoutAndLit = MyShaders.CreatePs("billboard.hlsl", new[] { new ShaderMacro("ALPHA_CUTOUT", null), new ShaderMacro("LIT_PARTICLE", null) });

            m_inputLayout = MyShaders.CreateIL(m_vs.BytecodeId, MyVertexLayouts.GetLayout(MyVertexInputComponentType.POSITION3, MyVertexInputComponentType.TEXCOORD0_H));

            //MyCallbacks.RegisterDeviceResetListener(new OnDeviceResetDelegate(OnDeviceRestart));

            InitBillboardsIndexBuffer(MaxBillboards);

            m_VB = MyHwBuffers.CreateVertexBuffer(MaxBillboards * 4, sizeof(MyVertexFormatPositionTextureH), BindFlags.VertexBuffer, ResourceUsage.Dynamic, null, "MyBillboardRenderer");

            var stride = sizeof(MyBillboardData);
            m_SB = MyHwBuffers.CreateStructuredBuffer(MaxBillboards, stride, true, null, "MyBillboardRenderer");
            m_atlas = new MyTextureAtlas("Textures\\Particles\\", "Textures\\Particles\\ParticlesAtlas.tai");
        }
        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
        }
Beispiel #29
0
 internal static void Destroy(ref StructuredBufferId id)
 {
     if (id != StructuredBufferId.NULL)
     {
         Destroy(id); id = StructuredBufferId.NULL;
     }
 }
Beispiel #30
0
 internal static ShaderResourceView GetView(StructuredBufferId id)
 {
     return(id != StructuredBufferId.NULL ? SBuffersData[id.Index].Srv : null);
 }
        internal unsafe static void Init()
        {
            m_vs = MyShaders.CreateVs("billboard.hlsl", "vs");
            m_ps = MyShaders.CreatePs("billboard.hlsl", "ps");
            m_vsLit = MyShaders.CreateVs("billboard.hlsl", "vs", MyShaderHelpers.FormatMacros("LIT_PARTICLE"));
            m_psLit = MyShaders.CreatePs("billboard.hlsl", "ps", MyShaderHelpers.FormatMacros("LIT_PARTICLE"));
            m_inputLayout = MyShaders.CreateIL(m_vs.BytecodeId, MyVertexLayouts.GetLayout(MyVertexInputComponentType.POSITION3, MyVertexInputComponentType.TEXCOORD0_H));

            //MyCallbacks.RegisterDeviceResetListener(new OnDeviceResetDelegate(OnDeviceRestart));

            InitBillboardsIndexBuffer(MaxBillboards);

            m_VB = MyHwBuffers.CreateVertexBuffer(MaxBillboards * 4, sizeof(MyVertexFormatPositionTextureH), BindFlags.VertexBuffer, ResourceUsage.Dynamic);

            var stride = sizeof(MyBillboardData);
            m_SB = MyHwBuffers.CreateStructuredBuffer(MaxBillboards, stride, true);

            MyTextureAtlas.ParseAtlasDescription("Textures\\Particles\\", "Textures\\Particles\\ParticlesAtlas.tai", m_atlasedTextures);
        }
Beispiel #32
0
 internal static BufferDescription GetBufferDesc(StructuredBufferId id)
 {
     return(SBuffers.Data[id.Index].Description);
 }
Beispiel #33
0
 internal static void InitStructuredBuffer(StructuredBufferId id, IntPtr data)
 {
     SBuffersData[id.Index].Buffer = new Buffer(MyRender11.Device, data, SBuffers.Data[id.Index].Description);
     SBuffersData[id.Index].Srv = new ShaderResourceView(MyRender11.Device, SBuffersData[id.Index].Buffer);
     if (SBuffers.Data[id.Index].DebugName != null)
     {
         SBuffersData[id.Index].Buffer.DebugName = SBuffers.Data[id.Index].DebugName;
         SBuffersData[id.Index].Srv.DebugName = SBuffers.Data[id.Index].DebugName;
     }
 }
Beispiel #34
0
        internal unsafe void MoveToGPU()
        {
            if(m_dirty)
            {
                Release();

                fixed(void* ptr = m_vertexStream0)
                {
                    m_VB_positions = MyHwBuffers.CreateStructuredBuffer(m_vertices, Stride0, false, new IntPtr(ptr));
                }
                fixed (void* ptr = m_vertexStream1)
                {
                    m_VB_rest = MyHwBuffers.CreateStructuredBuffer(m_vertices, Stride1, false, new IntPtr(ptr));
                }
                fixed (void* ptr = m_indexStream)
                {
                    m_IB = MyHwBuffers.CreateStructuredBuffer(m_indices, IndexStride, false, new IntPtr(ptr));
                }

                m_dirty = false;
            }
        }
Beispiel #35
0
 internal static Buffer GetBuffer(StructuredBufferId id)
 {
     return SBuffersData[id.Index].Buffer;
 }
Beispiel #36
0
        internal void Release()
        {
            if (m_VB_positions != StructuredBufferId.NULL)
            {
                MyHwBuffers.Destroy(m_VB_positions);
                MyHwBuffers.Destroy(m_VB_rest);
                MyHwBuffers.Destroy(m_IB);
            }

            m_VB_positions = StructuredBufferId.NULL;
            m_VB_rest = StructuredBufferId.NULL;
            m_IB = StructuredBufferId.NULL;
        }
Beispiel #37
0
 internal static BufferDescription GetBufferDesc(StructuredBufferId id)
 {
     return SBuffers.Data[id.Index].Description;
 }
Beispiel #38
0
 internal static Buffer GetBuffer(StructuredBufferId id)
 {
     return(SBuffersData[id.Index].Buffer);
 }