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

Subversion Repositories jart

[/] [jart/] [branches/] [ver0branch/] [powerGrid.vhd] - Blame information for rev 81

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

Line No. Rev Author Line
1 16 jguarin200
-- Author : Julian Andres Guarin Reyes.
2
-- Project : JART, Just Another Ray Tracer.
3
-- email : jguarin2002 at gmail.com, j.guarin at javeriana.edu.co
4
 
5
-- This code was entirely written by Julian Andres Guarin Reyes.
6
-- The following code is licensed under GNU Public License
7
-- http://www.gnu.org/licenses/gpl-3.0.txt.
8
 
9
 -- This file is part of JART (Just Another Ray Tracer).
10
 
11
    -- JART (Just Another Ray Tracer) is free software: you can redistribute it and/or modify
12
    -- it under the terms of the GNU General Public License as published by
13
    -- the Free Software Foundation, either version 3 of the License, or
14
    -- (at your option) any later version.
15
 
16
    -- JART (Just Another Ray Tracer) 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 JART (Just Another Ray Tracer).  If not, see <http://www.gnu.org/licenses/>.
23
 
24
-- 16X50M Intersection Tests    
25
 
26
library ieee;
27
use ieee.std_logic_1164.all;
28
 
29 64 jguarin200
 
30
 
31
 
32 16 jguarin200
package powerGrid is
33 64 jguarin200
 
34
        -- R2 for size and width
35 69 jguarin200
        type SIZE_WIDTH is array (integer,integer) of integer;
36
        type DUPLA is array (0 to 2,1 downto 0) of integer;
37 64 jguarin200
 
38
        -- Tuple for widths
39
        type WARRAY is array (0 to 2) of integer;
40
 
41
        -- Index 
42 69 jguarin200
        constant SZINDEX: integer :=0;   -- Size Description Index.
43
        constant WDINDEX: integer :=1;  -- Width description Index.
44 64 jguarin200
 
45
        -- Register file for spheres.
46
        -- OP1 : One sphere output per clock.
47
        -- OP2 : Two sphere output per clock.
48
        -- OP4 : Four sphere output per clock.
49
        constant OP4            : integer := 2;
50
        constant OP2            : integer := 1;
51
        constant OP1            : integer := 0;
52
 
53
        constant SZALFA         : integer := 1;
54
        constant SZBETA         : integer := 2;
55
 
56 69 jguarin200
        constant DBUSW          : integer := 64;
57 64 jguarin200
        constant BUSW           : integer := 32;
58
        constant HBUSW          : integer := 18;
59
 
60 69 jguarin200
        -- Size and Width depending upon the number of spheres to push out in one clock (OP1= One sphere, OP2 = Two spheres, OP4= Four spheres).
61 64 jguarin200
        constant REGSZADD       : WARRAY := (12,11,10);
62
        constant CIDSZADD       : DUPLA := ((1,0),(2,1),(4,2));
63
 
64 80 jguarin200
        -- Unitary Ray Set. 
65
        -- Y component generation.
66
        component yu
67
                generic (
68
 
69
                TOP : integer := 1024;          -- Define the max counting number.. the number must be expressed as 2 power, cause the range of counting is going to be defined as top-1 downto top/2.
70
                -- However this is going to be by now, cause in the future the ray generation will GO on for higher resolution images , and perhaps it would be required a more extended range for the yu component.
71
                SCREENW : integer := 320
72
                );
73
                port (
74
                clk,rst,ena             : in std_logic;
75
                lineDone                : out std_logic;
76
                ypos                    : out integer range TOP/2 to TOP-1
77
                );
78
        end component;
79
        -- Z and X component generation
80
        component zu
81
                generic
82
                (
83
                VALSTART                : integer := 9
84
                );
85
                port (
86
 
87
                clk,rst,ena     : in std_logic; -- The usual control signals
88
                clr                             : in std_logic;
89
                zpos                    : out integer range -1024 to 1023;
90
                zneg                    : out integer range -1024 to 1023
91
                );
92
        end component;
93 64 jguarin200
 
94
 
95
        -- Register blocks.....
96
 
97
        -- 8 x 512 x 32 
98
        component bt81
99
                port
100
                (
101
                address         : in std_logic_vector (11 downto 0);
102
                clken           : in std_logic ;
103
                clock           : in std_logic ;
104
                data            : in std_logic_vector (31 downto 0);
105
                wren            : in std_logic ;
106
                q                       : out std_logic_vector (31 downto 0)
107
                );
108
        end component;
109
 
110
        -- 4 x 512 x 32 
111
        component bt41
112
                port
