static void* pthread_a_work(void* args) { sorm_connection_t *_conn; int ret = sorm_open(DB_FILE, SORM_DB_SQLITE, 0, &rwlock, SORM_ENABLE_RWLOCK, &_conn); assert(ret == SORM_OK); device_t *device; sorm_iterator_t *iterator; ret = device_select_iterate_by_open(_conn, ALL_COLUMNS, NULL, &iterator); sorm_begin_read_transaction(_conn); int i; for (i = 0; i < 4; i ++) { device_select_iterate_by(iterator, &device); char string[1024]; printf("select : %s\n", device_to_string(device, string, 1024)); device_free(device); } sorm_begin_write_transaction(_conn); device = device_new(); device_set_id(device, 3); device_set_uuid(device, "uuid-3"); device_set_name(device, "name-3"); device_set_password(device, "passwd-3"); ret = device_insert(_conn, device); assert(ret == SORM_OK); device_free(device); printf("insert uuid-3\n"); pthread_mutex_lock(&mutex); condition_b = 1; pthread_mutex_unlock(&mutex); pthread_cond_signal(&cond_b); printf("wait for input\n"); ret = getchar(); printf("continue running\n"); sorm_commit_transaction(_conn); while (1) { device_select_iterate_by(iterator, &device); if (!device_select_iterate_more(iterator)) { break; } char string[1024]; printf("select : %s\n", device_to_string(device, string, 1024)); device_free(device); } sorm_commit_transaction(_conn); device_select_iterate_close(iterator); //sorm_commit_transaction(_conn); printf("a finish\n"); sorm_close(_conn); }
void Integrator::device_update(Device *device, DeviceScene *dscene, Scene *scene) { if(!need_update) return; device_free(device, dscene); KernelIntegrator *kintegrator = &dscene->data.integrator; /* integrator parameters */ kintegrator->max_bounce = max_bounce + 1; if(probalistic_termination) kintegrator->min_bounce = min_bounce + 1; else kintegrator->min_bounce = kintegrator->max_bounce; kintegrator->max_diffuse_bounce = max_diffuse_bounce + 1; kintegrator->max_glossy_bounce = max_glossy_bounce + 1; kintegrator->max_transmission_bounce = max_transmission_bounce + 1; kintegrator->transparent_max_bounce = transparent_max_bounce + 1; if(transparent_probalistic) kintegrator->transparent_min_bounce = transparent_min_bounce + 1; else kintegrator->transparent_min_bounce = kintegrator->transparent_max_bounce; kintegrator->transparent_shadows = transparent_shadows; kintegrator->no_caustics = no_caustics; kintegrator->filter_glossy = (filter_glossy == 0.0f)? FLT_MAX: 1.0f/filter_glossy; kintegrator->seed = hash_int(seed); kintegrator->layer_flag = layer_flag << PATH_RAY_LAYER_SHIFT; kintegrator->use_ambient_occlusion = ((dscene->data.film.pass_flag & PASS_AO) || dscene->data.background.ao_factor != 0.0f); kintegrator->sample_clamp = (sample_clamp == 0.0f)? FLT_MAX: sample_clamp*3.0f; kintegrator->branched = (method == BRANCHED_PATH); kintegrator->aa_samples = aa_samples; kintegrator->diffuse_samples = diffuse_samples; kintegrator->glossy_samples = glossy_samples; kintegrator->transmission_samples = transmission_samples; kintegrator->ao_samples = ao_samples; kintegrator->mesh_light_samples = mesh_light_samples; kintegrator->subsurface_samples = subsurface_samples; kintegrator->sampling_pattern = sampling_pattern; /* sobol directions table */ int max_samples = 1; if(method == BRANCHED_PATH) { foreach(Light *light, scene->lights) max_samples = max(max_samples, light->samples); max_samples = max(max_samples, max(diffuse_samples, max(glossy_samples, transmission_samples))); max_samples = max(max_samples, max(ao_samples, max(mesh_light_samples, subsurface_samples))); } max_samples *= (max_bounce + transparent_max_bounce + 3); int dimensions = PRNG_BASE_NUM + max_samples*PRNG_BOUNCE_NUM; dimensions = min(dimensions, SOBOL_MAX_DIMENSIONS); uint *directions = dscene->sobol_directions.resize(SOBOL_BITS*dimensions); sobol_generate_direction_vectors((uint(*)[SOBOL_BITS])directions, dimensions); device->tex_alloc("__sobol_directions", dscene->sobol_directions); need_update = false; }
static void manager_free(Manager *m) { Session *session; User *u; Device *d; Seat *s; Inhibitor *i; Button *b; if (!m) return; while ((session = hashmap_first(m->sessions))) session_free(session); while ((u = hashmap_first(m->users))) user_free(u); while ((d = hashmap_first(m->devices))) device_free(d); while ((s = hashmap_first(m->seats))) seat_free(s); while ((i = hashmap_first(m->inhibitors))) inhibitor_free(i); while ((b = hashmap_first(m->buttons))) button_free(b); hashmap_free(m->devices); hashmap_free(m->seats); hashmap_free(m->sessions); hashmap_free(m->users); hashmap_free(m->inhibitors); hashmap_free(m->buttons); hashmap_free(m->user_units); hashmap_free(m->session_units); sd_event_source_unref(m->idle_action_event_source); sd_event_source_unref(m->inhibit_timeout_source); sd_event_source_unref(m->scheduled_shutdown_timeout_source); sd_event_source_unref(m->nologin_timeout_source); sd_event_source_unref(m->wall_message_timeout_source); sd_event_source_unref(m->console_active_event_source); sd_event_source_unref(m->udev_seat_event_source); sd_event_source_unref(m->udev_device_event_source); sd_event_source_unref(m->udev_vcsa_event_source); sd_event_source_unref(m->udev_button_event_source); sd_event_source_unref(m->lid_switch_ignore_event_source); safe_close(m->console_active_fd); udev_monitor_unref(m->udev_seat_monitor); udev_monitor_unref(m->udev_device_monitor); udev_monitor_unref(m->udev_vcsa_monitor); udev_monitor_unref(m->udev_button_monitor); udev_unref(m->udev); if (m->unlink_nologin) (void) unlink_or_warn("/run/nologin"); bus_verify_polkit_async_registry_free(m->polkit_registry); sd_bus_unref(m->bus); sd_event_unref(m->event); safe_close(m->reserve_vt_fd); strv_free(m->kill_only_users); strv_free(m->kill_exclude_users); free(m->scheduled_shutdown_type); free(m->scheduled_shutdown_tty); free(m->wall_message); free(m->action_job); free(m); }
int main() { pthread_rwlock_init(&rwlock, NULL); pthread_t p1, p2; sorm_init(0); sorm_connection_t *_conn; int ret = sorm_open(DB_FILE, SORM_DB_SQLITE, 0, &rwlock, SORM_ENABLE_RWLOCK, &_conn); ret = device_create_table(_conn); assert(ret == SORM_OK); /* insert rows for select */ int i; device_t *device; for(i = 0; i < 10; i ++) { if (i == 3) { continue; } device = device_new(); device->id = i; device->id_stat = SORM_STAT_VALUED; sprintf(device->uuid,"uuid-%d", i); device->uuid_stat = SORM_STAT_VALUED; sprintf(device->name,"name-%d", i); device->name_stat = SORM_STAT_VALUED; sprintf(device->password, "passwd-%d", i); device->password_stat = SORM_STAT_VALUED; device_insert(_conn, device); device_free(device); } ret = pthread_create(&p1, NULL, pthread_a_work, (void*)_conn); assert(ret == 0); ret = pthread_create(&p2, NULL, pthread_b_work, (void*)_conn); assert(ret == 0); pthread_join(p1, NULL); pthread_join(p2, NULL); sorm_iterator_t *iterator; ret = device_select_iterate_by_open(_conn, ALL_COLUMNS, NULL, &iterator); while (1) { device_select_iterate_by(iterator, &device); if (!device_select_iterate_more(iterator)) { break; } char string[1024]; printf("select : %s\n", device_to_string(device, string, 1024)); device_free(device); } device_select_iterate_close(iterator); ret = device_delete_table(_conn); assert(ret == SORM_OK); sorm_close(_conn); }
static void do_loadLinkToGPU(int* X, void *even, void*odd, void **cpuGauge, void** ghost_cpuGauge, void** ghost_cpuGauge_diag, QudaReconstructType reconstruct, int bytes, int Vh, int pad, int Vsh_x, int Vsh_y, int Vsh_z, int Vsh_t, QudaPrecision prec, QudaGaugeFieldOrder cpu_order) { int Vh_2d_max = MAX(X[0]*X[1]/2, X[0]*X[2]/2); Vh_2d_max = MAX(Vh_2d_max, X[0]*X[3]/2); Vh_2d_max = MAX(Vh_2d_max, X[1]*X[2]/2); Vh_2d_max = MAX(Vh_2d_max, X[1]*X[3]/2); Vh_2d_max = MAX(Vh_2d_max, X[2]*X[3]/2); int i; int len = Vh*gaugeSiteSize*prec; #ifdef MULTI_GPU int glen[4] = { Vsh_x*gaugeSiteSize*prec, Vsh_y*gaugeSiteSize*prec, Vsh_z*gaugeSiteSize*prec, Vsh_t*gaugeSiteSize*prec }; int ghostV = 2*(Vsh_x+Vsh_y+Vsh_z+Vsh_t)+4*Vh_2d_max; #else int ghostV = 0; #endif int glen_sum = ghostV*gaugeSiteSize*prec; char *tmp_even = (char *) device_malloc(4*(len+glen_sum)); char *tmp_odd = tmp_even; //even links if(cpu_order == QUDA_QDP_GAUGE_ORDER){ for(i=0;i < 4; i++){ #ifdef GPU_DIRECT cudaMemcpyAsync(tmp_even + i*(len+glen_sum), cpuGauge[i], len, cudaMemcpyHostToDevice, streams[0]); #else cudaMemcpy(tmp_even + i*(len+glen_sum), cpuGauge[i], len, cudaMemcpyHostToDevice); #endif } } else { //QUDA_MILC_GAUGE_ORDER #ifdef MULTI_GPU errorQuda("Multi-GPU for MILC gauge order is not supported"); #endif #ifdef GPU_DIRECT cudaMemcpyAsync(tmp_even, ((char*)cpuGauge), 4*len, cudaMemcpyHostToDevice, streams[0]); #else cudaMemcpy(tmp_even, ((char*)cpuGauge), 4*len, cudaMemcpyHostToDevice); #endif } for(i=0;i < 4;i++){ #ifdef MULTI_GPU //dir: the source direction char* dest = tmp_even + i*(len+glen_sum)+len; for(int dir = 0; dir < 4; dir++){ #ifdef GPU_DIRECT cudaMemcpyAsync(dest, ((char*)ghost_cpuGauge[dir])+i*2*glen[dir], glen[dir], cudaMemcpyHostToDevice, streams[0]); cudaMemcpyAsync(dest + glen[dir], ((char*)ghost_cpuGauge[dir])+8*glen[dir]+i*2*glen[dir], glen[dir], cudaMemcpyHostToDevice, streams[0]); #else cudaMemcpy(dest, ((char*)ghost_cpuGauge[dir])+i*2*glen[dir], glen[dir], cudaMemcpyHostToDevice); cudaMemcpy(dest + glen[dir], ((char*)ghost_cpuGauge[dir])+8*glen[dir]+i*2*glen[dir], glen[dir], cudaMemcpyHostToDevice); #endif dest += 2*glen[dir]; } //fill in diag //@nu is @i, mu iterats from 0 to 4 and mu != nu int nu = i; for(int mu = 0; mu < 4; mu++){ if(nu == mu ){ continue; } int dir1, dir2; for(dir1=0; dir1 < 4; dir1 ++){ if(dir1 != nu && dir1 != mu){ break; } } for(dir2=0; dir2 < 4; dir2 ++){ if(dir2 != nu && dir2 != mu && dir2 != dir1){ break; } } #ifdef GPU_DIRECT cudaMemcpyAsync(dest+ mu *Vh_2d_max*gaugeSiteSize*prec,ghost_cpuGauge_diag[nu*4+mu], X[dir1]*X[dir2]/2*gaugeSiteSize*prec, cudaMemcpyHostToDevice, streams[0]); #else cudaMemcpy(dest+ mu *Vh_2d_max*gaugeSiteSize*prec,ghost_cpuGauge_diag[nu*4+mu], X[dir1]*X[dir2]/2*gaugeSiteSize*prec, cudaMemcpyHostToDevice); #endif } #endif } link_format_cpu_to_gpu((void*)even, (void*)tmp_even, reconstruct, Vh, pad, ghostV, prec, cpu_order, streams[0]); //odd links if(cpu_order == QUDA_QDP_GAUGE_ORDER){ for(i=0;i < 4; i++){ #ifdef GPU_DIRECT cudaMemcpyAsync(tmp_odd + i*(len+glen_sum), ((char*)cpuGauge[i]) + Vh*gaugeSiteSize*prec, len, cudaMemcpyHostToDevice, streams[0]); #else cudaMemcpy(tmp_odd + i*(len+glen_sum), ((char*)cpuGauge[i]) + Vh*gaugeSiteSize*prec, len, cudaMemcpyHostToDevice); #endif } }else{ //QUDA_MILC_GAUGE_ORDER #ifdef GPU_DIRECT cudaMemcpyAsync(tmp_odd , ((char*)cpuGauge)+4*Vh*gaugeSiteSize*prec, 4*len, cudaMemcpyHostToDevice, streams[0]); #else cudaMemcpy(tmp_odd, (char*)cpuGauge+4*Vh*gaugeSiteSize*prec, 4*len, cudaMemcpyHostToDevice); #endif } for(i=0;i < 4; i++){ #ifdef MULTI_GPU char* dest = tmp_odd + i*(len+glen_sum)+len; for(int dir = 0; dir < 4; dir++){ #ifdef GPU_DIRECT cudaMemcpyAsync(dest, ((char*)ghost_cpuGauge[dir])+glen[dir] +i*2*glen[dir], glen[dir], cudaMemcpyHostToDevice, streams[0]); cudaMemcpyAsync(dest + glen[dir], ((char*)ghost_cpuGauge[dir])+8*glen[dir]+glen[dir] +i*2*glen[dir], glen[dir], cudaMemcpyHostToDevice, streams[0]); #else cudaMemcpy(dest, ((char*)ghost_cpuGauge[dir])+glen[dir] +i*2*glen[dir], glen[dir], cudaMemcpyHostToDevice); cudaMemcpy(dest + glen[dir], ((char*)ghost_cpuGauge[dir])+8*glen[dir]+glen[dir] +i*2*glen[dir], glen[dir], cudaMemcpyHostToDevice); #endif dest += 2*glen[dir]; } //fill in diag //@nu is @i, mu iterats from 0 to 4 and mu != nu int nu = i; for(int mu = 0; mu < 4; mu++){ if(nu == mu ){ continue; } int dir1, dir2; for(dir1=0; dir1 < 4; dir1 ++){ if(dir1 != nu && dir1 != mu){ break; } } for(dir2=0; dir2 < 4; dir2 ++){ if(dir2 != nu && dir2 != mu && dir2 != dir1){ break; } } #ifdef GPU_DIRECT cudaMemcpyAsync(dest+ mu *Vh_2d_max*gaugeSiteSize*prec,((char*)ghost_cpuGauge_diag[nu*4+mu])+X[dir1]*X[dir2]/2*gaugeSiteSize*prec, X[dir1]*X[dir2]/2*gaugeSiteSize*prec, cudaMemcpyHostToDevice, streams[0]); #else cudaMemcpy(dest+ mu *Vh_2d_max*gaugeSiteSize*prec,((char*)ghost_cpuGauge_diag[nu*4+mu])+X[dir1]*X[dir2]/2*gaugeSiteSize*prec, X[dir1]*X[dir2]/2*gaugeSiteSize*prec, cudaMemcpyHostToDevice ); #endif } #endif } link_format_cpu_to_gpu((void*)odd, (void*)tmp_odd, reconstruct, Vh, pad, ghostV, prec, cpu_order, streams[0]); cudaStreamSynchronize(streams[0]); device_free(tmp_even); }
int run_simulation(struct simulation *sim) { struct device cell; log_clear(sim); printf_log(sim,_("Run_simulation\n")); device_init(&cell); cell.onlypos=FALSE; dump_init(sim,&cell); set_dump_status(sim,dump_stop_plot, FALSE); set_dump_status(sim,dump_print_text, TRUE); char temp[1000]; cell.kl_in_newton=FALSE; //if (strcmp(outputpath,"")!=0) strcpy(get_output_path(sim),outputpath); //if (strcmp(inputpath,"")!=0) strcpy(get_input_path(sim),inputpath); dump_load_config(sim,&cell); int i; int z; int x; int y; join_path(2,temp,get_output_path(sim),"error.dat"); remove(temp); join_path(2,temp,get_output_path(sim),"equilibrium"); remove_dir(sim,temp); join_path(2,temp,get_output_path(sim),"snapshots"); remove_dir(sim,temp); join_path(2,temp,get_output_path(sim),"light_dump"); remove_dir(sim,temp); join_path(2,temp,get_output_path(sim),"dynamic"); remove_dir(sim,temp); join_path(2,temp,get_output_path(sim),"frequency"); remove_dir(sim,temp); load_config(sim,&cell); if (strcmp(sim->force_sim_mode,"")!=0) { strcpy(cell.simmode,sim->force_sim_mode); } if (strcmp(cell.simmode,"opticalmodel@optics")!=0) { solver_init(sim,cell.solver_name); newton_init(sim,cell.newton_name); printf_log(sim,_("Loading DoS for %d layers\n"),cell.my_epitaxy.electrical_layers); char tempn[100]; char tempp[100]; i=0; for (i=0;i<cell.my_epitaxy.electrical_layers;i++) { dos_init(&cell,i); printf_log(sim,"Load DoS %d/%d\n",i,cell.my_epitaxy.electrical_layers); sprintf(tempn,"%s_dosn.dat",cell.my_epitaxy.dos_file[i]); sprintf(tempp,"%s_dosp.dat",cell.my_epitaxy.dos_file[i]); load_dos(sim,&cell,tempn,tempp,i); } device_alloc_traps(&cell); if (get_dump_status(sim,dump_write_converge)==TRUE) { sim->converge = fopena(get_output_path(sim),"converge.dat","w"); fclose(sim->converge); sim->tconverge=fopena(get_output_path(sim),"tconverge.dat","w"); fclose(sim->tconverge); } mesh_cal_layer_widths(&cell); long double depth=0.0; long double percent=0.0; long double value=0.0; for (z=0;z<cell.zmeshpoints;z++) { for (x=0;x<cell.xmeshpoints;x++) { for (y=0;y<cell.ymeshpoints;y++) { depth=cell.ymesh[y]-cell.layer_start[cell.imat[z][x][y]]; percent=depth/cell.layer_width[cell.imat[z][x][y]]; cell.Nad[z][x][y]=get_dos_doping_start(&cell,cell.imat[z][x][y])+(get_dos_doping_stop(&cell,cell.imat[z][x][y])-get_dos_doping_start(&cell,cell.imat[z][x][y]))*percent; } } } init_mat_arrays(&cell); for (z=0;z<cell.zmeshpoints;z++) { for (x=0;x<cell.xmeshpoints;x++) { for (y=0;y<cell.ymeshpoints;y++) { cell.phi[z][x][y]=0.0; cell.R[z][x][y]=0.0; cell.n[z][x][y]=0.0; } } } contacts_load(sim,&cell); cell.C=cell.xlen*cell.zlen*epsilon0*cell.epsilonr[0][0][0]/(cell.ylen+cell.other_layers); if (get_dump_status(sim,dump_print_text)==TRUE) printf_log(sim,"C=%Le\n",cell.C); cell.A=cell.xlen*cell.zlen; cell.Vol=cell.xlen*cell.zlen*cell.ylen; ///////////////////////light model char old_model[100]; gdouble old_Psun=0.0; old_Psun=light_get_sun(&cell.mylight); light_init(&cell.mylight); light_set_dx(&cell.mylight,cell.ymesh[1]-cell.ymesh[0]); light_load_config(sim,&cell.mylight); if (cell.led_on==TRUE) { strcpy(old_model,cell.mylight.mode); strcpy(cell.mylight.mode,"ray"); } light_load_dlls(sim,&cell.mylight); light_setup_ray(sim,&cell,&cell.mylight); if (cell.led_on==TRUE) { cell.mylight.force_update=TRUE; light_set_sun(&(cell.mylight),1.0); light_set_sun_delta_at_wavelength(&(cell.mylight),cell.led_wavelength); light_solve_all(sim,&(cell.mylight)); cell.mylight.force_update=FALSE; strcpy(cell.mylight.mode,old_model); light_set_sun(&(cell.mylight),old_Psun); light_free_dlls(sim,&cell.mylight); light_load_dlls(sim,&cell.mylight); } /////////////////////// //update_arrays(&cell); contact_set_all_voltages(sim,&cell,0.0); get_initial(sim,&cell); remesh_shrink(&cell); if (cell.math_enable_pos_solver==TRUE) { for (z=0;z<cell.zmeshpoints;z++) { for (x=0;x<cell.xmeshpoints;x++) { solve_pos(sim,&cell,z,x); } } } time_init(sim,&cell); cell.N=0; cell.M=0; solver_realloc(sim,&cell); plot_open(sim); cell.go_time=FALSE; plot_now(sim,"plot"); //set_solver_dump_every_matrix(1); find_n0(sim,&cell); //set_solver_dump_every_matrix(0); draw_gaus(&cell); if (cell.onlypos==TRUE) { join_path(2,temp,get_output_path(sim),"equilibrium"); dump_1d_slice(sim,&cell,temp); device_free(sim,&cell); device_free_traps(&cell); mesh_free(sim,&cell); return 0; } } //Load the dll if (is_domain(cell.simmode)!=0) { char gussed_full_mode[200]; if (guess_whole_sim_name(sim,gussed_full_mode,get_input_path(sim),cell.simmode)==0) { printf_log(sim,"I guess we are using running %s\n",gussed_full_mode); strcpy(cell.simmode,gussed_full_mode); }else { ewe(sim,"I could not guess which simulation to run from the mode %s\n",cell.simmode); } } run_electrical_dll(sim,&cell,strextract_domain(cell.simmode)); if (strcmp(cell.simmode,"opticalmodel@optics")!=0) { device_free(sim,&cell); device_free_traps(&cell); mesh_free(sim,&cell); plot_close(sim); for (i=0;i<cell.my_epitaxy.electrical_layers;i++) { dos_free(&cell,i); } solver_free_memory(sim,&cell); newton_interface_free(sim); light_free(sim,&cell.mylight); } return cell.odes; }
void manager_free(Manager *m) { Session *session; User *u; Device *d; Seat *s; Inhibitor *i; Button *b; assert(m); while ((session = hashmap_first(m->sessions))) session_free(session); while ((u = hashmap_first(m->users))) user_free(u); while ((d = hashmap_first(m->devices))) device_free(d); while ((s = hashmap_first(m->seats))) seat_free(s); while ((i = hashmap_first(m->inhibitors))) inhibitor_free(i); while ((b = hashmap_first(m->buttons))) button_free(b); hashmap_free(m->devices); hashmap_free(m->seats); hashmap_free(m->sessions); hashmap_free(m->users); hashmap_free(m->inhibitors); hashmap_free(m->buttons); hashmap_free(m->user_units); hashmap_free(m->session_units); set_free_free(m->busnames); sd_event_source_unref(m->idle_action_event_source); sd_event_source_unref(m->console_active_event_source); sd_event_source_unref(m->udev_seat_event_source); sd_event_source_unref(m->udev_device_event_source); sd_event_source_unref(m->udev_vcsa_event_source); sd_event_source_unref(m->udev_button_event_source); sd_event_source_unref(m->lid_switch_ignore_event_source); safe_close(m->console_active_fd); if (m->udev_seat_monitor) udev_monitor_unref(m->udev_seat_monitor); if (m->udev_device_monitor) udev_monitor_unref(m->udev_device_monitor); if (m->udev_vcsa_monitor) udev_monitor_unref(m->udev_vcsa_monitor); if (m->udev_button_monitor) udev_monitor_unref(m->udev_button_monitor); if (m->udev) udev_unref(m->udev); bus_verify_polkit_async_registry_free(m->bus, m->polkit_registry); sd_bus_unref(m->bus); sd_event_unref(m->event); safe_close(m->reserve_vt_fd); strv_free(m->kill_only_users); strv_free(m->kill_exclude_users); free(m->action_job); free(m); }
void Background::device_update(Device *device, DeviceScene *dscene, Scene *scene) { if (!need_update) return; device_free(device, dscene); Shader *bg_shader = shader; if (use_shader) { if (!bg_shader) bg_shader = scene->default_background; } else bg_shader = scene->default_empty; /* set shader index and transparent option */ KernelBackground *kbackground = &dscene->data.background; kbackground->ao_factor = (use_ao) ? ao_factor : 0.0f; kbackground->ao_bounces_factor = ao_factor; kbackground->ao_distance = ao_distance; kbackground->transparent = transparent; kbackground->surface_shader = scene->shader_manager->get_shader_id(bg_shader); if (transparent && transparent_glass) { /* Square twice, once for principled BSDF convention, and once for * faster comparison in kernel with anisotropic roughness. */ kbackground->transparent_roughness_squared_threshold = sqr( sqr(transparent_roughness_threshold)); } else { kbackground->transparent_roughness_squared_threshold = -1.0f; } if (bg_shader->has_volume) kbackground->volume_shader = kbackground->surface_shader; else kbackground->volume_shader = SHADER_NONE; /* No background node, make world shader invisible to all rays, to skip evaluation in kernel. */ if (bg_shader->graph->nodes.size() <= 1) { kbackground->surface_shader |= SHADER_EXCLUDE_ANY; } /* Background present, check visibilities */ else { if (!(visibility & PATH_RAY_DIFFUSE)) kbackground->surface_shader |= SHADER_EXCLUDE_DIFFUSE; if (!(visibility & PATH_RAY_GLOSSY)) kbackground->surface_shader |= SHADER_EXCLUDE_GLOSSY; if (!(visibility & PATH_RAY_TRANSMIT)) kbackground->surface_shader |= SHADER_EXCLUDE_TRANSMIT; if (!(visibility & PATH_RAY_VOLUME_SCATTER)) kbackground->surface_shader |= SHADER_EXCLUDE_SCATTER; if (!(visibility & PATH_RAY_CAMERA)) kbackground->surface_shader |= SHADER_EXCLUDE_CAMERA; } need_update = false; }
void Film::device_update(Device *device, DeviceScene *dscene, Scene *scene) { if (!need_update) return; device_free(device, dscene, scene); KernelFilm *kfilm = &dscene->data.film; /* update __data */ kfilm->exposure = exposure; kfilm->pass_flag = 0; kfilm->light_pass_flag = 0; kfilm->pass_stride = 0; kfilm->use_light_pass = use_light_visibility || use_sample_clamp; bool have_cryptomatte = false; for (size_t i = 0; i < passes.size(); i++) { Pass &pass = passes[i]; if (pass.type == PASS_NONE) { continue; } /* Can't do motion pass if no motion vectors are available. */ if (pass.type == PASS_MOTION || pass.type == PASS_MOTION_WEIGHT) { if (scene->need_motion() != Scene::MOTION_PASS) { kfilm->pass_stride += pass.components; continue; } } int pass_flag = (1 << (pass.type % 32)); if (pass.type <= PASS_CATEGORY_MAIN_END) { kfilm->pass_flag |= pass_flag; } else { assert(pass.type <= PASS_CATEGORY_LIGHT_END); kfilm->use_light_pass = 1; kfilm->light_pass_flag |= pass_flag; } switch (pass.type) { case PASS_COMBINED: kfilm->pass_combined = kfilm->pass_stride; break; case PASS_DEPTH: kfilm->pass_depth = kfilm->pass_stride; break; case PASS_NORMAL: kfilm->pass_normal = kfilm->pass_stride; break; case PASS_UV: kfilm->pass_uv = kfilm->pass_stride; break; case PASS_MOTION: kfilm->pass_motion = kfilm->pass_stride; break; case PASS_MOTION_WEIGHT: kfilm->pass_motion_weight = kfilm->pass_stride; break; case PASS_OBJECT_ID: kfilm->pass_object_id = kfilm->pass_stride; break; case PASS_MATERIAL_ID: kfilm->pass_material_id = kfilm->pass_stride; break; case PASS_MIST: kfilm->pass_mist = kfilm->pass_stride; break; case PASS_EMISSION: kfilm->pass_emission = kfilm->pass_stride; break; case PASS_BACKGROUND: kfilm->pass_background = kfilm->pass_stride; break; case PASS_AO: kfilm->pass_ao = kfilm->pass_stride; break; case PASS_SHADOW: kfilm->pass_shadow = kfilm->pass_stride; break; case PASS_LIGHT: break; case PASS_DIFFUSE_COLOR: kfilm->pass_diffuse_color = kfilm->pass_stride; break; case PASS_GLOSSY_COLOR: kfilm->pass_glossy_color = kfilm->pass_stride; break; case PASS_TRANSMISSION_COLOR: kfilm->pass_transmission_color = kfilm->pass_stride; break; case PASS_SUBSURFACE_COLOR: kfilm->pass_subsurface_color = kfilm->pass_stride; break; case PASS_DIFFUSE_INDIRECT: kfilm->pass_diffuse_indirect = kfilm->pass_stride; break; case PASS_GLOSSY_INDIRECT: kfilm->pass_glossy_indirect = kfilm->pass_stride; break; case PASS_TRANSMISSION_INDIRECT: kfilm->pass_transmission_indirect = kfilm->pass_stride; break; case PASS_SUBSURFACE_INDIRECT: kfilm->pass_subsurface_indirect = kfilm->pass_stride; break; case PASS_VOLUME_INDIRECT: kfilm->pass_volume_indirect = kfilm->pass_stride; break; case PASS_DIFFUSE_DIRECT: kfilm->pass_diffuse_direct = kfilm->pass_stride; break; case PASS_GLOSSY_DIRECT: kfilm->pass_glossy_direct = kfilm->pass_stride; break; case PASS_TRANSMISSION_DIRECT: kfilm->pass_transmission_direct = kfilm->pass_stride; break; case PASS_SUBSURFACE_DIRECT: kfilm->pass_subsurface_direct = kfilm->pass_stride; break; case PASS_VOLUME_DIRECT: kfilm->pass_volume_direct = kfilm->pass_stride; break; #ifdef WITH_CYCLES_DEBUG case PASS_BVH_TRAVERSED_NODES: kfilm->pass_bvh_traversed_nodes = kfilm->pass_stride; break; case PASS_BVH_TRAVERSED_INSTANCES: kfilm->pass_bvh_traversed_instances = kfilm->pass_stride; break; case PASS_BVH_INTERSECTIONS: kfilm->pass_bvh_intersections = kfilm->pass_stride; break; case PASS_RAY_BOUNCES: kfilm->pass_ray_bounces = kfilm->pass_stride; break; #endif case PASS_RENDER_TIME: break; case PASS_CRYPTOMATTE: kfilm->pass_cryptomatte = have_cryptomatte ? min(kfilm->pass_cryptomatte, kfilm->pass_stride) : kfilm->pass_stride; have_cryptomatte = true; break; default: assert(false); break; } kfilm->pass_stride += pass.components; } kfilm->pass_denoising_data = 0; kfilm->pass_denoising_clean = 0; kfilm->denoising_flags = 0; if (denoising_data_pass) { kfilm->pass_denoising_data = kfilm->pass_stride; kfilm->pass_stride += DENOISING_PASS_SIZE_BASE; kfilm->denoising_flags = denoising_flags; if (denoising_clean_pass) { kfilm->pass_denoising_clean = kfilm->pass_stride; kfilm->pass_stride += DENOISING_PASS_SIZE_CLEAN; kfilm->use_light_pass = 1; } if (denoising_prefiltered_pass) { kfilm->pass_stride += DENOISING_PASS_SIZE_PREFILTERED; } } kfilm->pass_stride = align_up(kfilm->pass_stride, 4); kfilm->pass_alpha_threshold = pass_alpha_threshold; /* update filter table */ vector<float> table = filter_table(filter_type, filter_width); scene->lookup_tables->remove_table(&filter_table_offset); filter_table_offset = scene->lookup_tables->add_table(dscene, table); kfilm->filter_table_offset = (int)filter_table_offset; /* mist pass parameters */ kfilm->mist_start = mist_start; kfilm->mist_inv_depth = (mist_depth > 0.0f) ? 1.0f / mist_depth : 0.0f; kfilm->mist_falloff = mist_falloff; kfilm->cryptomatte_passes = cryptomatte_passes; kfilm->cryptomatte_depth = cryptomatte_depth; pass_stride = kfilm->pass_stride; denoising_data_offset = kfilm->pass_denoising_data; denoising_clean_offset = kfilm->pass_denoising_clean; need_update = false; }