small optimizations for performance
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit

This commit is contained in:
austin 2024-12-12 00:31:47 -05:00
parent c96113133d
commit 4010b2beb7
2 changed files with 52 additions and 34 deletions

View File

@ -25,15 +25,33 @@ void fluid_grid2_addDensity(
){
int i;
int size=DIM*DIM*DIM;
__m256 minVec = _mm256_set1_ps(MIN_FLUID_VALUE);
__m256 maxVec = _mm256_set1_ps(MAX_FLUID_VALUE);
__m256 existing;
__m256 delta;
float * x = GET_ARR_RAW(d,CENTER_LOC);
float * s = GET_ARR_RAW(d0,CENTER_LOC);
for(i=0; i<size; i++){
x[i] += dt*s[i];
if(x[i] < MIN_FLUID_VALUE){
x[i] = MIN_FLUID_VALUE;
} else if(x[i] > MAX_FLUID_VALUE){
x[i] = MAX_FLUID_VALUE;
}
for(i=0; i<size; i=i+8){
existing = _mm256_loadu_ps(&x[i]);
delta = _mm256_loadu_ps(&s[i]);
_mm256_storeu_ps(&x[i],
_mm256_max_ps(
_mm256_min_ps(
_mm256_add_ps(
existing,
delta
),
maxVec
),
minVec
)
);
// x[i] += dt*s[i];
// if(x[i] < MIN_FLUID_VALUE){
// x[i] = MIN_FLUID_VALUE;
// } else if(x[i] > MAX_FLUID_VALUE){
// x[i] = MAX_FLUID_VALUE;
// }
}
}

View File

@ -91,17 +91,17 @@ LIBRARY_API void fluid_grid2_simulate(
//solve vector diffusion
fluid_grid2_solveVectorDiffuse(currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,currentChunk->w0,timestep);
}
// }
//time tracking
gettimeofday(&tv,NULL);
end = 1000000.0 * tv.tv_sec + tv.tv_usec;
perMilli = (end - start) / 1000.0f;
environment->state.timeTracking.velocityDiffuse = perMilli;
start = end;
// //time tracking
// gettimeofday(&tv,NULL);
// end = 1000000.0 * tv.tv_sec + tv.tv_usec;
// perMilli = (end - start) / 1000.0f;
// environment->state.timeTracking.velocityDiffuse = perMilli;
// start = end;
for(int i = 0; i < numChunks; i++){
Chunk * currentChunk = chunks[i];
// for(int i = 0; i < numChunks; i++){
// Chunk * currentChunk = chunks[i];
//setup projection
fluid_grid2_setupProjection(currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,timestep);
@ -116,31 +116,31 @@ LIBRARY_API void fluid_grid2_simulate(
fluid_grid2_flip_arrays(currentChunk->u,currentChunk->u0);
fluid_grid2_flip_arrays(currentChunk->v,currentChunk->v0);
fluid_grid2_flip_arrays(currentChunk->w,currentChunk->w0);
}
// }
//time tracking
gettimeofday(&tv,NULL);
end = 1000000.0 * tv.tv_sec + tv.tv_usec;
perMilli = (end - start) / 1000.0f;
environment->state.timeTracking.velocityProject = perMilli;
start = end;
// //time tracking
// gettimeofday(&tv,NULL);
// end = 1000000.0 * tv.tv_sec + tv.tv_usec;
// perMilli = (end - start) / 1000.0f;
// environment->state.timeTracking.velocityProject = perMilli;
// start = end;
for(int i = 0; i < numChunks; i++){
Chunk * currentChunk = chunks[i];
// for(int i = 0; i < numChunks; i++){
// Chunk * currentChunk = chunks[i];
//advect
fluid_grid2_advectVectors(currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,currentChunk->w0,timestep);
}
// }
//time tracking
gettimeofday(&tv,NULL);
end = 1000000.0 * tv.tv_sec + tv.tv_usec;
perMilli = (end - start) / 1000.0f;
environment->state.timeTracking.velocityAdvect = perMilli;
start = end;
// //time tracking
// gettimeofday(&tv,NULL);
// end = 1000000.0 * tv.tv_sec + tv.tv_usec;
// perMilli = (end - start) / 1000.0f;
// environment->state.timeTracking.velocityAdvect = perMilli;
// start = end;
for(int i = 0; i < numChunks; i++){
Chunk * currentChunk = chunks[i];
// for(int i = 0; i < numChunks; i++){
// Chunk * currentChunk = chunks[i];
//setup projection
fluid_grid2_setupProjection(currentChunk->u,currentChunk->v,currentChunk->w,currentChunk->u0,currentChunk->v0,timestep);
//Perform main projection solver