From 798dd30e9ff7e2cd00a5510c898d11807a5c892d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Mon, 22 Dec 2014 20:14:48 -0800 Subject: [PATCH] Cleanup. --- examples/24-nbody/cs_init_instances.sc | 4 +- examples/24-nbody/cs_update_instances.sc | 22 +-- examples/24-nbody/nbody.cpp | 143 +++++++++--------- .../shaders/gles/cs_init_instances.bin | Bin 3350 -> 3353 bytes .../shaders/gles/cs_update_instances.bin | Bin 2687 -> 2701 bytes .../shaders/glsl/cs_init_instances.bin | Bin 3347 -> 3350 bytes .../shaders/glsl/cs_update_instances.bin | Bin 2684 -> 2698 bytes 7 files changed, 84 insertions(+), 85 deletions(-) diff --git a/examples/24-nbody/cs_init_instances.sc b/examples/24-nbody/cs_init_instances.sc index 495cdd60..34909a9e 100644 --- a/examples/24-nbody/cs_init_instances.sc +++ b/examples/24-nbody/cs_init_instances.sc @@ -7,7 +7,7 @@ #include "uniforms.sh" BUFFER_WR(prevPositionBuffer, vec4, 0); -BUFFER_WR(curPositionBuffer, vec4, 1); +BUFFER_WR(currPositionBuffer, vec4, 1); uint rotl(uint _x, uint _r) { @@ -101,5 +101,5 @@ void main() vec3 velocity = u_initialSpeed * randomPointOnSphere(gl_GlobalInvocationID.x, u_baseSeed * 7u + 3u); prevPositionBuffer[gl_GlobalInvocationID.x] = vec4(position - velocity * u_timeStep, 0.0); - curPositionBuffer[ gl_GlobalInvocationID.x] = vec4(position, 0.0); + currPositionBuffer[gl_GlobalInvocationID.x] = vec4(position, 0.0); } diff --git a/examples/24-nbody/cs_update_instances.sc b/examples/24-nbody/cs_update_instances.sc index 2d7c1642..b818f97c 100644 --- a/examples/24-nbody/cs_update_instances.sc +++ b/examples/24-nbody/cs_update_instances.sc @@ -7,16 +7,16 @@ #include "uniforms.sh" BUFFER_RO(prevPositionBuffer, vec4, 0); -BUFFER_RO(curPositionBuffer, vec4, 1); +BUFFER_RO(currPositionBuffer, vec4, 1); BUFFER_WR(outPrevPositionBuffer, vec4, 2); -BUFFER_WR(outCurPositionBuffer, vec4, 3); +BUFFER_WR(outCurrPositionBuffer, vec4, 3); #define GROUP_SIZE 512 SHARED vec3 otherEntries[GROUP_SIZE]; -vec3 calcAcceleration(vec3 _curPosition, vec3 _otherPosition) +vec3 calcAcceleration(vec3 _currPosition, vec3 _otherPosition) { - vec3 difference = _otherPosition - _curPosition; + vec3 difference = _otherPosition - _currPosition; float dist2 = dot(difference, difference); float dist6 = dist2 * dist2 * dist2; float invDist3 = 1.0 / (sqrt(dist6) + 0.1); @@ -27,22 +27,22 @@ NUM_THREADS(GROUP_SIZE, 1, 1) void main() { vec3 prevPosition = prevPositionBuffer[gl_GlobalInvocationID.x].xyz; - vec3 curPosition = curPositionBuffer[ gl_GlobalInvocationID.x].xyz; + vec3 currPosition = currPositionBuffer[gl_GlobalInvocationID.x].xyz; vec3 newAcceleration = vec3_splat(0.0); for (int j = 0; j < int(u_dispatchSize); ++j) { - otherEntries[gl_LocalInvocationIndex] = curPositionBuffer[j * GROUP_SIZE + int(gl_LocalInvocationIndex)].xyz; + otherEntries[gl_LocalInvocationIndex] = currPositionBuffer[j * GROUP_SIZE + int(gl_LocalInvocationIndex)].xyz; barrier(); for (int i = 0; i < GROUP_SIZE; ++i) { - newAcceleration += calcAcceleration(curPosition, otherEntries[i]); + newAcceleration += calcAcceleration(currPosition, otherEntries[i]); } } - newAcceleration += (prevPosition - curPosition) * u_damping; + newAcceleration += (prevPosition - currPosition) * u_damping; float accelerationMagnitude = length(newAcceleration); float color = pow(min(accelerationMagnitude / 3.0, 1.0), 0.25); if (accelerationMagnitude > 0.0) @@ -50,8 +50,8 @@ void main() newAcceleration = normalize(newAcceleration) * min(accelerationMagnitude, u_maxAcceleration); } - vec3 newPosition = 2.0 * curPosition - prevPosition + newAcceleration * u_timeStep; + vec3 newPosition = 2.0 * currPosition - prevPosition + newAcceleration * u_timeStep; - outPrevPositionBuffer[gl_GlobalInvocationID.x] = vec4(curPosition, 0.0); - outCurPositionBuffer[ gl_GlobalInvocationID.x] = vec4(newPosition, color); + outPrevPositionBuffer[gl_GlobalInvocationID.x] = vec4(currPosition, 0.0); + outCurrPositionBuffer[gl_GlobalInvocationID.x] = vec4(newPosition, color); } diff --git a/examples/24-nbody/nbody.cpp b/examples/24-nbody/nbody.cpp index 1881b866..688bb5b2 100644 --- a/examples/24-nbody/nbody.cpp +++ b/examples/24-nbody/nbody.cpp @@ -1,7 +1,7 @@ /* - * Copyright 2014 Stanlo Slasinski. All rights reserved. - * License: http://www.opensource.org/licenses/BSD-2-Clause - */ +* Copyright 2014 Stanlo Slasinski. All rights reserved. +* License: http://www.opensource.org/licenses/BSD-2-Clause +*/ #include "common.h" #include "bgfx_utils.h" @@ -22,69 +22,68 @@ struct u_paramsDataStruct float initialSpeed; int32_t initialShape; float maxAccel; - }; -void InitializeParams(unsigned mode, u_paramsDataStruct * params) +void InitializeParams(unsigned _mode, u_paramsDataStruct* _params) { - switch(mode) - { - case 0: - params->timeStep = 0.0067f; - params->dispatchSize = 32; - params->gravity = 0.069f; - params->damping = 0.0f; - params->particleIntensity = 0.35f; - params->particleSize = 0.925f; - params->baseSeed = 0; - params->particlePower = 5.0f; - params->initialSpeed = 122.6f; - params->initialShape = 0; - params->maxAccel = 30.0; - break; + switch(_mode) + { + case 0: + _params->timeStep = 0.0067f; + _params->dispatchSize = 32; + _params->gravity = 0.069f; + _params->damping = 0.0f; + _params->particleIntensity = 0.35f; + _params->particleSize = 0.925f; + _params->baseSeed = 0; + _params->particlePower = 5.0f; + _params->initialSpeed = 122.6f; + _params->initialShape = 0; + _params->maxAccel = 30.0; + break; - case 1: - params->timeStep = 0.0157f; - params->dispatchSize = 32; - params->gravity = 0.109f; - params->damping = 0.25f; - params->particleIntensity = 0.64f; - params->particleSize = 0.279f; - params->baseSeed = 57; - params->particlePower = 3.5f; - params->initialSpeed = 3.2f; - params->initialShape = 1; - params->maxAccel = 100.0; - break; + case 1: + _params->timeStep = 0.0157f; + _params->dispatchSize = 32; + _params->gravity = 0.109f; + _params->damping = 0.25f; + _params->particleIntensity = 0.64f; + _params->particleSize = 0.279f; + _params->baseSeed = 57; + _params->particlePower = 3.5f; + _params->initialSpeed = 3.2f; + _params->initialShape = 1; + _params->maxAccel = 100.0; + break; - case 2: - params->timeStep = 0.02f; - params->dispatchSize = 32; - params->gravity = 0.24f; - params->damping = 0.12f; - params->particleIntensity = 1.0f; - params->particleSize = 1.0f; - params->baseSeed = 23; - params->particlePower = 4.0f; - params->initialSpeed = 31.1f; - params->initialShape = 2; - params->maxAccel = 39.29f; - break; + case 2: + _params->timeStep = 0.02f; + _params->dispatchSize = 32; + _params->gravity = 0.24f; + _params->damping = 0.12f; + _params->particleIntensity = 1.0f; + _params->particleSize = 1.0f; + _params->baseSeed = 23; + _params->particlePower = 4.0f; + _params->initialSpeed = 31.1f; + _params->initialShape = 2; + _params->maxAccel = 39.29f; + break; - case 3: - params->timeStep = 0.0118f; - params->dispatchSize = 32; - params->gravity = 0.141f; - params->damping = 1.0f; - params->particleIntensity = 0.64f; - params->particleSize = 0.28f; - params->baseSeed = 60; - params->particlePower = 1.97f; - params->initialSpeed = 69.7f; - params->initialShape = 3; - params->maxAccel = 3.21f; - break; - } + case 3: + _params->timeStep = 0.0118f; + _params->dispatchSize = 32; + _params->gravity = 0.141f; + _params->damping = 1.0f; + _params->particleIntensity = 0.64f; + _params->particleSize = 0.28f; + _params->baseSeed = 60; + _params->particlePower = 1.97f; + _params->initialSpeed = 69.7f; + _params->initialShape = 3; + _params->maxAccel = 3.21f; + break; + } } static const float s_quadVertices[] = @@ -129,8 +128,8 @@ int _main_(int /*_argc*/, char** /*_argv*/) // Create static vertex buffer. bgfx::VertexBufferHandle vbh = bgfx::createVertexBuffer( - // Static data can be passed with bgfx::makeRef - bgfx::makeRef(s_quadVertices, sizeof(s_quadVertices) ) + // Static data can be passed with bgfx::makeRef + bgfx::makeRef(s_quadVertices, sizeof(s_quadVertices) ) , quadVertexDecl ); @@ -150,7 +149,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) .end(); const uint32_t threadGroupUpdateSize = 512; - const uint32_t maxParticleCount = 32 * 1024; + const uint32_t maxParticleCount = 32 * 1024; bgfx::DynamicVertexBufferHandle currPositionBuffer0 = bgfx::createDynamicVertexBuffer(1 << 15, computeVertexDecl, BGFX_BUFFER_COMPUTE_READ_WRITE); bgfx::DynamicVertexBufferHandle currPositionBuffer1 = bgfx::createDynamicVertexBuffer(1 << 15, computeVertexDecl, BGFX_BUFFER_COMPUTE_READ_WRITE); @@ -164,8 +163,8 @@ int _main_(int /*_argc*/, char** /*_argv*/) bgfx::ShaderHandle updateInstancesShader = loadShader("cs_update_instances"); bgfx::ProgramHandle updateInstancesProgram = bgfx::createProgram(updateInstancesShader, true); - u_paramsDataStruct u_paramsData; - InitializeParams(0, &u_paramsData); + u_paramsDataStruct u_paramsData; + InitializeParams(0, &u_paramsData); bgfx::setUniform(u_params, &u_paramsData, 3); bgfx::setBuffer(0, prevPositionBuffer0, bgfx::Access::Write); @@ -225,18 +224,18 @@ int _main_(int /*_argc*/, char** /*_argv*/) imguiEndScrollArea(); imguiEndFrame(); - // Modify parameters and reset if shape is changed - if (shape != u_paramsData.initialShape) - { - reset = true; - InitializeParams(shape, &u_paramsData); - } + // Modify parameters and reset if shape is changed + if (shape != u_paramsData.initialShape) + { + reset = true; + InitializeParams(shape, &u_paramsData); + } if (reset) { bgfx::setBuffer(0, prevPositionBuffer0, bgfx::Access::Write); bgfx::setBuffer(1, currPositionBuffer0, bgfx::Access::Write); - bgfx::setUniform(u_params, &u_paramsData, 3); + bgfx::setUniform(u_params, &u_paramsData, 3); bgfx::dispatch(0, initInstancesProgram, maxParticleCount / threadGroupUpdateSize, 1, 1); } diff --git a/examples/runtime/shaders/gles/cs_init_instances.bin b/examples/runtime/shaders/gles/cs_init_instances.bin index 92cc0d8e8b79a6ee6bcc3c72c974e316c03f6ae9..a65f651e35ceb41ee1f4848d1863e84f4717bbcb 100644 GIT binary patch delta 58 zcmbOxHB*Y)IoN}d0Sve{a&KZ5DhkLi&Me8y&vPnGOG_Qtua@ diff --git a/examples/runtime/shaders/gles/cs_update_instances.bin b/examples/runtime/shaders/gles/cs_update_instances.bin index 24bfbcee057b8d4ae1aea91a936f5047a6842b00..c8ecec1ed96a6bca228ddf314dd07bd59869bf1d 100644 GIT binary patch delta 146 zcmew_(ksgC9PGi!00wm%xi>Hi6$RuMXO?8<=Q)+8rKJ`nmljPv$RfiGqF*u}6-ATI zFD-Eft5BN!h$UpQDXZt^TGlj10k|>+TLqxjqRH<$)hA1`PoBJ*y??SLhx_Jw4n4-n UYdA|MD{zT3f~55)r*laF0C}V``Tzg` delta 153 zcmeAb{V&4p9PGi!00spcxi>Hi1mqWImSpDVIhCfRr4}WZPCm;lKlv^5k;$7_L?)kO zmS)W_EpaZL{DLK9vMsB}<~G(;Mmd-s1zUyW(jpiSVnVdSWG?pAlee+=O?KsQ+uXyU a%Q$%#XUSxJE-^H_fGWAU6egE)NdN$$Vl-#~ diff --git a/examples/runtime/shaders/glsl/cs_init_instances.bin b/examples/runtime/shaders/glsl/cs_init_instances.bin index b8ea84ad39213250e84b4b5bdb2a84878d08933e..e1308e1fb07fce7384ca6fc83cc8b4a79db4db09 100644 GIT binary patch delta 66 zcmbO%HBE}!IoN}d0SwqTa<69=DhkLi&Me8y&vPnGOG_W;Srq7&C3k{P9PU_ diff --git a/examples/runtime/shaders/glsl/cs_update_instances.bin b/examples/runtime/shaders/glsl/cs_update_instances.bin index c0ddfe52c7c6b0571b35857afbddc2814cfe6fb7..1ebe5635e9c7595e226f1d6d38ef3da90401b2c5 100644 GIT binary patch delta 150 zcmew((k0669PGi!00z|?xz{oa6$RuMXO?8<=Q)+8rKJ`nmljRl$0EZFqVKbaP5#5Y zUKCA9erbs_Sd|h`MaX0$R?p2#sl g87FV&EK!50(orzbGtji=0vnI1mxD`TauJsV09*7xWB>pF