OpenCores
URL https://opencores.org/ocsvn/theia_gpu/theia_gpu/trunk

Subversion Repositories theia_gpu

[/] [theia_gpu/] [branches/] [beta_1.2/] [rtl/] [MEM/] [Module_ROM.v] - Blame information for rev 210

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 21 diegovalve
 
2
 
3
`define ONE (32'h1 << `SCALE)
4
 
5
`timescale 1ns / 1ps
6
`include "aDefinitions.v"
7
/**********************************************************************************
8
Theia, Ray Cast Programable graphic Processing Unit.
9
Copyright (C) 2010  Diego Valverde (diego.valverde.g@gmail.com)
10
 
11
This program is free software; you can redistribute it and/or
12
modify it under the terms of the GNU General Public License
13
as published by the Free Software Foundation; either version 2
14
of the License, or (at your option) any later version.
15
 
16
This program is distributed in the hope that it will be useful,
17
but WITHOUT ANY WARRANTY; without even the implied warranty of
18
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
GNU General Public License for more details.
20
 
21
You should have received a copy of the GNU General Public License
22
along with this program; if not, write to the Free Software
23
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
24
 
25
***********************************************************************************/
26
 
27 60 diegovalve
/*
28
I can't synthesize roms, the rom needs to be adapted depending on the
29
final target silicon.
30
*/
31 21 diegovalve
 
32
 
33
//--------------------------------------------------------
34
module ROM
35
(
36
        input  wire[`ROM_ADDRESS_WIDTH-1:0]              Address,
37
        output reg [`INSTRUCTION_WIDTH-1:0]              I
38
);
39
 
40
 
41
always @( Address )
42
begin
43
                        case (Address)
44
 
45
//Hardcoded stuff :(
46
`define RAY_INSIDE_BOX                          `R3
47
`define CURRENT_LIGHT_POS `CREG_FIRST_LIGTH  //TODO: CAHNEG T 
48
`define CURRENT_LIGHT_DIFFUSE 16'h6
49
 
50
//-----------------------------------------------------------------
51 76 diegovalve
`define TAG_PSU_UCODE_ADRESS2 16'd232
52
`define TAG_PSU_UCODE_ADRESS 16'd216
53
`define LABEL_TCC_EXIT 16'd215
54
`define TAG_TCC_UCODE_ADDRESS 16'd174
55
`define LABEL_BIU4 16'd173
56
`define LABEL_BIU3 16'd163
57
`define LABEL_BIU2 16'd160
58
`define LABEL_BIU1 16'd158
59
`define TAG_BIU_UCODE_ADDRESS 16'd141
60
`define LABEL_HIT 16'd139
61
`define LABEL15 16'd137
62
`define LABEL14 16'd135
63
`define LABEL13 16'd133
64
`define LABEL_TEST_XY_PLANE 16'd128
65
`define LABEL12 16'd126
66
`define LABEL11 16'd124
67
`define LABEL10 16'd122
68
`define LABEL_TEST_XZ_PLANE 16'd116
69
`define LABEL9 16'd114
70
`define LABEL8 16'd112
71
`define LABEL7 16'd110
72
`define LABEL_TEST_YZ_PLANE 16'd104
73
`define LABEL_RAY_INSIDE_BOX 16'd101
74
`define LABEL_ELSEZ 16'd100
75
`define LABEL6 16'd97
76
`define LABEL_ELESE_IFZ 16'd93
77
`define LABEL5 16'd90
78
`define LABEL_TEST_RAY_Z_ORIGEN 16'd86
79
`define LABEL_ELSEY 16'd85
80
`define LABEL4 16'd82
81
`define LABEL_ELESE_IFY 16'd78
82
`define LABEL3 16'd75
83
`define LABEL_TEST_RAY_Y_ORIGEN 16'd71
84
`define LABEL_ELSEX 16'd70
85
`define LABEL2 16'd67
86
`define LABEL_ELSE_IFX 16'd63
87
`define LABEL1 16'd60
88
`define LABEL_TEST_RAY_X_ORIGEN 16'd56
89
`define TAG_AABBIU_UCODE_ADDRESS 16'd53
90
`define LABEL_ALLDONE 16'd51
91
`define LABEL_NPG_NEXT_ROW 16'd47
92
`define TAG_NPG_UCODE_ADDRESS 16'd39
93
`define TAG_RGU_UCODE_ADDRESS 16'd32
94
`define TAG_CPPU_UCODE_ADDRESS 16'd29
95 21 diegovalve
 
96 76 diegovalve
 
97 21 diegovalve
//-------------------------------------------------------------------------
98
//Default values for some registers after reset
99 76 diegovalve
//-------------------------------------------------------------------------
100
//This is the first code that gets executed after the machine is
101
//externally configured, ie after the MST_I goes from 1 to zero.
102
//It sets initial values for some of the internal registers
103 21 diegovalve
 
104 76 diegovalve
0: I = { `ZERO ,`CREG_LAST_t ,`VOID ,`VOID };
105
//Set the last 't' to very positive value(500) 
106
1: I = { `SETX ,`CREG_LAST_t ,32'h1F40000  };
107
2: I = { `ZERO ,`OREG_PIXEL_COLOR ,`VOID ,`VOID };
108
3: I = { `COPY ,`CREG_PIXEL_2D_POSITION ,`CREG_PIXEL_2D_INITIAL_POSITION ,`VOID };
109 21 diegovalve
 
110
 
111 76 diegovalve
//Calculate the initial linear address for ADR_O
112
//this is: (X_initial + RESOLUTION_Y*Y_intial) * 3.
113
//Notice, that we need to use 'unscaled' ie. integer
114
//values because the resuts of the multiplication by
115
//the resoluction is to large to fit a fixed point 
116
//representation.
117 21 diegovalve
 
118 76 diegovalve
4: I = { `COPY ,`R1 ,`CREG_RESOLUTION ,`VOID };
119
5: I = { `UNSCALE ,`R1 ,`R1 ,`VOID };
120
6: I = { `SETX ,`R1 ,32'h1  };
121
7: I = { `SETZ ,`R1 ,32'h0  };
122
8: I = { `COPY ,`R2 ,`CREG_PIXEL_2D_INITIAL_POSITION ,`VOID };
123
9: I = { `UNSCALE ,`R2 ,`R2 ,`VOID };
124 21 diegovalve
 
125 76 diegovalve
//Ok lets start by calculating RESOLUTION_Y*Y_intial
126
10: I = { `IMUL ,`R1 ,`R1 ,`R2 };
127
11: I = { `COPY ,`R2 ,`R1 ,`VOID };
128
12: I = { `SWIZZLE3D ,`R2 ,`SWIZZLE_YYY  };
129
 
