Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/ocean.c
| Show First 20 Lines • Show All 447 Lines • ▼ Show 20 Lines | for (j = 0; j <= o->_N / 2; j++) { | ||||
| mul_complex_c(exp_param1, o->_h0[i * o->_N + j], exp_param1); | mul_complex_c(exp_param1, o->_h0[i * o->_N + j], exp_param1); | ||||
| mul_complex_c(exp_param2, conj_param, exp_param2); | mul_complex_c(exp_param2, conj_param, exp_param2); | ||||
| add_comlex_c(o->_htilda[i * (1 + o->_N / 2) + j], exp_param1, exp_param2); | add_comlex_c(o->_htilda[i * (1 + o->_N / 2) + j], exp_param1, exp_param2); | ||||
| mul_complex_f(o->_fft_in[i * (1 + o->_N / 2) + j], o->_htilda[i * (1 + o->_N / 2) + j], scale); | mul_complex_f(o->_fft_in[i * (1 + o->_N / 2) + j], o->_htilda[i * (1 + o->_N / 2) + j], scale); | ||||
| } | } | ||||
| } | } | ||||
| static void ocean_compute_displacement_y(TaskPool *__restrict pool, | static void ocean_compute_displacement_y(TaskPool *__restrict pool, void *UNUSED(taskdata)) | ||||
| void *UNUSED(taskdata), | |||||
| int UNUSED(threadid)) | |||||
| { | { | ||||
| OceanSimulateData *osd = BLI_task_pool_userdata(pool); | OceanSimulateData *osd = BLI_task_pool_tbb_user_data(pool); | ||||
| const Ocean *o = osd->o; | const Ocean *o = osd->o; | ||||
| fftw_execute(o->_disp_y_plan); | fftw_execute(o->_disp_y_plan); | ||||
| } | } | ||||
| static void ocean_compute_displacement_x(TaskPool *__restrict pool, | static void ocean_compute_displacement_x(TaskPool *__restrict pool, void *UNUSED(taskdata)) | ||||
| void *UNUSED(taskdata), | |||||
| int UNUSED(threadid)) | |||||
| { | { | ||||
| OceanSimulateData *osd = BLI_task_pool_userdata(pool); | OceanSimulateData *osd = BLI_task_pool_tbb_user_data(pool); | ||||
| const Ocean *o = osd->o; | const Ocean *o = osd->o; | ||||
| const float scale = osd->scale; | const float scale = osd->scale; | ||||
| const float chop_amount = osd->chop_amount; | const float chop_amount = osd->chop_amount; | ||||
| int i, j; | int i, j; | ||||
| for (i = 0; i < o->_M; i++) { | for (i = 0; i < o->_M; i++) { | ||||
| for (j = 0; j <= o->_N / 2; j++) { | for (j = 0; j <= o->_N / 2; j++) { | ||||
| fftw_complex mul_param; | fftw_complex mul_param; | ||||
| Show All 10 Lines | for (j = 0; j <= o->_N / 2; j++) { | ||||
| 0.0f : | 0.0f : | ||||
| o->_kx[i] / o->_k[i * (1 + o->_N / 2) + j])); | o->_kx[i] / o->_k[i * (1 + o->_N / 2) + j])); | ||||
| init_complex(o->_fft_in_x[i * (1 + o->_N / 2) + j], real_c(mul_param), image_c(mul_param)); | init_complex(o->_fft_in_x[i * (1 + o->_N / 2) + j], real_c(mul_param), image_c(mul_param)); | ||||
| } | } | ||||
| } | } | ||||
| fftw_execute(o->_disp_x_plan); | fftw_execute(o->_disp_x_plan); | ||||
| } | } | ||||
| static void ocean_compute_displacement_z(TaskPool *__restrict pool, | static void ocean_compute_displacement_z(TaskPool *__restrict pool, void *UNUSED(taskdata)) | ||||
| void *UNUSED(taskdata), | |||||
| int UNUSED(threadid)) | |||||
| { | { | ||||
| OceanSimulateData *osd = BLI_task_pool_userdata(pool); | OceanSimulateData *osd = BLI_task_pool_tbb_user_data(pool); | ||||
| const Ocean *o = osd->o; | const Ocean *o = osd->o; | ||||
| const float scale = osd->scale; | const float scale = osd->scale; | ||||
| const float chop_amount = osd->chop_amount; | const float chop_amount = osd->chop_amount; | ||||
| int i, j; | int i, j; | ||||
| for (i = 0; i < o->_M; i++) { | for (i = 0; i < o->_M; i++) { | ||||
| for (j = 0; j <= o->_N / 2; j++) { | for (j = 0; j <= o->_N / 2; j++) { | ||||
| fftw_complex mul_param; | fftw_complex mul_param; | ||||
| Show All 10 Lines | for (j = 0; j <= o->_N / 2; j++) { | ||||
| 0.0f : | 0.0f : | ||||
| o->_kz[j] / o->_k[i * (1 + o->_N / 2) + j])); | o->_kz[j] / o->_k[i * (1 + o->_N / 2) + j])); | ||||
| init_complex(o->_fft_in_z[i * (1 + o->_N / 2) + j], real_c(mul_param), image_c(mul_param)); | init_complex(o->_fft_in_z[i * (1 + o->_N / 2) + j], real_c(mul_param), image_c(mul_param)); | ||||
| } | } | ||||
| } | } | ||||
| fftw_execute(o->_disp_z_plan); | fftw_execute(o->_disp_z_plan); | ||||
| } | } | ||||
| static void ocean_compute_jacobian_jxx(TaskPool *__restrict pool, | static void ocean_compute_jacobian_jxx(TaskPool *__restrict pool, void *UNUSED(taskdata)) | ||||
| void *UNUSED(taskdata), | |||||
| int UNUSED(threadid)) | |||||
| { | { | ||||
| OceanSimulateData *osd = BLI_task_pool_userdata(pool); | OceanSimulateData *osd = BLI_task_pool_tbb_user_data(pool); | ||||
| const Ocean *o = osd->o; | const Ocean *o = osd->o; | ||||
| const float chop_amount = osd->chop_amount; | const float chop_amount = osd->chop_amount; | ||||
| int i, j; | int i, j; | ||||
| for (i = 0; i < o->_M; i++) { | for (i = 0; i < o->_M; i++) { | ||||
| for (j = 0; j <= o->_N / 2; j++) { | for (j = 0; j <= o->_N / 2; j++) { | ||||
| fftw_complex mul_param; | fftw_complex mul_param; | ||||
| Show All 14 Lines | static void ocean_compute_jacobian_jxx(TaskPool *__restrict pool, void *UNUSED(taskdata)) | ||||
| for (i = 0; i < o->_M; i++) { | for (i = 0; i < o->_M; i++) { | ||||
| for (j = 0; j < o->_N; j++) { | for (j = 0; j < o->_N; j++) { | ||||
| o->_Jxx[i * o->_N + j] += 1.0; | o->_Jxx[i * o->_N + j] += 1.0; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void ocean_compute_jacobian_jzz(TaskPool *__restrict pool, | static void ocean_compute_jacobian_jzz(TaskPool *__restrict pool, void *UNUSED(taskdata)) | ||||
| void *UNUSED(taskdata), | |||||
| int UNUSED(threadid)) | |||||
| { | { | ||||
| OceanSimulateData *osd = BLI_task_pool_userdata(pool); | OceanSimulateData *osd = BLI_task_pool_tbb_user_data(pool); | ||||
| const Ocean *o = osd->o; | const Ocean *o = osd->o; | ||||
| const float chop_amount = osd->chop_amount; | const float chop_amount = osd->chop_amount; | ||||
| int i, j; | int i, j; | ||||
| for (i = 0; i < o->_M; i++) { | for (i = 0; i < o->_M; i++) { | ||||
| for (j = 0; j <= o->_N / 2; j++) { | for (j = 0; j <= o->_N / 2; j++) { | ||||
| fftw_complex mul_param; | fftw_complex mul_param; | ||||
| Show All 14 Lines | static void ocean_compute_jacobian_jzz(TaskPool *__restrict pool, void *UNUSED(taskdata)) | ||||
| for (i = 0; i < o->_M; i++) { | for (i = 0; i < o->_M; i++) { | ||||
| for (j = 0; j < o->_N; j++) { | for (j = 0; j < o->_N; j++) { | ||||
| o->_Jzz[i * o->_N + j] += 1.0; | o->_Jzz[i * o->_N + j] += 1.0; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void ocean_compute_jacobian_jxz(TaskPool *__restrict pool, | static void ocean_compute_jacobian_jxz(TaskPool *__restrict pool, void *UNUSED(taskdata)) | ||||
| void *UNUSED(taskdata), | |||||
| int UNUSED(threadid)) | |||||
| { | { | ||||
| OceanSimulateData *osd = BLI_task_pool_userdata(pool); | OceanSimulateData *osd = BLI_task_pool_tbb_user_data(pool); | ||||
| const Ocean *o = osd->o; | const Ocean *o = osd->o; | ||||
| const float chop_amount = osd->chop_amount; | const float chop_amount = osd->chop_amount; | ||||
| int i, j; | int i, j; | ||||
| for (i = 0; i < o->_M; i++) { | for (i = 0; i < o->_M; i++) { | ||||
| for (j = 0; j <= o->_N / 2; j++) { | for (j = 0; j <= o->_N / 2; j++) { | ||||
| fftw_complex mul_param; | fftw_complex mul_param; | ||||
| /* init_complex(mul_param, -scale, 0); */ | /* init_complex(mul_param, -scale, 0); */ | ||||
| init_complex(mul_param, -1, 0); | init_complex(mul_param, -1, 0); | ||||
| mul_complex_f(mul_param, mul_param, chop_amount); | mul_complex_f(mul_param, mul_param, chop_amount); | ||||
| mul_complex_c(mul_param, mul_param, o->_htilda[i * (1 + o->_N / 2) + j]); | mul_complex_c(mul_param, mul_param, o->_htilda[i * (1 + o->_N / 2) + j]); | ||||
| mul_complex_f(mul_param, | mul_complex_f(mul_param, | ||||
| mul_param, | mul_param, | ||||
| ((o->_k[i * (1 + o->_N / 2) + j] == 0.0f) ? | ((o->_k[i * (1 + o->_N / 2) + j] == 0.0f) ? | ||||
| 0.0f : | 0.0f : | ||||
| o->_kx[i] * o->_kz[j] / o->_k[i * (1 + o->_N / 2) + j])); | o->_kx[i] * o->_kz[j] / o->_k[i * (1 + o->_N / 2) + j])); | ||||
| init_complex(o->_fft_in_jxz[i * (1 + o->_N / 2) + j], real_c(mul_param), image_c(mul_param)); | init_complex(o->_fft_in_jxz[i * (1 + o->_N / 2) + j], real_c(mul_param), image_c(mul_param)); | ||||
| } | } | ||||
| } | } | ||||
| fftw_execute(o->_Jxz_plan); | fftw_execute(o->_Jxz_plan); | ||||
| } | } | ||||
| static void ocean_compute_normal_x(TaskPool *__restrict pool, | static void ocean_compute_normal_x(TaskPool *__restrict pool, void *UNUSED(taskdata)) | ||||
| void *UNUSED(taskdata), | |||||
| int UNUSED(threadid)) | |||||
| { | { | ||||
| OceanSimulateData *osd = BLI_task_pool_userdata(pool); | OceanSimulateData *osd = BLI_task_pool_tbb_user_data(pool); | ||||
| const Ocean *o = osd->o; | const Ocean *o = osd->o; | ||||
| int i, j; | int i, j; | ||||
| for (i = 0; i < o->_M; i++) { | for (i = 0; i < o->_M; i++) { | ||||
| for (j = 0; j <= o->_N / 2; j++) { | for (j = 0; j <= o->_N / 2; j++) { | ||||
| fftw_complex mul_param; | fftw_complex mul_param; | ||||
| init_complex(mul_param, 0.0, -1.0); | init_complex(mul_param, 0.0, -1.0); | ||||
| mul_complex_c(mul_param, mul_param, o->_htilda[i * (1 + o->_N / 2) + j]); | mul_complex_c(mul_param, mul_param, o->_htilda[i * (1 + o->_N / 2) + j]); | ||||
| mul_complex_f(mul_param, mul_param, o->_kx[i]); | mul_complex_f(mul_param, mul_param, o->_kx[i]); | ||||
| init_complex(o->_fft_in_nx[i * (1 + o->_N / 2) + j], real_c(mul_param), image_c(mul_param)); | init_complex(o->_fft_in_nx[i * (1 + o->_N / 2) + j], real_c(mul_param), image_c(mul_param)); | ||||
| } | } | ||||
| } | } | ||||
| fftw_execute(o->_N_x_plan); | fftw_execute(o->_N_x_plan); | ||||
| } | } | ||||
| static void ocean_compute_normal_z(TaskPool *__restrict pool, | static void ocean_compute_normal_z(TaskPool *__restrict pool, void *UNUSED(taskdata)) | ||||
| void *UNUSED(taskdata), | |||||
| int UNUSED(threadid)) | |||||
| { | { | ||||
| OceanSimulateData *osd = BLI_task_pool_userdata(pool); | OceanSimulateData *osd = BLI_task_pool_tbb_user_data(pool); | ||||
| const Ocean *o = osd->o; | const Ocean *o = osd->o; | ||||
| int i, j; | int i, j; | ||||
| for (i = 0; i < o->_M; i++) { | for (i = 0; i < o->_M; i++) { | ||||
| for (j = 0; j <= o->_N / 2; j++) { | for (j = 0; j <= o->_N / 2; j++) { | ||||
| fftw_complex mul_param; | fftw_complex mul_param; | ||||
| init_complex(mul_param, 0.0, -1.0); | init_complex(mul_param, 0.0, -1.0); | ||||
| mul_complex_c(mul_param, mul_param, o->_htilda[i * (1 + o->_N / 2) + j]); | mul_complex_c(mul_param, mul_param, o->_htilda[i * (1 + o->_N / 2) + j]); | ||||
| mul_complex_f(mul_param, mul_param, o->_kz[i]); | mul_complex_f(mul_param, mul_param, o->_kz[i]); | ||||
| init_complex(o->_fft_in_nz[i * (1 + o->_N / 2) + j], real_c(mul_param), image_c(mul_param)); | init_complex(o->_fft_in_nz[i * (1 + o->_N / 2) + j], real_c(mul_param), image_c(mul_param)); | ||||
| } | } | ||||
| } | } | ||||
| fftw_execute(o->_N_z_plan); | fftw_execute(o->_N_z_plan); | ||||
| } | } | ||||
| void BKE_ocean_simulate(struct Ocean *o, float t, float scale, float chop_amount) | void BKE_ocean_simulate(struct Ocean *o, float t, float scale, float chop_amount) | ||||
| { | { | ||||
| TaskScheduler *scheduler = BLI_task_scheduler_get(); | TaskScheduler *scheduler = BLI_task_scheduler_legacy_get(); | ||||
| TaskPool *pool; | TaskPool *pool; | ||||
| OceanSimulateData osd; | OceanSimulateData osd; | ||||
| scale *= o->normalize_factor; | scale *= o->normalize_factor; | ||||
| osd.o = o; | osd.o = o; | ||||
| osd.t = t; | osd.t = t; | ||||
| osd.scale = scale; | osd.scale = scale; | ||||
| osd.chop_amount = chop_amount; | osd.chop_amount = chop_amount; | ||||
| pool = BLI_task_pool_create(scheduler, &osd, TASK_PRIORITY_HIGH); | pool = BLI_task_pool_tbb_create(scheduler, &osd, TASK_PRIORITY_HIGH); | ||||
| BLI_rw_mutex_lock(&o->oceanmutex, THREAD_LOCK_WRITE); | BLI_rw_mutex_lock(&o->oceanmutex, THREAD_LOCK_WRITE); | ||||
| /* Note about multi-threading here: we have to run a first set of computations (htilda one) | /* Note about multi-threading here: we have to run a first set of computations (htilda one) | ||||
| * before we can run all others, since they all depend on it. | * before we can run all others, since they all depend on it. | ||||
| * So we make a first parallelized forloop run for htilda, | * So we make a first parallelized forloop run for htilda, | ||||
| * and then pack all other computations into a set of parallel tasks. | * and then pack all other computations into a set of parallel tasks. | ||||
| * This is not optimal in all cases, | * This is not optimal in all cases, | ||||
| * but remains reasonably simple and should be OK most of the time. */ | * but remains reasonably simple and should be OK most of the time. */ | ||||
| /* compute a new htilda */ | /* compute a new htilda */ | ||||
| TaskParallelSettings settings; | TaskParallelSettings settings; | ||||
| BLI_parallel_range_settings_defaults(&settings); | BLI_parallel_range_settings_defaults(&settings); | ||||
| settings.use_threading = (o->_M > 16); | settings.use_threading = (o->_M > 16); | ||||
| BLI_task_parallel_range(0, o->_M, &osd, ocean_compute_htilda, &settings); | BLI_task_parallel_range(0, o->_M, &osd, ocean_compute_htilda, &settings); | ||||
| if (o->_do_disp_y) { | if (o->_do_disp_y) { | ||||
| BLI_task_pool_push(pool, ocean_compute_displacement_y, NULL, false, NULL); | BLI_task_pool_tbb_push(pool, ocean_compute_displacement_y, NULL, false, NULL); | ||||
| } | } | ||||
| if (o->_do_chop) { | if (o->_do_chop) { | ||||
| BLI_task_pool_push(pool, ocean_compute_displacement_x, NULL, false, NULL); | BLI_task_pool_tbb_push(pool, ocean_compute_displacement_x, NULL, false, NULL); | ||||
| BLI_task_pool_push(pool, ocean_compute_displacement_z, NULL, false, NULL); | BLI_task_pool_tbb_push(pool, ocean_compute_displacement_z, NULL, false, NULL); | ||||
| } | } | ||||
| if (o->_do_jacobian) { | if (o->_do_jacobian) { | ||||
| BLI_task_pool_push(pool, ocean_compute_jacobian_jxx, NULL, false, NULL); | BLI_task_pool_tbb_push(pool, ocean_compute_jacobian_jxx, NULL, false, NULL); | ||||
| BLI_task_pool_push(pool, ocean_compute_jacobian_jzz, NULL, false, NULL); | BLI_task_pool_tbb_push(pool, ocean_compute_jacobian_jzz, NULL, false, NULL); | ||||
| BLI_task_pool_push(pool, ocean_compute_jacobian_jxz, NULL, false, NULL); | BLI_task_pool_tbb_push(pool, ocean_compute_jacobian_jxz, NULL, false, NULL); | ||||
| } | } | ||||
| if (o->_do_normals) { | if (o->_do_normals) { | ||||
| BLI_task_pool_push(pool, ocean_compute_normal_x, NULL, false, NULL); | BLI_task_pool_tbb_push(pool, ocean_compute_normal_x, NULL, false, NULL); | ||||
| BLI_task_pool_push(pool, ocean_compute_normal_z, NULL, false, NULL); | BLI_task_pool_tbb_push(pool, ocean_compute_normal_z, NULL, false, NULL); | ||||
| o->_N_y = 1.0f / scale; | o->_N_y = 1.0f / scale; | ||||
| } | } | ||||
| BLI_task_pool_work_and_wait(pool); | BLI_task_pool_tbb_work_and_wait(pool); | ||||
| BLI_rw_mutex_unlock(&o->oceanmutex); | BLI_rw_mutex_unlock(&o->oceanmutex); | ||||
| BLI_task_pool_free(pool); | BLI_task_pool_tbb_free(pool); | ||||
| } | } | ||||
| static void set_height_normalize_factor(struct Ocean *oc) | static void set_height_normalize_factor(struct Ocean *oc) | ||||
| { | { | ||||
| float res = 1.0; | float res = 1.0; | ||||
| float max_h = 0.0; | float max_h = 0.0; | ||||
| int i, j; | int i, j; | ||||
| ▲ Show 20 Lines • Show All 905 Lines • Show Last 20 Lines | |||||