113
                (
114
                address         : in std_logic_vector (10 downto 0);
115
                clken           : in std_logic ;
116
                clock           : in std_logic ;
117
                data            : in std_logic_vector (31 downto 0);
118
                wren            : in std_logic ;
119
                q                       : out std_logic_vector (31 downto 0)
120
                );
121
        end component;
122
 
123
        -- 2 x 512 x 32 
124
        component bt21
125
                port
126
                (
127
                address         : in std_logic_vector (9 downto 0);
128
                clken           : in std_logic ;
129
                clock           : in std_logic ;
130
                data            : in std_logic_vector (31 downto 0);
131
                wren            : in std_logic ;
132
                q                       : out std_logic_vector (31 downto 0)
133
                );
134
        end component;
135
 
136
        -- 1 x 512 x 32 
137 66 jguarin200
        component bt11
138 64 jguarin200
                port
139
                (
140
                address         : in std_logic_vector (8 downto 0);
141
                clken           : in std_logic ;
142
                clock           : in std_logic ;
143
                data            : in std_logic_vector (31 downto 0);
144
                wren            : in std_logic ;
145
                q                       : out std_logic_vector (31 downto 0)
146
                );
147
        end component;
148
 
149 67 jguarin200
        -- 8 x 512 x 18 
150 64 jguarin200
        component bt84
151
                port
152
                (
153
                address         : in std_logic_vector (11 downto 0);
154
                clken           : in std_logic ;
155
                clock           : in std_logic ;
156
                data            : in std_logic_vector (17 downto 0);
157
                wren            : in std_logic ;
158
                q                       : out std_logic_vector (17 downto 0)
159
                );
160
        end component;
161
 
162 66 jguarin200
        -- 4 x 512 x 18 
163 64 jguarin200
        component bt44
164
                port
165
                (
166
                address         : in std_logic_vector (10 downto 0);
167
                clken           : in std_logic ;
168
                clock           : in std_logic ;
169
                data            : in std_logic_vector (17 downto 0);
170
                wren            : in std_logic ;
171
                q                       : out std_logic_vector (17 downto 0)
172
                );
173
        end component;
174
 
175 66 jguarin200
        -- 2 x 512 x 18 
176 64 jguarin200
        component bt24
177
                port
178
                (
179
                address         : in std_logic_vector (9 downto 0);
180
                clken           : in std_logic ;
181
                clock           : in std_logic ;
182
                data            : in std_logic_vector (17 downto 0);
183
                wren            : in std_logic ;
184
                q                       : out std_logic_vector (17 downto 0)
185
                );
186
        end component;
187
 
188
        -- 1 x 512 x 18 
189
        component bt14
190
                port
191
                (
192
                address         : in std_logic_vector (8 downto 0);
193
                clken           : in std_logic ;
194
                clock           : in std_logic ;
195
                data            : in std_logic_vector (17 downto 0);
196
                wren            : in std_logic ;
197
                q                       : out std_logic_vector (17 downto 0)
198
                );
199
        end component;
200
 
201
        -- Register type 1 .
202
        component r1
