void InitializeSimulation() { if (SystemInfo.supportsComputeShaders) { m_cb_params = new ComputeBuffer(1, CSParams.size); m_cb_particles = new ComputeBuffer(m_particle_count, peParticle.size); m_cb_positions = new ComputeBuffer(m_particle_count, 12); m_cb_velocities = new ComputeBuffer(m_particle_count, 12); m_buf_positions = new Vector3[m_particle_count]; m_buf_velocities = new Vector3[m_particle_count]; m_csparams = new CSParams[1]; } { UnityEngine.Random.InitState(0); var tmp = new peParticle[m_particle_count]; for (int i = 0; i < tmp.Length; ++i) { tmp[i].position = new Vector3( UnityEngine.Random.Range(-5.0f, 5.0f), UnityEngine.Random.Range(-5.0f, 5.0f) + 5.0f, UnityEngine.Random.Range(-5.0f, 5.0f)); } m_cb_particles.SetData(tmp); } }
void InitializeSimulation() { if (SystemInfo.supportsComputeShaders) { m_cb_params = new ComputeBuffer(1, CSParams.size); m_cb_particles = new ComputeBuffer(m_particle_count, peParticle.size); m_cb_positions = new ComputeBuffer(m_particle_count, 12); m_cb_velocities = new ComputeBuffer(m_particle_count, 12); m_buf_positions = new Vector3[m_particle_count]; m_buf_velocities = new Vector3[m_particle_count]; m_csparams = new CSParams[1]; } { UnityEngine.Random.seed = 0; var tmp = new peParticle[m_particle_count]; for (int i = 0; i < tmp.Length; ++i) { tmp[i].position = new Vector3( UnityEngine.Random.Range(-5.0f, 5.0f), UnityEngine.Random.Range(-5.0f, 5.0f) + 5.0f, UnityEngine.Random.Range(-5.0f, 5.0f)); } m_cb_particles.SetData(tmp); } }
int RunGPUBenchmark(string text) { if (!SystemInfo.supportsComputeShaders) { m_output.text = m_output.text + text + "not available\n"; return(0); } ComputeBuffer cb_params = new ComputeBuffer(1, CSParams.size); ComputeBuffer cb_particles = new ComputeBuffer(BenchmarkParticleCount, peParticle.size); var particles = new peParticle[BenchmarkParticleCount]; { UnityEngine.Random.seed = 0; for (int i = 0; i < particles.Length; ++i) { particles[i].position = new Vector3( UnityEngine.Random.Range(-5.0f, 5.0f), UnityEngine.Random.Range(-5.0f, 5.0f) + 5.0f, UnityEngine.Random.Range(-5.0f, 5.0f)); } cb_particles.SetData(particles); } { CSParams[] csparams = new CSParams[1]; csparams[0].particle_count = BenchmarkParticleCount; csparams[0].particle_size = m_particle_size; csparams[0].rcp_particle_size2 = 1.0f / (m_particle_size * 2.0f); csparams[0].pressure_stiffness = m_pressure_stiffness; csparams[0].wall_stiffness = m_wall_stiffness; csparams[0].timestep = BenchmarkDeltaTime; cb_params.SetData(csparams); } for (int i = 0; i < 2; ++i) { m_cs_particle_core.SetBuffer(i, "g_params", cb_params); m_cs_particle_core.SetBuffer(i, "g_particles", cb_particles); } float elapsed_total = 0.0f; int num_try = 0; while (elapsed_total < BenchmarkTimeout) { float t = Time.realtimeSinceStartup; m_cs_particle_core.Dispatch(0, BenchmarkParticleCount / KernelBlockSize, 1, 1); m_cs_particle_core.Dispatch(1, BenchmarkParticleCount / KernelBlockSize, 1, 1); cb_particles.GetData(particles); elapsed_total += Time.realtimeSinceStartup - t; ++num_try; } cb_params.Release(); cb_particles.Release(); m_output.text = m_output.text + text + (elapsed_total / num_try * 1000.0f).ToString("0.00") + "ms\n"; return(0); }
public void ResetParticles() { peResetParticles(m_ctx); { UnityEngine.Random.seed = 0; var tmp = new peParticle[m_particle_count]; for (int i = 0; i < tmp.Length; ++i) { tmp[i].position = new Vector3( UnityEngine.Random.Range(-5.0f, 5.0f), UnityEngine.Random.Range(-5.0f, 5.0f) + 5.0f, UnityEngine.Random.Range(-5.0f, 5.0f)); } m_cb_particles.SetData(tmp); } }
int RunGPUBenchmark(string text) { if (!SystemInfo.supportsComputeShaders) { m_output.text = m_output.text + text + "not available\n"; return 0; } ComputeBuffer cb_params = new ComputeBuffer(1, CSParams.size); ComputeBuffer cb_particles = new ComputeBuffer(BenchmarkParticleCount, peParticle.size); var particles = new peParticle[BenchmarkParticleCount]; { UnityEngine.Random.seed = 0; for (int i = 0; i < particles.Length; ++i) { particles[i].position = new Vector3( UnityEngine.Random.Range(-5.0f, 5.0f), UnityEngine.Random.Range(-5.0f, 5.0f) + 5.0f, UnityEngine.Random.Range(-5.0f, 5.0f) ); } cb_particles.SetData(particles); } { CSParams[] csparams = new CSParams[1]; csparams[0].particle_count = BenchmarkParticleCount; csparams[0].particle_size = m_particle_size; csparams[0].rcp_particle_size2 = 1.0f / (m_particle_size * 2.0f); csparams[0].pressure_stiffness = m_pressure_stiffness; csparams[0].wall_stiffness = m_wall_stiffness; csparams[0].timestep = BenchmarkDeltaTime; cb_params.SetData(csparams); } for (int i = 0; i < 2; ++i ) { m_cs_particle_core.SetBuffer(i, "g_params", cb_params); m_cs_particle_core.SetBuffer(i, "g_particles", cb_particles); } float elapsed_total = 0.0f; int num_try = 0; while (elapsed_total < BenchmarkTimeout) { float t = Time.realtimeSinceStartup; m_cs_particle_core.Dispatch(0, BenchmarkParticleCount / KernelBlockSize, 1, 1); m_cs_particle_core.Dispatch(1, BenchmarkParticleCount / KernelBlockSize, 1, 1); cb_particles.GetData(particles); elapsed_total += Time.realtimeSinceStartup - t; ++num_try; } cb_params.Release(); cb_particles.Release(); m_output.text = m_output.text + text + (elapsed_total / num_try * 1000.0f).ToString("0.00") + "ms\n"; return 0; }