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

Subversion Repositories theia_gpu

[/] [theia_gpu/] [trunk/] [rtl/] [Module_ROM.v] - Blame information for rev 212

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

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

powered by: WebSVN 2.1.0

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