private static void InitDevice() { m_particleBuffer = MyManagers.Buffers.CreateSrvUav( "MyGPUParticleRenderer::particleBuffer", MyGPUEmitters.MAX_PARTICLES, PARTICLE_STRIDE); m_deadListBuffer = MyManagers.Buffers.CreateUav( "MyGPUParticleRenderer::deadListBuffer", MyGPUEmitters.MAX_PARTICLES, sizeof(uint), uavType: MyUavType.Append); m_skippedParticleCountBuffer = MyManagers.Buffers.CreateSrvUav( "MyGPUParticleRenderer::skippedParticleCountBuffer", 1, sizeof(uint), uavType: MyUavType.Counter); // 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] = MyManagers.Buffers.CreateRead("MyGPUParticleRenderer::debugCounterBuffers[0]", 1, sizeof(uint)); m_debugCounterBuffers[1] = MyManagers.Buffers.CreateRead("MyGPUParticleRenderer::debugCounterBuffers[1]", 1, sizeof(uint)); m_activeListConstantBuffer = MyManagers.Buffers.CreateConstantBuffer("MyGPUParticleRenderer::activeListConstantBuffer", 4 * sizeof(uint)); m_emitterConstantBuffer = MyManagers.Buffers.CreateConstantBuffer("MyGPUParticleRenderer::emitterConstantBuffer", EMITTERCONSTANTBUFFER_SIZE, usage: ResourceUsage.Dynamic); m_emitterStructuredBuffer = MyManagers.Buffers.CreateSrv( "MyGPUParticleRenderer::emitterStructuredBuffer", MyGPUEmitters.MAX_LIVE_EMITTERS, EMITTERDATA_SIZE, usage: ResourceUsage.Dynamic); m_aliveIndexBuffer = MyManagers.Buffers.CreateSrvUav( "MyGPUParticleRenderer::aliveIndexBuffer", MyGPUEmitters.MAX_PARTICLES, sizeof(float), uavType: MyUavType.Counter); m_indirectDrawArgsBuffer = MyManagers.Buffers.CreateIndirectArgsBuffer("MyGPUParticleRenderer::indirectDrawArgsBuffer", 5, sizeof(uint)); 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 = MyManagers.Buffers.CreateIndexBuffer( "MyGPUParticleRenderer::indexBuffer", MyGPUEmitters.MAX_PARTICLES * 6, new IntPtr(ptr), MyIndexBufferFormat.UInt, ResourceUsage.Immutable); } } //MyRender11.BlendAlphaPremult }
private static void DoneDevice() { MyManagers.Buffers.Dispose(m_ib); m_ib = null; MyManagers.Buffers.Dispose(m_activeListConstantBuffer); m_activeListConstantBuffer = null; MyManagers.Buffers.Dispose(m_indirectDrawArgsBuffer); m_indirectDrawArgsBuffer = null; MyManagers.Buffers.Dispose(m_debugCounterBuffers); m_debugCounterBuffers = new IReadBuffer[m_debugCounterBuffers.Length]; MyManagers.Buffers.Dispose(m_aliveIndexBuffer); m_aliveIndexBuffer = null; MyManagers.Buffers.Dispose(m_deadListBuffer); m_deadListBuffer = null; MyManagers.Buffers.Dispose(m_skippedParticleCountBuffer); m_skippedParticleCountBuffer = null; MyManagers.Buffers.Dispose(m_particleBuffer); m_particleBuffer = null; MyManagers.Buffers.Dispose(m_emitterConstantBuffer); m_emitterConstantBuffer = null; MyManagers.Buffers.Dispose(m_emitterStructuredBuffer); m_emitterStructuredBuffer = null; }
internal static void Resize(int width, int height) { m_tilesX = (width + TILE_SIZE - 1) / TILE_SIZE; m_tilesY = (height + TILE_SIZE - 1) / TILE_SIZE; m_tilesNum = m_tilesX * m_tilesY; if (m_tileIndices != null) { MyManagers.Buffers.Dispose(m_tileIndices); } m_tileIndices = MyManagers.Buffers.CreateSrvUav("MyScreenDependants::tileIndices", m_tilesNum + m_tilesNum * MyRender11Constants.MAX_POINT_LIGHTS, sizeof(uint)); }
internal static void Resize(int width, int height, int samplesNum, int samplesQuality) { Width = width; Height = height; TilesX = (width + MyLightRendering.TILE_SIZE - 1) / MyLightRendering.TILE_SIZE; TilesY = ((height + MyLightRendering.TILE_SIZE - 1) / MyLightRendering.TILE_SIZE); TilesNum = TilesX * TilesY; if (TileIndices != null) MyManagers.Buffers.Dispose(TileIndices); TileIndices = MyManagers.Buffers.CreateSrvUav("MyScreenDependants::tileIndices", TilesNum + TilesNum * MyRender11Constants.MAX_POINT_LIGHTS, sizeof(uint)); }
internal static void Resize(int width, int height, int samplesNum, int samplesQuality) { Width = width; Height = height; TilesX = (width + MyLightRendering.TILE_SIZE - 1) / MyLightRendering.TILE_SIZE; TilesY = ((height + MyLightRendering.TILE_SIZE - 1) / MyLightRendering.TILE_SIZE); TilesNum = TilesX * TilesY; if (TileIndices != null) { MyManagers.Buffers.Dispose(TileIndices); } TileIndices = MyManagers.Buffers.CreateSrvUav("MyScreenDependants::tileIndices", TilesNum + TilesNum * MyRender11Constants.MAX_POINT_LIGHTS, sizeof(uint)); }
private static void InitDevice() { m_particleBuffer = MyManagers.Buffers.CreateSrvUav( "MyGPUParticleRenderer::particleBuffer", MyGPUEmitters.MAX_PARTICLES, PARTICLE_STRIDE); m_deadListBuffer = MyManagers.Buffers.CreateUav( "MyGPUParticleRenderer::deadListBuffer", MyGPUEmitters.MAX_PARTICLES, sizeof(uint), uavType: MyUavType.Append); m_skippedParticleCountBuffer = MyManagers.Buffers.CreateSrvUav( "MyGPUParticleRenderer::skippedParticleCountBuffer", 1, sizeof(uint), uavType: MyUavType.Counter); // 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] = MyManagers.Buffers.CreateRead("MyGPUParticleRenderer::debugCounterBuffers[0]", 1, sizeof(uint)); m_debugCounterBuffers[1] = MyManagers.Buffers.CreateRead("MyGPUParticleRenderer::debugCounterBuffers[1]", 1, sizeof(uint)); m_activeListConstantBuffer = MyManagers.Buffers.CreateConstantBuffer("MyGPUParticleRenderer::activeListConstantBuffer", 4 * sizeof(uint)); m_emitterConstantBuffer = MyManagers.Buffers.CreateConstantBuffer("MyGPUParticleRenderer::emitterConstantBuffer", EMITTERCONSTANTBUFFER_SIZE, usage: ResourceUsage.Dynamic); m_emitterStructuredBuffer = MyManagers.Buffers.CreateSrv( "MyGPUParticleRenderer::emitterStructuredBuffer", MyGPUEmitters.MAX_LIVE_EMITTERS, EMITTERDATA_SIZE, usage: ResourceUsage.Dynamic); m_aliveIndexBuffer = MyManagers.Buffers.CreateSrvUav( "MyGPUParticleRenderer::aliveIndexBuffer", MyGPUEmitters.MAX_PARTICLES, sizeof(float), uavType: MyUavType.Counter); m_indirectDrawArgsBuffer = MyManagers.Buffers.CreateIndirectArgsBuffer("MyGPUParticleRenderer::indirectDrawArgsBuffer", 5, sizeof(uint)); 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 = MyManagers.Buffers.CreateIndexBuffer( "MyGPUParticleRenderer::indexBuffer", MyGPUEmitters.MAX_PARTICLES * 6, new IntPtr(ptr), MyIndexBufferFormat.UInt, ResourceUsage.Immutable); } } //MyRender11.BlendAlphaPremult }