203
                port (
204
 
205
 
206
                        clk, ena: in std_logic; -- The usual control signals.
207
 
208
                        wen             : in std_logic_vector   (3 downto 0);
209
                        add             : in std_logic_vector   (8 downto 0);
210
                        datain  : in std_logic_vector   (BUSW-1 downto 0);-- incoming data from 32 bits width bus.
211
                        Vx              : out std_logic_vector  (HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
212
                        Vy              : out std_logic_vector  (HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
213
                        Vz              : out std_logic_vector  (HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
214
                        K               : out std_logic_vector  (BUSW-1 downto 0)
215
                );
216
        end component;
217
        -- Register type 2 .
218
        component r2
219
                port (
220
 
221
 
222
                        clk, ena: in std_logic; -- The usual control signals.
223
 
224
                        wen             : in std_logic_vector   (3 downto 0);
225
                        add             : in std_logic_vector   (9 downto 0);
226
                        datain  : in std_logic_vector   (BUSW-1 downto 0);-- incoming data from 32 bits width bus.
227
                        Vx              : out std_logic_vector  (HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
228
                        Vy              : out std_logic_vector  (HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
229
                        Vz              : out std_logic_vector  (HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
230
                        K               : out std_logic_vector  (BUSW-1 downto 0)
231
                );
232
        end component;
233
        -- Register type 4
234
        component r4
235
                port (
236
 
237
 
238
                        clk, ena: in std_logic; -- The usual control signals.
239
 
240
                        wen             : in std_logic_vector   (3 downto 0);
241
                        add             : in std_logic_vector   (10 downto 0);
242
                        datain  : in std_logic_vector   (BUSW-1 downto 0);-- incoming data from 32 bits width bus.
243
                        Vx              : out std_logic_vector  (HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
244
                        Vy              : out std_logic_vector  (HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
245
                        Vz              : out std_logic_vector  (HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
246
                        K               : out std_logic_vector  (BUSW-1 downto 0)
247
                );
248
        end component;-- Register type 8.
249
        component r8
250
                port (
251
 
252
 
253
                        clk, ena: in std_logic; -- The usual control signals.
254
 
255
                        wen             : in std_logic_vector   (3 downto 0);
256
                        add             : in std_logic_vector   (11 downto 0);
257
                        datain  : in std_logic_vector   (BUSW-1 downto 0);-- incoming data from 32 bits width bus.
258
                        Vx              : out std_logic_vector  (HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
259
                        Vy              : out std_logic_vector  (HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
260
                        Vz              : out std_logic_vector  (HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
261
                        K               : out std_logic_vector  (BUSW-1 downto 0)
262
                );
263
        end component;
264
 
265
 
266
        -- Register Option mode 1
267
        component rop1
268
                generic (
269
                        SZMODE  : integer       := SZBETA       -- By default use the 50% of the max memory for sphere register block.
270
                );
271
                port (
272
 
273
 
274
                        clk, ena: in std_logic; -- The usual control signals.
275
                        wen             : in std_logic_vector   (3 downto 0);
276
                        add             : in std_logic_vector   (REGSZADD(OP1)-SZMODE downto 0);
277
                        datain  : in std_logic_vector   (BUSW-1 downto 0);-- incoming data from 32 bits width bus.
278
                        Vx              : out std_logic_vector  (2*HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
279
                        Vy              : out std_logic_vector  (2*HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
280
                        Vz              : out std_logic_vector  (2*HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
281
                        K               : out std_logic_vector  (2*BUSW-1 downto 0)
282
                );
283
 
284
        end component;
285
 
286
        -- Register Option mode 2
287
        component rop2
288
                generic (
289
                        SZMODE  : integer       := SZBETA       -- By default use the 50% of the max memory for sphere register block.
290
                );
291
                port (
292
 
293
 
294
                        clk, ena: in std_logic; -- The usual control signals.
295
                        wen             : in std_logic_vector   (7 downto 0);
296
                        add             : in std_logic_vector   (REGSZADD(OP2)-SZMODE downto 0);
297
                        datain  : in std_logic_vector   (BUSW-1 downto 0);-- incoming data from 32 bits width bus.
298
                        Vx              : out std_logic_vector  (2*HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
299
                        Vy              : out std_logic_vector  (2*HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
300
                        Vz              : out std_logic_vector  (2*HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
301
                        K               : out std_logic_vector  (2*BUSW-1 downto 0)
302
                );
303
 
304
        end component;
305
 
306
        -- Register Option mode 2
307
        component rop4
308
                generic (
309
                        SZMODE  : integer       := SZBETA       -- By default use the 50% of the max memory for sphere register block.
310
                );
311
                port (
312
 
313
 
314
                        clk, ena: in std_logic; -- The usual control signals.
315
                        wen             : in std_logic_vector   (15 downto 0);
316
                        add             : in std_logic_vector   (REGSZADD(OP4)-SZMODE downto 0);
317
                        datain  : in std_logic_vector   (BUSW-1 downto 0);-- incoming data from 32 bits width bus.
318
                        Vx              : out std_logic_vector  (4*HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
319
                        Vy              : out std_logic_vector  (4*HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
320
                        Vz              : out std_logic_vector  (4*HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
321
                        K               : out std_logic_vector  (4*BUSW-1 downto 0)
322
                );
323
 
324
        end component;
325
 
326
 
327
        -- Sphere Register Block
328
        component sphereRegisterBlock
329
                generic (
330
 
331
                        OPMODE  : integer := OP4;               -- By default push out 4 spheres at same time.
332 69 jguarin200
                        SZMODE  : integer := SZBETA             -- By default the max sphere numbers is 2048, but could be 4096 with SZALFA.
333
 
334
 
335 64 jguarin200
                );
336
                port (
337
 
338
 
339
                        clk, ena: in std_logic; -- The usual control signals.
340
 
341 69 jguarin200
                        wen             : in std_logic_vector   (CIDSZADD(OP4,SZINDEX)-1 downto 0);      -- Write enable signals
342 64 jguarin200
                        add             : in std_logic_vector   (REGSZADD(OPMODE)-SZMODE  downto 0);             -- Address bus
343
 
344
                        datain  : in std_logic_vector   (BUSW-1 downto 0);       -- incoming data from 32 bits width bus.
345
 
346
                        Vx              : out std_logic_vector  (OPMODE*HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
347
                        Vy              : out std_logic_vector  (OPMODE*HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
348
                        Vz              : out std_logic_vector  (OPMODE*HBUSW-1 downto 0); -- outcoming data to 54 bit width bus multiplexer selector and intersection test cube.
349
                        K               : out std_logic_vector  (OPMODE*BUSW-1 downto 0)
350
 
351
                );
352
 
353 69 jguarin200
        end component;
354 64 jguarin200
 
355 58 jguarin200
        -- A scan flip flop, aka selectable input ff.
356
        component scanFF
357
                generic (
358
                W       : integer := 8);
359
                port    (
360 61 jguarin200
                clk,rst,ena,sel         : in std_logic; -- The usual  control signals
361 58 jguarin200
 
362 61 jguarin200
                d0,d1   : in std_logic_vector (W-1 downto 0);    -- The two operands.
363
                q               : out std_logic_vector (W-1 downto 0)    -- The selected data.
364 58 jguarin200
 
365
                );
366
        end component;
367 33 jguarin200
        --A one stage pipe (1 Clk) a+b+c with w width bits in input as well as output.
368
        --As a fixed signed addtion we have:
369
        -- A(B,C) ====> B+C SIGNED BITS FORMAT : 1 bit for sign, B bits for integer part, C bits for decimal part. (FORMAT)
370
        -- A(15,20)*A(15,20) = A(15,20). (This component format)
371
 
372 22 jguarin200
        component p1ax
373 33 jguarin200
                generic (
374
                -- The width of the operands and result.
375
                W               : integer := 36 );
376
                port    (
377
                -- The usual control signals.
378
                clk             :        in std_logic;
379
                rst             :        in std_logic;
380 61 jguarin200
                enable  :        in std_logic;
381 33 jguarin200
 
382
                -- Operand A.
383
                dataa           :        in std_logic_vector(W-1 downto 0);
384
                -- Operand B.
385
                datab           :        in std_logic_vector(W-1 downto 0);
386
                -- Operand C
387
                datac           :        in std_logic_vector(W-1 downto 0);
388
                -- Result.
389
                result          :        out std_logic_vector(W-1 downto 0)
390 22 jguarin200
                );
391
        end component;
392
 
393
        -- A 1 stage pipe 18x18 multiplier. On Cycle III devices is a M-R (Multiplier, Register). (Should be generated using a synthesis tool....).
394 33 jguarin200
        -- As a fixed signed multiplication we have :
395
        -- A(B,C) ====> B+C SIGNED BITS FORMAT : 1 bit for sign, B bits for integer part, C bits for decimal part. (FORMAT)
396
        -- A(7,10)*A(7,10) = A(15,20). (This component format)
397
 
398 22 jguarin200
        component p1m18
399
                port    (
400 33 jguarin200
                -- Asynchronous clear signal.
401
                aclr            : in std_logic ;
402
                -- The usual control signals.
403
                clken           : in std_logic ;
404
                clock           : in std_logic ;
405
 
406
                -- Factor A.
407
                dataa           : in std_logic_vector (17 downto 0);
408
                -- Factor B.
409
                datab           : in std_logic_vector (17 downto 0);
410
                -- Product.
411
                result          : out std_logic_vector (35 downto 0)
412 22 jguarin200
                );
413
        end component;
414
 
415 33 jguarin200
        -- Signed "less than". dataa < datab
416 16 jguarin200
        component sl32
417
                port    (
418 33 jguarin200
 
419
                dataa   : in std_logic_vector (31 downto 0);
420
                datab   : in std_logic_vector (31 downto 0);
421
                AlB             : out std_logic
422
 
423 16 jguarin200
                );
424
                end component;
425
 
426 33 jguarin200
        -- Signed "greater than". dataa >= datab.
427 16 jguarin200
        component sge32
428
                port    (
429 33 jguarin200
 
430
                dataa   : in std_logic_vector (31 downto 0);
431
                datab   : in std_logic_vector (31 downto 0);
432
                AgeB    : out std_logic
433
 
434 16 jguarin200
                );
435
                end component;
436
 
437
 
438 22 jguarin200
        -- Dot Product Calculation Cell. 
439
        -- A 4 side cell along with an upper side. 
440
        -- V input flows through V output using a data flipflop, so turning V output in the next cell on the next row V Input. V input also flows upwards into the dotproduct 3 stage pipeline. 
441
        -- D input flows through D output using a data flipflop, so turning D output in the next column cell. D input also flows upwards into the dotproduct 3 stage. 
442 16 jguarin200
        component dotCell
443 40 jguarin200
                generic (
444
 
445
                -- Register V?, by default register the pass of V to the next grid. This should be NO when using a single grid cube or in the last grid of the grid array.
446
                RV      : string := "yes";
447 33 jguarin200
                -- Actual Level Width
448 40 jguarin200
                W0      : integer := 18;
449 33 jguarin200
                -- Next Level Width
450 40 jguarin200
                W1      : integer := 32);
451 33 jguarin200
 
452 16 jguarin200
                port    (
453 33 jguarin200
                --The usual control signals
454
                clk                     : in std_logic;
455
                rst                     : in std_logic;
456 16 jguarin200
 
457 33 jguarin200
                -- This bit controls when the sphere center goes to the next row.
458
                nxtSphere       : in std_logic;
459
                -- This bit controls when the ray goes to the next column.
460
                nxtRay          : in std_logic;
461 22 jguarin200
 
462 33 jguarin200
                -- First Side.
463 40 jguarin200
                vxInput         : in std_logic_vector(W0-1 downto 0);
464
                vyInput         : in std_logic_vector(W0-1 downto 0);
465
                vzInput         : in std_logic_vector(W0-1 downto 0);
466 16 jguarin200
 
467 33 jguarin200
                -- Second Side (Opposite to the first one)
468 40 jguarin200
                vxOutput        : out std_logic_vector(W0-1 downto 0);
469
                vyOutput        : out std_logic_vector(W0-1 downto 0);
470
                vzOutput        : out std_logic_vector(W0-1 downto 0);
471 16 jguarin200
 
472 33 jguarin200
                -- Third Side (Perpendicular to the first and second ones)
473 40 jguarin200
                dxInput         : in std_logic_vector(W0-1 downto 0);
474
                dyInput         : in std_logic_vector(W0-1 downto 0);
475
                dzInput         : in std_logic_vector(W0-1 downto 0);
476 16 jguarin200
 
477 33 jguarin200
                --Fourth Side (Opposite to the third one)
478 64 jguarin200
                dxOutput        : out std_logic_vector(W0-1 downto 0);
479
                dyOutput        : out std_logic_vector(W0-1 downto 0);
480
                dzOutput        : out std_logic_vector(W0-1 downto 0);
481 16 jguarin200
 
482 33 jguarin200
                --Fifth Side (Going to the floor right upstairs!)
483 40 jguarin200
                vdOutput        : out std_logic_vector(W1-1 downto 0) -- Dot product.
484 16 jguarin200
 
485 22 jguarin200
                );
486 16 jguarin200
        end component;
487
 
488
        -- K discriminant comparison.
489 33 jguarin200
        -- The vdinput value is the calculation of the ray and the column's sphere dot product. This value should be compared to a sphere constant in order to find out whether the ray intersects
490
        -- or not the sphere. If vdinput is grather or equal than kinput there's an intersection or else when vdinput is less than kinput. If there's an intersection the block sets vdinput at vdoutput,
491
        -- whenever there's no intersection the output is asserted with the maximum positive distance in 32 bits : 0x7fffffff.
492 16 jguarin200
        component kComparisonCell
493 40 jguarin200
                generic (
494
                RK      : string        := "yes";
495
                W1      : integer       := 32
496 16 jguarin200
                );
497 40 jguarin200
                port (
498
                clk,rst         : in std_logic;
499
                scanOut         : in std_logic; -- This signals overrides the 'signed greater or equal than' internal function and allows vdinput to flow upwards.
500
                nxtSphere       : in std_logic; -- Controls when the sphere goes to the next Row. 
501
                pipeOn          : in std_logic; -- Enables / Disable the upwarding flow.
502
                kinput          : in std_logic_vector (W1-1 downto 0);
503
                koutputhor      : out std_logic_vector (W1-1 downto 0);
504
                koutputver      : out std_logic_vector (W1-1 downto 0);  -- K input  flowing to the next floor upstairs (but waits one clock). 
505
                vdinput         : in std_logic_vector (W1-1 downto 0);   -- V.D input.
506
                vdoutput        : out std_logic_vector (W1-1 downto 0)   -- Selected dot product.
507
                );
508 22 jguarin200
        end component;
509 33 jguarin200
        -- Minimun distance Comparison.
510
        -- The reference value, refvd, is the ray minimal intersection distance calculated in the moment of the comparison. 
511
        -- The column value, colvd, is the column sphere and ray intersection distance (if any or else the maximum distance is asserted).
512
 
513
 
514
        component dComparisonCell
515
                generic (
516
                -- V.D, minDistance and selectD Width 
517 40 jguarin200
                W1              : integer := 32;
518 33 jguarin200
                -- Column Sphere ID width. 1 = 2 columns max, 2= 4 colums max... and so on.
519 40 jguarin200
                IDW     : integer := 2;
520 33 jguarin200
                -- Column Id
521
                idCol   : integer := 0
522
                );
523
                port    (
524
                -- The usual control signals.           
525 40 jguarin200
                clk, rst, pipeOn : in std_logic;
526
 
527 61 jguarin200
 
528
                intd    : in    std_logic;
529
                intq    : out   std_logic;
530 33 jguarin200
                -- This is the reference column identification input.
531 40 jguarin200
                cIdd    : in    std_logic_vector (IDW - 1 downto 0);
532 33 jguarin200
                -- This is the result column identification output.
533 61 jguarin200
                cIdq    : out   std_logic_vector (IDW - 1 downto 0);
534
                refk    : in    std_logic_vector (W1 - 1 downto 0); -- This is the columns sphere constant
535
                colk    : in    std_logic_vector (W1 - 1 downto 0); -- This is the reference sphere constant
536
                selk    : out   std_logic_vector (W1 - 1 downto 0); -- This is the selected sphere constant              
537 33 jguarin200
                -- This is the reference projection incoming from the previous cell.
538 40 jguarin200
                refvd   : in    std_logic_vector (W1 - 1 downto 0);
539 33 jguarin200
                -- This is the sphere position over the ray traced vector projection.
540 40 jguarin200
                colvd   : in    std_logic_vector (W1 - 1 downto 0);
541 33 jguarin200
                -- This is the smallest value between refvd and colvd.
542 40 jguarin200
                selvd   : out   std_logic_vector (W1 - 1 downto 0)
543 33 jguarin200
                );
544
        end component;
545
 
546
        component floor0Row
547
                generic (
548
                -- Floor Level Width (V.D width)
549 40 jguarin200
                W1 : integer := 32;
550 33 jguarin200
                -- Vector input Width           
551 40 jguarin200
                W0 : integer := 18;
552 33 jguarin200
                -- Number of Colums
553 40 jguarin200
                C       : integer := 4
554 33 jguarin200
        );
555
        port (
556
                -- The usual control signals. nxtRay should be 0 whenever I want to stop the entire machine.
557
                clk, rst, nxtRay : in std_logic;
558 16 jguarin200
 
559 33 jguarin200
                -- Clk, Rst, the usual control signals.
560
                -- enabled, the machine is running when this input is set.
561
                -- enabled, all the counters begin again.
562 40 jguarin200
                nxtSphere : in std_logic_vector (C-1 downto 0);
563 33 jguarin200
 
564
 
565
                -- Input Values. 
566
                -- The ray input vector.
567 40 jguarin200
                iRayx: in std_logic_vector (W0 - 1 downto 0);
568
                iRayy: in std_logic_vector (W0 - 1 downto 0);
569
                iRayz: in std_logic_vector (W0 - 1 downto 0);
570 33 jguarin200
 
571
                -- The spheres x position (sphere centers) input vectors.
572 40 jguarin200
                iSphrCenterx: in std_logic_vector (C*W0 - 1 downto 0);
573 33 jguarin200
                -- The spheres y position (sphere centers) input vectors.
574 40 jguarin200
                iSphrCentery: in std_logic_vector (C*W0 - 1 downto 0);
575 33 jguarin200
                -- The spheres z position (sphere centers) input vectors.
576 40 jguarin200
                iSphrCenterz: in std_logic_vector (C*W0 - 1 downto 0);
577 33 jguarin200
                -- The spheres x position (sphere centers) output vectors.
578 40 jguarin200
                oSphrCenterx: out std_logic_vector (C*W0 - 1 downto 0);
579 33 jguarin200
                -- The spheres y positions (sphere centes) output vectors.
580 40 jguarin200
                oSphrCentery: out std_logic_vector (C*W0 - 1 downto 0);
581 33 jguarin200
                -- The spheres z positions (sphere centers) output vectors.             
582 40 jguarin200
                oSphrCenterz: out std_logic_vector (C*W0 - 1 downto 0);
583 33 jguarin200
 
584
                -- Output Values
585
                -- The ray output vector.
586 40 jguarin200
                oRayx: out std_logic_vector (W0 - 1 downto 0);
587
                oRayy: out std_logic_vector (W0 - 1 downto 0);
588
                oRayz: out std_logic_vector (W0 - 1 downto 0);
589 33 jguarin200
 
590
                -- The dot product result from each dot prod cell.
591 40 jguarin200
                vdOutput : out std_logic_vector (W1*C - 1 downto 0)
592 33 jguarin200
                );
593
        end component;
594
 
595
        -- In this level the V.D results from floor 0 are compared whether they are greater or equal than column's sphere K constants, in order to find if there's an intersection per column or not.
596
        -- When any comparison is true, meaning VD value greater or equal than K, the outgoing value to floor2 level is the same VD, if not the outgoing value is 0x7fffffff (the maximum)
597
        -- distance value.
598
 
599
        component floor1Row
600
        generic (
601
 
602
                -- Vector input Width   
603 40 jguarin200
                W1 : integer := 32;
604 33 jguarin200
                -- Number of Colums
605 40 jguarin200
                C       : integer := 4
606 33 jguarin200
        );
607
        port (
608
 
609
                -- Input Control Signals, pipe on is one when raysr going on. 
610
                clk, rst        : in std_logic;
611
                pipeOn          : in std_logic;
612
 
613
                -- Clk, Rst, the usual control signals.
614 40 jguarin200
                nxtSphere       : in std_logic_vector (C-1 downto 0);
615 33 jguarin200
 
616
                -- VD Input / Output.
617 40 jguarin200
                vdInput : in std_logic_vector (W1*C-1 downto 0);
618
                vdOutput: out std_logic_vector (W1*C-1 downto 0);
619 33 jguarin200
 
620
                -- K Input / Output.
621 40 jguarin200
                kInput  : in std_logic_vector (W1*C - 1 downto 0);
622
                kOutput : out std_logic_vector (W1*C - 1 downto 0)
623 33 jguarin200
        );
624
        end component;
625
 
626
        -- This level takes the -on the moment smalles distance-- value per ray in the extreme left, and starts making comparisons from left to right, one comparison each clock and so on, searching for the smallest V.D value in the row incomung from the floor1 level. When the ray has finished crossing throguh all the spheres in the scene, the row extreme right value will be the smallest V.D found along with an ID of the sphere intersected. This is the goal of the intersection architecture : to find out which is the closest sphere intersected by a particular ray. 
627
 
628
        component floor2Row
629
        generic (
630
                -- Vector input Width
631 40 jguarin200
                W1 : integer := 32;
632 33 jguarin200
                -- ID Column width
633 40 jguarin200
                IDW : integer := 2;
634 33 jguarin200
                -- Number of Colums
635 40 jguarin200
                C       : integer := 4
636 33 jguarin200
        );
637
        port (
638
                -- Input Control Signal
639
                -- Clk, Rst, the usual control signals.
640
                clk, rst, pipeOn: in std_logic;
641
 
642
                -- Input Values
643
                -- Reference VD, the "at the moment" smallest VD sphere ray projection value.
644 40 jguarin200
                refvd   : in std_logic_vector (W1-1 downto 0);
645 33 jguarin200
 
646
                -- The smallest VD, value found.
647 40 jguarin200
                selvd   : out std_logic_vector (W1-1 downto 0);
648 33 jguarin200
 
649
                -- The column's sphere ray projection value.
650 40 jguarin200
                colvd   : in std_logic_vector (W1*C-1 downto 0);
651 33 jguarin200
                -- The smallest VD projection value column id.
652 40 jguarin200
                colid   : out std_logic_vector (IDW-1 downto 0);
653 33 jguarin200
                -- The intersection signal (1 on intersection else 0).
654
                inter   : out std_logic
655
        );
656
        end component;
657
 
658
        component rayxsphereGrid
659
        generic (
660
                -- Width of Column identificator.
661
                IDW     : integer := 2;
662
                -- Number of Columns.
663
                C       : integer := 4;
664
                -- Input rays width.
665
                W0      : integer := 18;
666
                -- Dot products and spheres constant width
667 40 jguarin200
                W1      : integer := 32
668 33 jguarin200
 
669
                );
670
        port (
671
                -- The usual control signals.
672
                clk,rst         : in std_logic;
673
 
674
                -- Grid, rays and sphere flow through control signals.
675
                pipeOn          : in std_logic;
676
                nxtSphere       : in std_logic_vector (C-1 downto 0);
677
 
678
                -- R-F0
679
                -- Input Values. 
680
                -- The ray input vector.
681
                iRayx: in std_logic_vector (W0 - 1 downto 0);
682
                iRayy: in std_logic_vector (W0 - 1 downto 0);
683
                iRayz: in std_logic_vector (W0 - 1 downto 0);
684
                -- The spheres x position (sphere centers) input vectors.
685
                iSphrCenterx: in std_logic_vector (C*W0 - 1 downto 0);
686
                -- The spheres y position (sphere centers) input vectors.
687
                iSphrCentery: in std_logic_vector (C*W0 - 1 downto 0);
688
                -- The spheres z position (sphere centers) input vectors.
689
                iSphrCenterz: in std_logic_vector (C*W0 - 1 downto 0);
690
                -- The spheres x position (sphere centers) output vectors.
691
                oSphrCenterx: out std_logic_vector (C*W0 - 1 downto 0);
692
                -- The spheres y positions (sphere centes) output vectors.
693
                oSphrCentery: out std_logic_vector (C*W0 - 1 downto 0);
694
                -- The spheres z positions (sphere centers) output vectors.             
695
                oSphrCenterz: out std_logic_vector (C*W0 - 1 downto 0);
696
                -- Output Values
697
                -- The ray output vector.
698
                oRayx: out std_logic_vector (W0 - 1 downto 0);
699
                oRayy: out std_logic_vector (W0 - 1 downto 0);
700
                oRayz: out std_logic_vector (W0 - 1 downto 0);
701
 
702
                -- R-F1
703
                -- K Input / Output.
704
                kInput  : in std_logic_vector (C*W1 - 1 downto 0);
705 40 jguarin200
                kOutput : out std_logic_vector (C*W1 - 1 downto 0);
706 33 jguarin200
 
707
                --R-F2
708
                -- Input Values
709
                refvd   : in std_logic_vector (W1-1 downto 0);
710
                selvd   : out std_logic_vector (W1-1 downto 0);
711
                colid   : out std_logic_vector (IDW-1 downto 0);
712
                inter   : out std_logic
713
                );
714
        end component;
715
        component gridCube
716
        generic (
717
                -- Depth
718
                D       : integer := 4;
719
                -- ID width.
720
                IDW     : integer := 2;
721
                -- Number of Columns.
722
                C       : integer := 4;
723
                -- Input rays width.
724
                W0      : integer := 18;
725
                -- Dot products and spheres constant width
726 40 jguarin200
                W1      : integer := 32
727 33 jguarin200
 
728
                );
729
        port (
730
                        -- The usual control signals.
731
                clk,rst : in std_logic;
732
 
733
                -- Grid, rays and sphere flow through control signals.
734
                pipeOn                  : in std_logic;
735
                -- The same column nxtSphere signal control..... regardless the Cube Depth.
736
                nxtSphere               : in std_logic_vector (C-1 downto 0);
737
 
738
                -- R-F0
739
                -- Input Values. 
740
                -- The ray input vector. 
741
                iRayx: in std_logic_vector (D*W0 - 1 downto 0);
742
                iRayy: in std_logic_vector (D*W0 - 1 downto 0);
743
                iRayz: in std_logic_vector (D*W0 - 1 downto 0);
744
                -- The spheres x position (sphere centers) input vectors.
745
                iSphrCenterx: in std_logic_vector (C*W0 - 1 downto 0);
746
                -- The spheres y position (sphere centers) input vectors.
747
                iSphrCentery: in std_logic_vector (C*W0 - 1 downto 0);
748
                -- The spheres z position (sphere centers) input vectors.
749
                iSphrCenterz: in std_logic_vector (C*W0 - 1 downto 0);
750
                -- The spheres x position (sphere centers) output vectors.
751
                oSphrCenterx: out std_logic_vector (C*W0 - 1 downto 0);
752
                -- The spheres y positions (sphere centes) output vectors.
753
                oSphrCentery: out std_logic_vector (C*W0 - 1 downto 0);
754
                -- The spheres z positions (sphere centers) output vectors.             
755
                oSphrCenterz: out std_logic_vector (C*W0 - 1 downto 0);
756
                -- Output Values
757
                -- The ray output vector.
758
                oRayx: out std_logic_vector (D*W0 - 1 downto 0);
759
                oRayy: out std_logic_vector (D*W0 - 1 downto 0);
760
                oRayz: out std_logic_vector (D*W0 - 1 downto 0);
761
 
762
                -- R-F1
763
                -- K Input / Output.
764
                kInput  : in std_logic_vector (C*W1 - 1 downto 0);
765 40 jguarin200
                kOutput : out std_logic_vector (C*W1 - 1 downto 0);
766 33 jguarin200
 
767
                --R-F2
768
                -- Input Values
769
                refvd   : in std_logic_vector (D*W1-1 downto 0);
770
                selvd   : out std_logic_vector (D*W1-1 downto 0);
771
                colid   : out std_logic_vector (D*IDW-1 downto 0);
772
                inter   : out std_logic_vector (D-1 downto 0)
773
                );
774
        end component;
775 80 jguarin200
 
776
        function mylog2( x : in integer; s: string) return integer;
777
 
778
end powerGrid;
779
package body powerGrid is
780
        function mylog2(x: integer; s : string) return integer is
781
                variable accum : integer :=1;
782
                variable i         : integer range 0 to 32 := 1;
783
        begin
784
 
785
                while (accum<=x) loop
786
                        accum   := accum*2;
787
                        i               := i+1;
788
                end loop;
789
                if s="unsigned" then
790
                        return i-1;
791
                else
792
                        return i;
793
                end if;
794
        end;
795
 
796
end package body;

powered by: WebSVN 2.1.0

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