annotate Renderer/Engine/Light.cc @ 2069:26aa08c9a1de draft default tip

cuda example fix
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 12 Feb 2017 10:04:55 +0900
parents 3361f2b7c63b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1405
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
1 #include "Light.h"
1406
8587ee89ef79 fix Light.
taiki
parents: 1405
diff changeset
2 #include "Func.h"
1405
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
3
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
4 void
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
5 Light::init()
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
6 {
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
7 int light_num = 4;
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
8 int size = sizeof(float)*4*light_num; //xyz+alfa(4) * light_num(4)
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
9 int light_size = size / sizeof(float);
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
10
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
11 light_xyz = (float *)manager->allocate(size);
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
12
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
13 for (int i = 0; i < light_size ; i++) {
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
14 light_xyz[i] = 0.0f;
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
15 }
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
16
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
17
1411
3361f2b7c63b fix cpu iterator
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1410
diff changeset
18 for(int i = 0;i<SPE_0+spe_num;) { // including CPU_PPE==0
1405
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
19 HTaskPtr data_load = manager->create_task(DataAllocate);
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
20 data_load->set_param(0,(memaddr)3); // num of allocate block
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
21 data_load->set_param(1,(memaddr)(sizeof(float)*4*light_num)); // 1st allocate size
1406
8587ee89ef79 fix Light.
taiki
parents: 1405
diff changeset
22 data_load->set_param(2,(memaddr)LightData); // 1st id
1405
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
23 data_load->set_param(3,(memaddr)(light_num * sizeof(int))); // 2nd size
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
24 data_load->set_param(4,(memaddr)LightSwitch); // 2nd id
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
25 data_load->set_param(5,(memaddr)16); // 3rd size
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
26 data_load->set_param(6,(memaddr)LightSysSwitch); // 3rd id
1410
acfa426b277e light fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1406
diff changeset
27 data_load->set_cpu((CPU_TYPE)i);
1405
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
28 data_load->spawn();
1411
3361f2b7c63b fix cpu iterator
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1410
diff changeset
29 if (i==0) i=SPE_0; else i++;
1405
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
30 }
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
31
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
32 light_switch = (int*)manager->allocate(size);
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
33
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
34 for (int i = 0; i < light_num; i++) {
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
35 light_switch[i] = 0;
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
36 }
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
37
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
38 int light_sw_size = 16; // LightSysSwitch は 4byte. 残り 12byte は DMA転送の為のパディング
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
39
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
40 light_sysswitch = (int*)manager->allocate(light_sw_size);
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
41
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
42 for (unsigned int i = 0; i < light_sw_size / sizeof(int); i++) {
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
43 light_sysswitch[i] = 0;
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
44 }
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
45
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
46 }
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
47
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
48
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
49 bool
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
50 Light::exec(HTaskPtr task_next)
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
51 {
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
52 light_xyz_stock = sgroot->getLightVector();
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
53
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
54
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
55 light_switch_stock = sgroot->getLightSwitch();
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
56 light_sysswitch_stock = sgroot->getLightSysSwitch();
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
57
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
58 return true;
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
59 }
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
60
1406
8587ee89ef79 fix Light.
taiki
parents: 1405
diff changeset
61 HTaskPtr
1405
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
62 Light::update(HTaskPtr task_next)
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
63 {
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
64
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
65 //task_next = manager->create_task(Dummy);
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
66 //task_next->set_post(post2runLoop, (void*)this);
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
67
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
68 //Light info update
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
69
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
70 int light_num = 4;
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
71 int size = sizeof(float)*4*light_num; //xyz+alpha(4) * light_num(4)
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
72 int light_size = size / sizeof(float);
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
73
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
74 for (int i = 0; i < light_size; i++) {
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
75 light_xyz[i] = light_xyz_stock[i];
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
76 }
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
77
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
78 for (int i = 0; i < light_num; i++) {
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
79 light_switch[i] = light_switch_stock[i];
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
80 }
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
81
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
82 light_sysswitch[0] = light_sysswitch_stock;
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
83
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
84
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
85 HTask *data_update_wait = manager->create_task(Dummy);
1411
3361f2b7c63b fix cpu iterator
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1410
diff changeset
86 for(int i = 0;i<SPE_0+spe_num;) { // including CPU_PPE==0
1405
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
87 HTaskPtr data_update = manager->create_task(DataUpdate);
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
88 data_update->set_param(0,3);
1406
8587ee89ef79 fix Light.
taiki
parents: 1405
diff changeset
89 data_update->set_param(1,LightData); // GlobalSet ID base
1405
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
90 data_update->set_inData(0,light_xyz,size); // Light
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
91 data_update->set_inData(1,light_switch,light_num * sizeof(int)); // LightSwitch = Light+1
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
92 data_update->set_inData(2,light_sysswitch,16); // LightSysSwitch = Light+2
1410
acfa426b277e light fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1406
diff changeset
93 data_update->set_cpu((CPU_TYPE)i);
1405
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
94 data_update_wait->wait_for(data_update);
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
95 data_update->spawn();
1411
3361f2b7c63b fix cpu iterator
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1410
diff changeset
96 if (i==0) i=SPE_0; else i++;
1405
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
97 }
1406
8587ee89ef79 fix Light.
taiki
parents: 1405
diff changeset
98 return data_update_wait;
1405
aafad9d18a2c sepalate light
taiki
parents:
diff changeset
99 }