130
//now X_initial + RESOLUTION_Y*Y_intial
131
13: I = { `ADD ,`R3 ,`R1 ,`R2 };
132
14: I = { `COPY ,`R2 ,`R1 ,`VOID };
133
15: I = { `SWIZZLE3D ,`R2 ,`SWIZZLE_ZZZ  };
134
16: I = { `ADD ,`R3 ,`R3 ,`R2 };
135
17: I = { `SWIZZLE3D ,`R3 ,`SWIZZLE_XXX  };
136
 
137
//finally multiply by 3 to get:
138
//(X_initial + RESOLUTION_Y*Y_intial) * 3, voila!
139
18: I = { `SETX ,`R2 ,32'h3  };
140
19: I = { `SWIZZLE3D ,`R2 ,`SWIZZLE_XXX  };
141
20: I = { `IMUL ,`CREG_PIXEL_PITCH ,`R3 ,`R2 };
142
//By this point you should be wondering why not
143
//just do DOT R1 [1 Resolution_Y 0] [X_intial Y_intial 0 ]?
144
//well because DOT uses fixed point and the result may not
145
//fit :(
146
 
147
//Transform from fixed point to integer
148
//UNSCALE CREG_PIXEL_PITCH CREG_PIXEL_PITCH VOID
149
21: I = { `COPY ,`OREG_ADDR_O ,`CREG_PIXEL_PITCH ,`VOID };
150
 
151
 
152
22: I = { `ZERO ,`R1 ,`VOID ,`VOID };
153
23: I = { `ZERO ,`R2 ,`VOID ,`VOID };
154
24: I = { `ZERO ,`R3 ,`VOID ,`VOID };
155
25: I = { `ZERO ,`R4 ,`VOID ,`VOID };
156
26: I = { `ZERO ,`R5 ,`VOID ,`VOID };
157
27: I = { `NOP ,`RT_FALSE   };
158
28: I = { `RETURN ,`RT_TRUE   };
159
 
160
 
161
 
162 21 diegovalve
//----------------------------------------------------------------------          
163
//Micro code for CPPU
164 76 diegovalve
//TAG_CPPU_UCODE_ADDRESS:
165 21 diegovalve
 
166
 
167 76 diegovalve
29: I = { `SUB ,`R1 ,`CREG_PROJECTION_WINDOW_MAX ,`CREG_PROJECTION_WINDOW_MIN };
168
30: I = { `DIV ,`CREG_PROJECTION_WINDOW_SCALE ,`R1 ,`CREG_RESOLUTION };
169
31: I = { `RETURN ,`RT_FALSE   };
170 21 diegovalve
 
171
//----------------------------------------------------------------------          
172
//Micro code for RGU
173 76 diegovalve
//TAG_RGU_UCODE_ADDRESS:
174 21 diegovalve
 
175
 
176 76 diegovalve
32: I = { `MUL ,`R1 ,`CREG_PIXEL_2D_POSITION ,`CREG_PROJECTION_WINDOW_SCALE };
177
33: I = { `ADD ,`R1 ,`R1 ,`CREG_PROJECTION_WINDOW_MIN };
178
34: I = { `SUB ,`CREG_UNORMALIZED_DIRECTION ,`R1 ,`CREG_CAMERA_POSITION };
179
35: I = { `MAG ,`R2 ,`CREG_UNORMALIZED_DIRECTION ,`VOID };
180
36: I = { `DIV ,`CREG_RAY_DIRECTION ,`CREG_UNORMALIZED_DIRECTION ,`R2 };
181
37: I = { `DEC,`CREG_LAST_COL,`CREG_PIXEL_2D_FINAL_POSITION ,`VOID   };
182
//   NOP RT_FALSE   
183
38: I = { `RETURN ,`RT_FALSE   };
184 21 diegovalve
//----------------------------------------------------------------------
185
//Next Pixel generation Code (NPG)
186 76 diegovalve
//TAG_NPG_UCODE_ADDRESS:
187 21 diegovalve
 
188 76 diegovalve
 
189
39: I = { `SETX ,`R1 ,32'h00003  };
190
40: I = { `SETY ,`R1 ,32'h00003  };
191
41: I = { `SETZ ,`R1 ,32'h00003  };
192 21 diegovalve
 
193 76 diegovalve
42: I = { `ADD ,`CREG_PIXEL_PITCH ,`CREG_PIXEL_PITCH ,`R1 };
194
43: I = { `COPY ,`OREG_ADDR_O ,`CREG_PIXEL_PITCH ,`VOID };
195
44: I = { `JGEX ,`LABEL_NPG_NEXT_ROW ,`CREG_PIXEL_2D_POSITION ,`CREG_LAST_COL };
196
45: I = { `INCX ,`CREG_PIXEL_2D_POSITION ,`CREG_PIXEL_2D_POSITION ,`VOID };
197
46: I = { `RETURN ,`RT_TRUE   };
198 21 diegovalve
 
199 76 diegovalve
//LABEL_NPG_NEXT_ROW:
200
47: I = { `SETX ,`CREG_PIXEL_2D_POSITION ,32'h0  };
201
48: I = { `INCY ,`CREG_PIXEL_2D_POSITION ,`CREG_PIXEL_2D_POSITION ,`VOID };
202
49: I = { `JGEY ,`LABEL_ALLDONE ,`CREG_PIXEL_2D_POSITION ,`CREG_PIXEL_2D_FINAL_POSITION };
203
50: I = { `RETURN ,`RT_TRUE   };
204
 
205
//LABEL_ALLDONE:
206
51: I = { `NOP ,`VOID ,`VOID  };
207
52: I = { `RETURN ,`RT_FALSE   };
208
 
209 21 diegovalve
//----------------------------------------------------------------------
210
//Micro code for AABBIU
211 76 diegovalve
//TAG_AABBIU_UCODE_ADDRESS:
212 21 diegovalve
 
213 76 diegovalve
53: I = { `ZERO ,`R3 ,`VOID ,`VOID };
214
54: I = { `SETX ,`CREG_LAST_t ,32'h1F40000  };
215
55: I = { `RETURN ,`RT_TRUE   };
216 21 diegovalve
 
217 76 diegovalve
//LABEL_TEST_RAY_X_ORIGEN:
218
56: I = { `JGEX ,`LABEL_ELSE_IFX ,`CREG_CAMERA_POSITION ,`CREG_AABBMIN };
219
57: I = { `SUB ,`R1 ,`CREG_AABBMIN ,`CREG_CAMERA_POSITION };
220
58: I = { `JLEX ,`LABEL1 ,`R1 ,`CREG_UNORMALIZED_DIRECTION };
221
59: I = { `RETURN ,`RT_FALSE   };
222 21 diegovalve
 
223 76 diegovalve
//LABEL1:
224
60: I = { `SETX ,`RAY_INSIDE_BOX ,32'd0  };
225
61: I = { `DIV ,`R6 ,`R1 ,`CREG_UNORMALIZED_DIRECTION };
226
62: I = { `JMP ,`LABEL_TEST_RAY_Y_ORIGEN ,`VOID ,`VOID };
227 21 diegovalve
 
228 76 diegovalve
//LABEL_ELSE_IFX:
229
63: I = { `JLEX ,`LABEL_ELSEX ,`CREG_CAMERA_POSITION ,`CREG_AABBMAX };
230
64: I = { `SUB ,`R1 ,`CREG_AABBMAX ,`CREG_CAMERA_POSITION };
231
65: I = { `JGEX ,`LABEL2 ,`R1 ,`CREG_UNORMALIZED_DIRECTION };
232
66: I = { `RETURN ,`RT_FALSE   };
233 21 diegovalve
 
234 76 diegovalve
//LABEL2:
235
67: I = { `SETX ,`RAY_INSIDE_BOX ,32'd0  };
236
68: I = { `DIV ,`R6 ,`R1 ,`CREG_UNORMALIZED_DIRECTION };
237
69: I = { `JMP ,`LABEL_TEST_RAY_Y_ORIGEN ,`VOID ,`VOID };
238
//LABEL_ELSEX:
239
70: I = { `SETX ,`R5 ,32'b1  };
240 21 diegovalve
 
241 76 diegovalve
//LABEL_TEST_RAY_Y_ORIGEN:
242
71: I = { `JGEY ,`LABEL_ELESE_IFY ,`CREG_CAMERA_POSITION ,`CREG_AABBMIN };
243
72: I = { `SUB ,`R1 ,`CREG_AABBMIN ,`CREG_CAMERA_POSITION };
244
73: I = { `JLEY ,`LABEL3 ,`R1 ,`CREG_UNORMALIZED_DIRECTION };
245
74: I = { `RETURN ,`RT_FALSE   };
246 21 diegovalve
 
247 76 diegovalve
//LABEL3:
248
75: I = { `SETX ,`RAY_INSIDE_BOX ,32'd0  };
249
76: I = { `DIV ,`R6 ,`R1 ,`CREG_UNORMALIZED_DIRECTION };
250
77: I = { `JMP ,`LABEL_TEST_RAY_Z_ORIGEN ,`VOID ,`VOID };
251 21 diegovalve
 
252 76 diegovalve
//LABEL_ELESE_IFY:
253
78: I = { `JLEY ,`LABEL_ELSEY ,`CREG_CAMERA_POSITION ,`CREG_AABBMAX };
254
79: I = { `SUB ,`R1 ,`CREG_AABBMAX ,`CREG_CAMERA_POSITION };
255
80: I = { `JGEY ,`LABEL4 ,`R1 ,`CREG_UNORMALIZED_DIRECTION };
256
81: I = { `RETURN ,`RT_FALSE   };
257 21 diegovalve
 
258 76 diegovalve
//LABEL4:
259
82: I = { `SETX ,`RAY_INSIDE_BOX ,32'd0  };
260
83: I = { `DIV ,`R6 ,`R1 ,`CREG_UNORMALIZED_DIRECTION };
261
84: I = { `JMP ,`LABEL_TEST_RAY_Z_ORIGEN ,`VOID ,`VOID };
262 21 diegovalve
 
263 76 diegovalve
//LABEL_ELSEY:
264
85: I = { `SETY ,`R5 ,32'b1  };
265 21 diegovalve
 
266 76 diegovalve
//LABEL_TEST_RAY_Z_ORIGEN:
267
86: I = { `JGEZ ,`LABEL_ELESE_IFZ ,`CREG_CAMERA_POSITION ,`CREG_AABBMIN };
268
87: I = { `SUB ,`R1 ,`CREG_AABBMIN ,`CREG_CAMERA_POSITION };
269
88: I = { `JLEZ ,`LABEL5 ,`R1 ,`CREG_UNORMALIZED_DIRECTION };
270
89: I = { `RETURN ,`RT_FALSE   };
271 21 diegovalve
 
272 76 diegovalve
//LABEL5:
273
90: I = { `SETX ,`RAY_INSIDE_BOX ,32'd0  };
274
91: I = { `DIV ,`R6 ,`R1 ,`CREG_UNORMALIZED_DIRECTION };
275
92: I = { `JMP ,`LABEL_RAY_INSIDE_BOX ,`VOID ,`VOID };
276 21 diegovalve
 
277 76 diegovalve
//LABEL_ELESE_IFZ:
278
93: I = { `JLEZ ,`LABEL_ELSEZ ,`CREG_CAMERA_POSITION ,`CREG_AABBMAX };
279
94: I = { `SUB ,`R1 ,`CREG_AABBMAX ,`CREG_CAMERA_POSITION };
280
95: I = { `JGEZ ,`LABEL6 ,`R1 ,`CREG_UNORMALIZED_DIRECTION };
281
96: I = { `RETURN ,`RT_FALSE   };
282 21 diegovalve
 
283 76 diegovalve
//LABEL6:
284
97: I = { `SETX ,`RAY_INSIDE_BOX ,32'd0  };
285
98: I = { `DIV ,`R6 ,`R1 ,`CREG_UNORMALIZED_DIRECTION };
286
99: I = { `JMP ,`LABEL_RAY_INSIDE_BOX ,`VOID ,`VOID };
287 21 diegovalve
 
288 76 diegovalve
//LABEL_ELSEZ:
289
100: I = { `SETZ ,`R5 ,32'b1  };
290 21 diegovalve
 
291 76 diegovalve
//LABEL_RAY_INSIDE_BOX:
292
101: I = { `ZERO ,`R1 ,`VOID ,`VOID };
293
102: I = { `JEQX ,`LABEL_TEST_YZ_PLANE ,`R1 ,`RAY_INSIDE_BOX };
294
//BUG need a NOP here else pipeline gets confused
295
103: I = { `RETURN ,`RT_TRUE   };
296 21 diegovalve
 
297 76 diegovalve
//LABEL_TEST_YZ_PLANE:
298
104: I = { `JNEX ,`LABEL_TEST_XZ_PLANE ,`R5 ,`R1 };
299
105: I = { `SWIZZLE3D ,`R6 ,`SWIZZLE_XXX  };
300
106: I = { `MUL ,`R2 ,`CREG_UNORMALIZED_DIRECTION ,`R6 };
301
107: I = { `ADD ,`R2 ,`R2 ,`CREG_CAMERA_POSITION };
302
108: I = { `JGEY ,`LABEL7 ,`R2 ,`CREG_AABBMIN };
303
109: I = { `RETURN ,`RT_FALSE   };
304 21 diegovalve
 
305 76 diegovalve
//LABEL7:
306
110: I = { `JLEY ,`LABEL8 ,`R2 ,`CREG_AABBMAX };
307
111: I = { `RETURN ,`RT_FALSE   };
308 21 diegovalve
 
309 76 diegovalve
//LABEL8:
310
112: I = { `JGEZ ,`LABEL9 ,`R2 ,`CREG_AABBMIN };
311
113: I = { `RETURN ,`RT_FALSE   };
312 21 diegovalve
 
313 76 diegovalve
//LABEL9:
314
114: I = { `JLEZ ,`LABEL_TEST_XZ_PLANE ,`R2 ,`CREG_AABBMAX };
315
115: I = { `RETURN ,`RT_FALSE   };
316 21 diegovalve
 
317 76 diegovalve
//LABEL_TEST_XZ_PLANE:
318
116: I = { `JNEY ,`LABEL_TEST_XY_PLANE ,`R5 ,`R1 };
319
117: I = { `SWIZZLE3D ,`R6 ,`SWIZZLE_YYY  };
320
118: I = { `MUL ,`R2 ,`CREG_UNORMALIZED_DIRECTION ,`R6 };
321
119: I = { `ADD ,`R2 ,`R2 ,`CREG_CAMERA_POSITION };
322
120: I = { `JGEX ,`LABEL10 ,`R2 ,`CREG_AABBMIN };
323
121: I = { `RETURN ,`RT_FALSE   };
324 21 diegovalve
 
325 76 diegovalve
//LABEL10:
326
122: I = { `JLEX ,`LABEL11 ,`R2 ,`CREG_AABBMAX };
327
123: I = { `RETURN ,`RT_FALSE   };
328 21 diegovalve
 
329 76 diegovalve
//LABEL11:
330
124: I = { `JGEZ ,`LABEL12 ,`R2 ,`CREG_AABBMIN };
331
125: I = { `RETURN ,`RT_FALSE   };
332 21 diegovalve
 
333 76 diegovalve
//LABEL12:
334
126: I = { `JLEZ ,`LABEL_TEST_XY_PLANE ,`R2 ,`CREG_AABBMAX };
335
127: I = { `RETURN ,`RT_FALSE   };
336 21 diegovalve
 
337 76 diegovalve
//LABEL_TEST_XY_PLANE:
338
128: I = { `SWIZZLE3D ,`R6 ,`SWIZZLE_ZZZ  };
339
129: I = { `MUL ,`R2 ,`CREG_UNORMALIZED_DIRECTION ,`R6 };
340
130: I = { `ADD ,`R2 ,`R2 ,`CREG_CAMERA_POSITION };
341
131: I = { `JGEX ,`LABEL13 ,`R2 ,`CREG_AABBMIN };
342
132: I = { `RETURN ,`RT_FALSE   };
343 21 diegovalve
 
344 76 diegovalve
//LABEL13:
345
133: I = { `JLEX ,`LABEL14 ,`R2 ,`CREG_AABBMAX };
346
134: I = { `RETURN ,`RT_FALSE   };
347 21 diegovalve
 
348 76 diegovalve
//LABEL14:
349
135: I = { `JGEY ,`LABEL15 ,`R2 ,`CREG_AABBMIN };
350
136: I = { `RETURN ,`RT_FALSE   };
351 21 diegovalve
 
352 76 diegovalve
//LABEL15:
353
137: I = { `JLEY ,`LABEL_HIT ,`R2 ,`CREG_AABBMAX };
354
138: I = { `RETURN ,`RT_FALSE   };
355 21 diegovalve
 
356 76 diegovalve
//LABEL_HIT:
357
139: I = { `SETX ,`CREG_LAST_t ,32'h1F40000  };
358
140: I = { `RETURN ,`RT_TRUE   };
359 21 diegovalve
 
360
 //------------------------------------------------------------------------
361
 //BIU Micro code
362 76 diegovalve
//TAG_BIU_UCODE_ADDRESS:
363 21 diegovalve
 
364 76 diegovalve
141: I = { `ZERO ,`OREG_PIXEL_COLOR ,`VOID ,`VOID };
365
142: I = { `SETX ,`R3 ,`ONE  };
366
143: I = { `SETX ,`R1 ,32'h00000  };
367
144: I = { `SUB ,`CREG_E1 ,`CREG_V1 ,`CREG_V0 };
368
145: I = { `SUB ,`CREG_E2 ,`CREG_V2 ,`CREG_V0 };
369
146: I = { `SUB ,`CREG_T ,`CREG_CAMERA_POSITION ,`CREG_V0 };
370
147: I = { `CROSS ,`CREG_P ,`CREG_RAY_DIRECTION ,`CREG_E2 };
371
148: I = { `CROSS ,`CREG_Q ,`CREG_T ,`CREG_E1 };
372
149: I = { `DOT ,`CREG_H1 ,`CREG_Q ,`CREG_E2 };
373
150: I = { `DOT ,`CREG_H2 ,`CREG_P ,`CREG_T };
374
151: I = { `DOT ,`CREG_H3 ,`CREG_Q ,`CREG_RAY_DIRECTION };
375
152: I = { `DOT ,`CREG_DELTA ,`CREG_P ,`CREG_E1 };
376
153: I = { `DIV ,`CREG_t ,`CREG_H1 ,`CREG_DELTA };
377
154: I = { `DIV ,`CREG_u ,`CREG_H2 ,`CREG_DELTA };
378
155: I = { `DIV ,`CREG_v ,`CREG_H3 ,`CREG_DELTA };
379
156: I = { `JGEX ,`LABEL_BIU1 ,`CREG_u ,`R1 };
380
157: I = { `RETURN ,`RT_FALSE   };
381 21 diegovalve
 
382 76 diegovalve
//LABEL_BIU1:
383
158: I = { `JGEX ,`LABEL_BIU2 ,`CREG_v ,`R1 };
384
159: I = { `RETURN ,`RT_FALSE   };
385 21 diegovalve
 
386 76 diegovalve
//LABEL_BIU2:
387
160: I = { `ADD ,`R2 ,`CREG_u ,`CREG_v };
388
161: I = { `JLEX ,`LABEL_BIU3 ,`R2 ,`R3 };
389
162: I = { `RETURN ,`RT_FALSE   };
390 21 diegovalve
 
391 76 diegovalve
//LABEL_BIU3:
392
163: I = { `JGEX ,`LABEL_BIU4 ,`CREG_t ,`CREG_LAST_t };
393
164: I = { `COPY ,`CREG_LAST_t ,`CREG_t ,`VOID };
394
165: I = { `COPY ,`CREG_LAST_u ,`CREG_u ,`VOID };
395
166: I = { `COPY ,`CREG_LAST_v ,`CREG_v ,`VOID };
396
167: I = { `COPY ,`CREG_E1_LAST ,`CREG_E1 ,`VOID };
397
168: I = { `COPY ,`CREG_E2_LAST ,`CREG_E2 ,`VOID };
398
169: I = { `COPY ,`CREG_UV0_LAST ,`CREG_UV0 ,`VOID };
399
170: I = { `COPY ,`CREG_UV1_LAST ,`CREG_UV1 ,`VOID };
400
171: I = { `COPY ,`CREG_UV2_LAST ,`CREG_UV2 ,`VOID };
401
172: I = { `COPY ,`CREG_TRI_DIFFUSE_LAST ,`CREG_TRI_DIFFUSE ,`VOID };
402
//LABEL_BIU4:
403
173: I = { `RETURN ,`RT_TRUE   };
404 21 diegovalve
 
405
 
406
//-------------------------------------------------------------------------
407
//Calculate the adress of the texure coordiantes.
408
 
409 76 diegovalve
//TAG_TCC_UCODE_ADDRESS:
410 21 diegovalve
//Do this calculation only if this triangle is the one closest to the camera
411 76 diegovalve
174: I = { `JGX ,`LABEL_TCC_EXIT ,`CREG_t ,`CREG_LAST_t };
412 21 diegovalve
 
413
//First get the UV coodrinates and store in R1
414 76 diegovalve
//R1x: u_coordinate = U0 + last_u * (U1 - U0) + last_v * (U2 - U0)
415
//R1y: v_coordinate = V0 + last_u * (V1 - V0) + last_v * (V2 - V0)
416 21 diegovalve
//R1z: 0
417
 
418 76 diegovalve
175: I = { `SUB ,`R1 ,`CREG_UV1_LAST ,`CREG_UV0_LAST };
419
176: I = { `SUB ,`R2 ,`CREG_UV2_LAST ,`CREG_UV0_LAST };
420
177: I = { `MUL ,`R1 ,`CREG_LAST_u ,`R1 };
421
178: I = { `MUL ,`R2 ,`CREG_LAST_v ,`R2 };
422
179: I = { `ADD ,`R1 ,`R1 ,`R2 };
423
180: I = { `ADD ,`R1 ,`R1 ,`CREG_UV0_LAST };
424 21 diegovalve
 
425 76 diegovalve
//R7x : fu = (u_coordinate) * gTexture.mWidth
426
//R7y : fv = (v_coordinate) * gTexture.mWidth
427 21 diegovalve
//R7z : 0
428 76 diegovalve
181: I = { `MUL ,`R7 ,`R1 ,`CREG_TEXTURE_SIZE };
429 21 diegovalve
 
430 76 diegovalve
//R1x: u1 = ((int)fu) % gTexture.mWidth
431
//R1y: v1 = ((int)fv) % gTexture.mHeight
432 21 diegovalve
//R1z: 0
433 76 diegovalve
//R2x: u2 = (u1 + 1 ) % gTexture.mWidth
434
//R2y: v2 = (v2 + 1 ) % gTexture.mHeight
435 21 diegovalve
//R2z: 0
436
// Notice MOD2 only operates over
437 76 diegovalve
// numbers that are power of 2 also notice that the
438 21 diegovalve
// textures are assumed to be squares!
439
//x % 2^n == x & (2^n - 1).
440
 
441 76 diegovalve
182: I = { `MOD ,`R1 ,`R7 ,`CREG_TEXTURE_SIZE };
442
183: I = { `INC ,`R2 ,`R1 ,`VOID };
443
184: I = { `MOD ,`R2 ,`R2 ,`CREG_TEXTURE_SIZE };
444 21 diegovalve
 
445 76 diegovalve
//Cool now we should store the values in the appropiate registers
446 21 diegovalve
//OREG_TEX_COORD1.x = u1 + v1 * gTexture.mWidth
447
//OREG_TEX_COORD1.y = u2 + v1 * gTexture.mWidth
448
//OREG_TEX_COORD1.z = 0
449
//OREG_TEX_COORD2.x = u1 + v2 * gTexture.mWidth
450
//OREG_TEX_COORD2.y = u2 + v2 * gTexture.mWidth
451
//OREG_TEX_COORD1.z = 0
452
 
453 76 diegovalve
//R1= [u1 v1 0]
454
//R2= [u2 v2 0]
455 21 diegovalve
 
456 76 diegovalve
//R2 = [v2 u2 0]
457
185: I = { `SWIZZLE3D ,`R2 ,`SWIZZLE_YXZ  };
458 21 diegovalve
 
459
//R3 = [v2 v1 0]
460 76 diegovalve
186: I = { `XCHANGEX ,`R3 ,`R1 ,`R2 };
461 21 diegovalve
 
462
 
463 76 diegovalve
//R4 = [u1 u2 0]
464
187: I = { `XCHANGEX ,`R4 ,`R2 ,`R1 };
465 21 diegovalve
 
466 76 diegovalve
//R2 = [v2*H v1*H 0]
467
188: I = { `UNSCALE ,`R9 ,`R3 ,`VOID };
468
189: I = { `UNSCALE ,`R8 ,`CREG_TEXTURE_SIZE ,`VOID };
469
190: I = { `IMUL ,`R2 ,`R9 ,`R8 };
470 21 diegovalve
 
471 76 diegovalve
//OREG_TEX_COORD1 = [u1 + v2*H u2 + v1*H 0]
472 21 diegovalve
//R4 = FixedToIinteger(R4)
473 76 diegovalve
191: I = { `UNSCALE ,`R4 ,`R4 ,`VOID };
474
192: I = { `ADD ,`R12 ,`R2 ,`R4 };
475
193: I = { `SETX ,`R5 ,32'h3  };
476
194: I = { `SETY ,`R5 ,32'h3  };
477
195: I = { `SETZ ,`R5 ,32'h3  };
478 21 diegovalve
//Multiply by 3 (the pitch)
479 76 diegovalve
196: I = { `IMUL ,`OREG_TEX_COORD1 ,`R12 ,`R5 };
480 21 diegovalve
 
481
//R4 = [u2 u1 0]
482 76 diegovalve
197: I = { `SWIZZLE3D ,`R4 ,`SWIZZLE_YXZ  };
483 21 diegovalve
 
484
 
485 76 diegovalve
//OREG_TEX_COORD2 [u2 + v2*H u1 + v1*H 0]
486
198: I = { `ADD ,`R12 ,`R2 ,`R4 };
487 21 diegovalve
//Multiply by 3 (the pitch)
488 76 diegovalve
199: I = { `IMUL ,`OREG_TEX_COORD2 ,`R12 ,`R5 };
489 21 diegovalve
 
490
 
491
//Cool now get the weights
492
 
493 76 diegovalve
//w1 = (1 - fracu) * (1 - fracv)
494
//w2 = fracu * (1 - fracv)
495
//w3 = (1 - fracu) * fracv
496
//w4 = fracu *  fracv
497 21 diegovalve
 
498
//R4x: fracu 
499
//R4y: fracv 
500
//R4z: 0
501 76 diegovalve
200: I = { `FRAC ,`R4 ,`R7 ,`VOID };
502 21 diegovalve
 
503
//R5x: fracv 
504
//R5y: fracu 
505
//R5z: 0 
506 76 diegovalve
201: I = { `COPY ,`R5 ,`R4 ,`VOID };
507
202: I = { `SWIZZLE3D ,`R5 ,`SWIZZLE_YXZ  };
508 21 diegovalve
 
509
 
510
//R5x: 1 - fracv 
511
//R5y: 1 - fracu 
512
//R5y: 1
513 76 diegovalve
203: I = { `NEG ,`R5 ,`R5 ,`VOID };
514
204: I = { `INC ,`R5 ,`R5 ,`VOID };
515 21 diegovalve
 
516
//R5x: 1 - fracv 
517
//R5y: 1 - fracu 
518
//R5y: (1 - fracv)(1 - fracu) 
519 76 diegovalve
205: I = { `MULP ,`CREG_TEXWEIGHT1 ,`R5 ,`VOID };
520 21 diegovalve
 
521 74 diegovalve
//CREG_TEXWEIGHT1.x = (1 - fracv)(1 - fracu) 
522
//CREG_TEXWEIGHT1.y = (1 - fracv)(1 - fracu) 
523
//CREG_TEXWEIGHT1.z = (1 - fracv)(1 - fracu) 
524 76 diegovalve
206: I = { `SWIZZLE3D ,`CREG_TEXWEIGHT1 ,`SWIZZLE_ZZZ  };
525 21 diegovalve
 
526
 
527
//R6x: w2: fracu * (1 - fracv )
528
//R6y: w3: fracv * (1 - fracu )
529
//R6z: 0
530 76 diegovalve
207: I = { `MUL ,`R6 ,`R4 ,`R5 };
531 21 diegovalve
 
532 74 diegovalve
//CREG_TEXWEIGHT2.x = fracu * (1 - fracv )
533
//CREG_TEXWEIGHT2.y = fracu * (1 - fracv )
534
//CREG_TEXWEIGHT2.z = fracu * (1 - fracv )
535 76 diegovalve
208: I = { `COPY ,`CREG_TEXWEIGHT2 ,`R6 ,`VOID };
536
209: I = { `SWIZZLE3D ,`CREG_TEXWEIGHT2 ,`SWIZZLE_XXX  };
537 21 diegovalve
 
538 74 diegovalve
//CREG_TEXWEIGHT3.x = fracv * (1 - fracu )
539
//CREG_TEXWEIGHT3.y = fracv * (1 - fracu )
540
//CREG_TEXWEIGHT3.z = fracv * (1 - fracu )
541 76 diegovalve
210: I = { `COPY ,`CREG_TEXWEIGHT3 ,`R6 ,`VOID };
542
211: I = { `SWIZZLE3D ,`CREG_TEXWEIGHT3 ,`SWIZZLE_YYY  };
543 21 diegovalve
 
544
 
545
//R4x: fracu
546
//R4y: fracv
547
//R4z: fracu * fracv
548 76 diegovalve
212: I = { `MULP ,`R4 ,`R4 ,`VOID };
549 21 diegovalve
 
550 74 diegovalve
//CREG_TEXWEIGHT4.x = fracv * fracu 
551
//CREG_TEXWEIGHT4.y = fracv * fracu 
552
//CREG_TEXWEIGHT4.z = fracv * fracu 
553 76 diegovalve
213: I = { `COPY ,`CREG_TEXWEIGHT4 ,`R4 ,`VOID };
554
214: I = { `SWIZZLE3D ,`CREG_TEXWEIGHT4 ,`SWIZZLE_ZZZ  };
555 21 diegovalve
 
556
 
557 76 diegovalve
//LABEL_TCC_EXIT:
558
215: I = { `RETURN ,`RT_TRUE   };
559 21 diegovalve
 
560
 
561
//-------------------------------------------------------------------------
562 76 diegovalve
//TAG_PSU_UCODE_ADRESS:
563 21 diegovalve
//Pixel Shader #1
564
//This pixel shader has diffuse light but no textures
565
 
566
 
567 76 diegovalve
216: I = { `CROSS ,`R1 ,`CREG_E1_LAST ,`CREG_E2_LAST };
568
217: I = { `MAG ,`R2 ,`R1 ,`VOID };
569
218: I = { `DIV ,`R1 ,`R1 ,`R2 };
570
219: I = { `MUL ,`R2 ,`CREG_RAY_DIRECTION ,`CREG_LAST_t };
571
220: I = { `ADD ,`R2 ,`R2 ,`CREG_CAMERA_POSITION };
572
221: I = { `SUB ,`R2 ,`CURRENT_LIGHT_POS ,`R2 };
573
222: I = { `MAG ,`R3 ,`R2 ,`VOID };
574
223: I = { `DIV ,`R2 ,`R2 ,`R3 };
575
224: I = { `DOT ,`R3 ,`R2 ,`R1 };
576
225: I = { `MUL ,`CREG_COLOR_ACC ,`CREG_TRI_DIFFUSE_LAST ,`CURRENT_LIGHT_DIFFUSE };
577
226: I = { `MUL ,`CREG_COLOR_ACC ,`CREG_COLOR_ACC ,`R3 };
578
227: I = { `COPY ,`CREG_TEXTURE_COLOR ,`CREG_COLOR_ACC ,`VOID };
579
228: I = { `NOP ,`RT_FALSE   }; //I = { `JLEX ,`LABEL_DEBUG_PRINT_REGS ,`CREG_COLOR_ACC ,`R3 }; 
580
229: I = { `NOP ,`RT_FALSE   }; //I = { `JMP ,`LABEL_DEBUG_PRINT_REGS ,`VOID ,`VOID }; 
581
230: I = { `NOP ,`RT_FALSE   };
582
231: I = { `RETURN ,`RT_TRUE   };
583 21 diegovalve
 
584
//-------------------------------------------------------------------------
585
//Pixel Shader #2
586 76 diegovalve
//TAG_PSU_UCODE_ADRESS2:
587 21 diegovalve
 
588
 
589
//This Pixel Shader has no light but it does texturinng 
590
//with bi-linear interpolation
591
 
592 76 diegovalve
//CColor TextureColor
593
//TextureColor.R = c1.R * w1 + c2.R * w2 + c3.R * w3 + c4.R * w4
594
//TextureColor.G = c1.G * w1 + c2.G * w2 + c3.G * w3 + c4.G * w4
595
//TextureColor.B = c1.B * w1 + c2.B * w2 + c3.B * w3 + c4.B * w4
596 21 diegovalve
 
597 76 diegovalve
232: I = { `MUL ,`R1 ,`CREG_TEX_COLOR5 ,`CREG_TEXWEIGHT1 };
598
233: I = { `MUL ,`R2 ,`CREG_TEX_COLOR2 ,`CREG_TEXWEIGHT2 };
599
234: I = { `MUL ,`R3 ,`CREG_TEX_COLOR1 ,`CREG_TEXWEIGHT3 };
600
235: I = { `MUL ,`R4 ,`CREG_TEX_COLOR4 ,`CREG_TEXWEIGHT4 };
601
236: I = { `ADD ,`CREG_TEXTURE_COLOR ,`R1 ,`R2 };
602
237: I = { `ADD ,`CREG_TEXTURE_COLOR ,`CREG_TEXTURE_COLOR ,`R3 };
603
238: I = { `ADD ,`CREG_TEXTURE_COLOR ,`CREG_TEXTURE_COLOR ,`R4 };
604
239: I = { `RETURN ,`RT_TRUE   };
605 21 diegovalve
 
606
 
607 76 diegovalve
240: I = { `RETURN ,`RT_TRUE   };
608
 
609
//-------------------------------------------------------------------------
610
//Default User constants
611
//TAG_USERCONSTANTS:
612
 
613
241: I = { `NOP ,`RT_FALSE   };
614
242: I = { `RETURN ,`RT_TRUE   };
615
 
616
//TAG_PIXELSHADER:
617
//Default Pixel Shader (just outputs texture)
618
243: I = { `COPY ,`OREG_PIXEL_COLOR,`CREG_TEXTURE_COLOR,`VOID   };
619
244: I = { `RETURN ,`RT_TRUE   };
620 21 diegovalve
 
621
//-------------------------------------------------------------------------             
622
 
623
 
624
                        default:
625
                        begin
626
 
627
                        `ifdef DEBUG
628
                        $display("Error: Reached undefined address in instruction Memory: %d!!!!",Address);
629 60 diegovalve
                //      $stop();
630 21 diegovalve
                        `endif
631 60 diegovalve
                        I =  {`INSTRUCTION_OP_LENGTH'hFF,16'hFFFF,32'hFFFFFFFF};
632 21 diegovalve
                        end
633
                        endcase
634
        end
635
endmodule
636
//--------------------------------------------------------

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.