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

Subversion Repositories jart

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

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
package powerGrid is
30 58 jguarin200
        -- A scan flip flop, aka selectable input ff.
31
        component scanFF
32
                generic (
33
                W       : integer := 8);
34
                port    (
35 61 jguarin200
                clk,rst,ena,sel         : in std_logic; -- The usual  control signals
36 58 jguarin200
 
37 61 jguarin200
                d0,d1   : in std_logic_vector (W-1 downto 0);    -- The two operands.
38
                q               : out std_logic_vector (W-1 downto 0)    -- The selected data.
39 58 jguarin200
 
40
                );
41
        end component;
42 33 jguarin200
        --A one stage pipe (1 Clk) a+b+c with w width bits in input as well as output.
43
        --As a fixed signed addtion we have:
44
        -- A(B,C) ====> B+C SIGNED BITS FORMAT : 1 bit for sign, B bits for integer part, C bits for decimal part. (FORMAT)
45
        -- A(15,20)*A(15,20) = A(15,20). (This component format)
46
 
47 22 jguarin200
        component p1ax
48 33 jguarin200
                generic (
49
                -- The width of the operands and result.
50
                W               : integer := 36 );
51
                port    (
52
                -- The usual control signals.
53
                clk             :        in std_logic;
54
                rst             :        in std_logic;
55 61 jguarin200
                enable  :        in std_logic;
56 33 jguarin200
 
57
                -- Operand A.
58
                dataa           :        in std_logic_vector(W-1 downto 0);
59
                -- Operand B.
60
                datab           :        in std_logic_vector(W-1 downto 0);
61
                -- Operand C
62
                datac           :        in std_logic_vector(W-1 downto 0);
63
                -- Result.
64
                result          :        out std_logic_vector(W-1 downto 0)
65 22 jguarin200
                );
66
        end component;
67
 
68
        -- A 1 stage pipe 18x18 multiplier. On Cycle III devices is a M-R (Multiplier, Register). (Should be generated using a synthesis tool....).
69 33 jguarin200
        -- As a fixed signed multiplication we have :
70
        -- A(B,C) ====> B+C SIGNED BITS FORMAT : 1 bit for sign, B bits for integer part, C bits for decimal part. (FORMAT)
71
        -- A(7,10)*A(7,10) = A(15,20). (This component format)
72
 
73 22 jguarin200
        component p1m18
74
                port    (
75 33 jguarin200
                -- Asynchronous clear signal.
76
                aclr            : in std_logic ;
77
                -- The usual control signals.
78
                clken           : in std_logic ;
79
                clock           : in std_logic ;
80
 
81
                -- Factor A.
82
                dataa           : in std_logic_vector (17 downto 0);
83
                -- Factor B.
84
                datab           : in std_logic_vector (17 downto 0);
85
                -- Product.
86
                result          : out std_logic_vector (35 downto 0)
87 22 jguarin200
                );
88
        end component;
89
 
90 33 jguarin200
        -- Signed "less than". dataa < datab
91 16 jguarin200
        component sl32
92
                port    (
93 33 jguarin200
 
94
                dataa   : in std_logic_vector (31 downto 0);
95
                datab   : in std_logic_vector (31 downto 0);
96
                AlB             : out std_logic
97
 
98 16 jguarin200
                );
99
                end component;
100
 
101 33 jguarin200
        -- Signed "greater than". dataa >= datab.
102 16 jguarin200
        component sge32
103
                port    (
104 33 jguarin200
 
105
                dataa   : in std_logic_vector (31 downto 0);
106
                datab   : in std_logic_vector (31 downto 0);
107
                AgeB    : out std_logic
108
 
109 16 jguarin200
                );
110
                end component;
111
 
112
 
113 22 jguarin200
        -- Dot Product Calculation Cell. 
114
        -- A 4 side cell along with an upper side. 
115
        -- 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. 
116
        -- 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. 
117 16 jguarin200
        component dotCell
118 40 jguarin200
                generic (
119
 
120
                -- 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.
121
                RV      : string := "yes";
122 33 jguarin200
                -- Actual Level Width
123 40 jguarin200
                W0      : integer := 18;
124 33 jguarin200
                -- Next Level Width
125 40 jguarin200
                W1      : integer := 32);
126 33 jguarin200
 
127 16 jguarin200
                port    (
128 33 jguarin200
                --The usual control signals
129
                clk                     : in std_logic;
130
                rst                     : in std_logic;
131 16 jguarin200
 
132 33 jguarin200
                -- This bit controls when the sphere center goes to the next row.
133
                nxtSphere       : in std_logic;
134
                -- This bit controls when the ray goes to the next column.
135
                nxtRay          : in std_logic;
136 22 jguarin200
 
137 33 jguarin200
                -- First Side.
138 40 jguarin200
                vxInput         : in std_logic_vector(W0-1 downto 0);
139
                vyInput         : in std_logic_vector(W0-1 downto 0);
140
                vzInput         : in std_logic_vector(W0-1 downto 0);
141 16 jguarin200
 
142 33 jguarin200
                -- Second Side (Opposite to the first one)
143 40 jguarin200
                vxOutput        : out std_logic_vector(W0-1 downto 0);
144
                vyOutput        : out std_logic_vector(W0-1 downto 0);
145
                vzOutput        : out std_logic_vector(W0-1 downto 0);
146 16 jguarin200
 
147 33 jguarin200
                -- Third Side (Perpendicular to the first and second ones)
148 40 jguarin200
                dxInput         : in std_logic_vector(W0-1 downto 0);
149
                dyInput         : in std_logic_vector(W0-1 downto 0);
150
                dzInput         : in std_logic_vector(W0-1 downto 0);
151 16 jguarin200
 
152 33 jguarin200
                --Fourth Side (Opposite to the third one)
153 40 jguarin200
                dxOutput        : in std_logic_vector(W0-1 downto 0);
154
                dyOutput        : in std_logic_vector(W0-1 downto 0);
155
                dzOutput        : in std_logic_vector(W0-1 downto 0);
156 16 jguarin200
 
157 33 jguarin200
                --Fifth Side (Going to the floor right upstairs!)
158 40 jguarin200
                vdOutput        : out std_logic_vector(W1-1 downto 0) -- Dot product.
159 16 jguarin200
 
160 22 jguarin200
                );
161 16 jguarin200
        end component;
162
 
163
        -- K discriminant comparison.
164 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
165
        -- 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,
166
        -- whenever there's no intersection the output is asserted with the maximum positive distance in 32 bits : 0x7fffffff.
167 16 jguarin200
        component kComparisonCell
168 40 jguarin200
                generic (
169
                RK      : string        := "yes";
170
                W1      : integer       := 32
171 16 jguarin200
                );
172 40 jguarin200
                port (
173
                clk,rst         : in std_logic;
174
                scanOut         : in std_logic; -- This signals overrides the 'signed greater or equal than' internal function and allows vdinput to flow upwards.
175
                nxtSphere       : in std_logic; -- Controls when the sphere goes to the next Row. 
176
                pipeOn          : in std_logic; -- Enables / Disable the upwarding flow.
177
                kinput          : in std_logic_vector (W1-1 downto 0);
178
                koutputhor      : out std_logic_vector (W1-1 downto 0);
179
                koutputver      : out std_logic_vector (W1-1 downto 0);  -- K input  flowing to the next floor upstairs (but waits one clock). 
180
                vdinput         : in std_logic_vector (W1-1 downto 0);   -- V.D input.
181
                vdoutput        : out std_logic_vector (W1-1 downto 0)   -- Selected dot product.
182
                );
183 22 jguarin200
        end component;
184 33 jguarin200
        -- Minimun distance Comparison.
185
        -- The reference value, refvd, is the ray minimal intersection distance calculated in the moment of the comparison. 
186
        -- The column value, colvd, is the column sphere and ray intersection distance (if any or else the maximum distance is asserted).
187
 
188
 
189
        component dComparisonCell
190
                generic (
191
                -- V.D, minDistance and selectD Width 
192 40 jguarin200
                W1              : integer := 32;
193 33 jguarin200
                -- Column Sphere ID width. 1 = 2 columns max, 2= 4 colums max... and so on.
194 40 jguarin200
                IDW     : integer := 2;
195 33 jguarin200
                -- Column Id
196
                idCol   : integer := 0
197
                );
198
                port    (
199
                -- The usual control signals.           
200 40 jguarin200
                clk, rst, pipeOn : in std_logic;
201
 
202 61 jguarin200
 
203
                intd    : in    std_logic;
204
                intq    : out   std_logic;
205 33 jguarin200
                -- This is the reference column identification input.
206 40 jguarin200
                cIdd    : in    std_logic_vector (IDW - 1 downto 0);
207 33 jguarin200
                -- This is the result column identification output.
208 61 jguarin200
                cIdq    : out   std_logic_vector (IDW - 1 downto 0);
209
                refk    : in    std_logic_vector (W1 - 1 downto 0); -- This is the columns sphere constant
210
                colk    : in    std_logic_vector (W1 - 1 downto 0); -- This is the reference sphere constant
211
                selk    : out   std_logic_vector (W1 - 1 downto 0); -- This is the selected sphere constant              
212 33 jguarin200
                -- This is the reference projection incoming from the previous cell.
213 40 jguarin200
                refvd   : in    std_logic_vector (W1 - 1 downto 0);
214 33 jguarin200
                -- This is the sphere position over the ray traced vector projection.
215 40 jguarin200
                colvd   : in    std_logic_vector (W1 - 1 downto 0);
216 33 jguarin200
                -- This is the smallest value between refvd and colvd.
217 40 jguarin200
                selvd   : out   std_logic_vector (W1 - 1 downto 0)
218 33 jguarin200
                );
219
        end component;
220
 
221
        component floor0Row
222
                generic (
223
                -- Floor Level Width (V.D width)
224 40 jguarin200
                W1 : integer := 32;
225 33 jguarin200
                -- Vector input Width           
226 40 jguarin200
                W0 : integer := 18;
227 33 jguarin200
                -- Number of Colums
228 40 jguarin200
                C       : integer := 4
229 33 jguarin200
        );
230
        port (
231
                -- The usual control signals. nxtRay should be 0 whenever I want to stop the entire machine.
232
                clk, rst, nxtRay : in std_logic;
233 16 jguarin200
 
234 33 jguarin200
                -- Clk, Rst, the usual control signals.
235
                -- enabled, the machine is running when this input is set.
236
                -- enabled, all the counters begin again.
237 40 jguarin200
                nxtSphere : in std_logic_vector (C-1 downto 0);
238 33 jguarin200
 
239
 
240
                -- Input Values. 
241
                -- The ray input vector.
242 40 jguarin200
                iRayx: in std_logic_vector (W0 - 1 downto 0);
243
                iRayy: in std_logic_vector (W0 - 1 downto 0);
244
                iRayz: in std_logic_vector (W0 - 1 downto 0);
245 33 jguarin200
 
246
                -- The spheres x position (sphere centers) input vectors.
247 40 jguarin200
                iSphrCenterx: in std_logic_vector (C*W0 - 1 downto 0);
248 33 jguarin200
                -- The spheres y position (sphere centers) input vectors.
249 40 jguarin200
                iSphrCentery: in std_logic_vector (C*W0 - 1 downto 0);
250 33 jguarin200
                -- The spheres z position (sphere centers) input vectors.
251 40 jguarin200
                iSphrCenterz: in std_logic_vector (C*W0 - 1 downto 0);
252 33 jguarin200
                -- The spheres x position (sphere centers) output vectors.
253 40 jguarin200
                oSphrCenterx: out std_logic_vector (C*W0 - 1 downto 0);
254 33 jguarin200
                -- The spheres y positions (sphere centes) output vectors.
255 40 jguarin200
                oSphrCentery: out std_logic_vector (C*W0 - 1 downto 0);
256 33 jguarin200
                -- The spheres z positions (sphere centers) output vectors.             
257 40 jguarin200
                oSphrCenterz: out std_logic_vector (C*W0 - 1 downto 0);
258 33 jguarin200
 
259
                -- Output Values
260
                -- The ray output vector.
261 40 jguarin200
                oRayx: out std_logic_vector (W0 - 1 downto 0);
262
                oRayy: out std_logic_vector (W0 - 1 downto 0);
263
                oRayz: out std_logic_vector (W0 - 1 downto 0);
264 33 jguarin200
 
265
                -- The dot product result from each dot prod cell.
266 40 jguarin200
                vdOutput : out std_logic_vector (W1*C - 1 downto 0)
267 33 jguarin200
                );
268
        end component;
269
 
270
        -- 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.
271
        -- 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)
272
        -- distance value.
273
 
274
        component floor1Row
275
        generic (
276
 
277
                -- Vector input Width   
278 40 jguarin200
                W1 : integer := 32;
279 33 jguarin200
                -- Number of Colums
280 40 jguarin200
                C       : integer := 4
281 33 jguarin200
        );
282
        port (
283
 
284
                -- Input Control Signals, pipe on is one when raysr going on. 
285
                clk, rst        : in std_logic;
286
                pipeOn          : in std_logic;
287
 
288
                -- Clk, Rst, the usual control signals.
289 40 jguarin200
                nxtSphere       : in std_logic_vector (C-1 downto 0);
290 33 jguarin200
 
291
                -- VD Input / Output.
292 40 jguarin200
                vdInput : in std_logic_vector (W1*C-1 downto 0);
293
                vdOutput: out std_logic_vector (W1*C-1 downto 0);
294 33 jguarin200
 
295
                -- K Input / Output.
296 40 jguarin200
                kInput  : in std_logic_vector (W1*C - 1 downto 0);
297
                kOutput : out std_logic_vector (W1*C - 1 downto 0)
298 33 jguarin200
        );
299
        end component;
300
 
301
        -- 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. 
302
 
303
        component floor2Row
304
        generic (
305
                -- Vector input Width
306 40 jguarin200
                W1 : integer := 32;
307 33 jguarin200
                -- ID Column width
308 40 jguarin200
                IDW : integer := 2;
309 33 jguarin200
                -- Number of Colums
310 40 jguarin200
                C       : integer := 4
311 33 jguarin200
        );
312
        port (
313
                -- Input Control Signal
314
                -- Clk, Rst, the usual control signals.
315
                clk, rst, pipeOn: in std_logic;
316
 
317
                -- Input Values
318
                -- Reference VD, the "at the moment" smallest VD sphere ray projection value.
319 40 jguarin200
                refvd   : in std_logic_vector (W1-1 downto 0);
320 33 jguarin200
 
321
                -- The smallest VD, value found.
322 40 jguarin200
                selvd   : out std_logic_vector (W1-1 downto 0);
323 33 jguarin200
 
324
                -- The column's sphere ray projection value.
325 40 jguarin200
                colvd   : in std_logic_vector (W1*C-1 downto 0);
326 33 jguarin200
                -- The smallest VD projection value column id.
327 40 jguarin200
                colid   : out std_logic_vector (IDW-1 downto 0);
328 33 jguarin200
                -- The intersection signal (1 on intersection else 0).
329
                inter   : out std_logic
330
        );
331
        end component;
332
 
333
        component rayxsphereGrid
334
        generic (
335
                -- Width of Column identificator.
336
                IDW     : integer := 2;
337
                -- Number of Columns.
338
                C       : integer := 4;
339
                -- Input rays width.
340
                W0      : integer := 18;
341
                -- Dot products and spheres constant width
342 40 jguarin200
                W1      : integer := 32
343 33 jguarin200
 
344
                );
345
        port (
346
                -- The usual control signals.
347
                clk,rst         : in std_logic;
348
 
349
                -- Grid, rays and sphere flow through control signals.
350
                pipeOn          : in std_logic;
351
                nxtSphere       : in std_logic_vector (C-1 downto 0);
352
 
353
                -- R-F0
354
                -- Input Values. 
355
                -- The ray input vector.
356
                iRayx: in std_logic_vector (W0 - 1 downto 0);
357
                iRayy: in std_logic_vector (W0 - 1 downto 0);
358
                iRayz: in std_logic_vector (W0 - 1 downto 0);
359
                -- The spheres x position (sphere centers) input vectors.
360
                iSphrCenterx: in std_logic_vector (C*W0 - 1 downto 0);
361
                -- The spheres y position (sphere centers) input vectors.
362
                iSphrCentery: in std_logic_vector (C*W0 - 1 downto 0);
363
                -- The spheres z position (sphere centers) input vectors.
364
                iSphrCenterz: in std_logic_vector (C*W0 - 1 downto 0);
365
                -- The spheres x position (sphere centers) output vectors.
366
                oSphrCenterx: out std_logic_vector (C*W0 - 1 downto 0);
367
                -- The spheres y positions (sphere centes) output vectors.
368
                oSphrCentery: out std_logic_vector (C*W0 - 1 downto 0);
369
                -- The spheres z positions (sphere centers) output vectors.             
370
                oSphrCenterz: out std_logic_vector (C*W0 - 1 downto 0);
371
                -- Output Values
372
                -- The ray output vector.
373
                oRayx: out std_logic_vector (W0 - 1 downto 0);
374
                oRayy: out std_logic_vector (W0 - 1 downto 0);
375
                oRayz: out std_logic_vector (W0 - 1 downto 0);
376
 
377
                -- R-F1
378
                -- K Input / Output.
379
                kInput  : in std_logic_vector (C*W1 - 1 downto 0);
380 40 jguarin200
                kOutput : out std_logic_vector (C*W1 - 1 downto 0);
381 33 jguarin200
 
382
                --R-F2
383
                -- Input Values
384
                refvd   : in std_logic_vector (W1-1 downto 0);
385
                selvd   : out std_logic_vector (W1-1 downto 0);
386
                colid   : out std_logic_vector (IDW-1 downto 0);
387
                inter   : out std_logic
388
                );
389
        end component;
390
        component gridCube
391
        generic (
392
                -- Depth
393
                D       : integer := 4;
394
                -- ID width.
395
                IDW     : integer := 2;
396
                -- Number of Columns.
397
                C       : integer := 4;
398
                -- Input rays width.
399
                W0      : integer := 18;
400
                -- Dot products and spheres constant width
401 40 jguarin200
                W1      : integer := 32
402 33 jguarin200
 
403
                );
404
        port (
405
                        -- The usual control signals.
406
                clk,rst : in std_logic;
407
 
408
                -- Grid, rays and sphere flow through control signals.
409
                pipeOn                  : in std_logic;
410
                -- The same column nxtSphere signal control..... regardless the Cube Depth.
411
                nxtSphere               : in std_logic_vector (C-1 downto 0);
412
 
413
                -- R-F0
414
                -- Input Values. 
415
                -- The ray input vector. 
416
                iRayx: in std_logic_vector (D*W0 - 1 downto 0);
417
                iRayy: in std_logic_vector (D*W0 - 1 downto 0);
418
                iRayz: in std_logic_vector (D*W0 - 1 downto 0);
419
                -- The spheres x position (sphere centers) input vectors.
420
                iSphrCenterx: in std_logic_vector (C*W0 - 1 downto 0);
421
                -- The spheres y position (sphere centers) input vectors.
422
                iSphrCentery: in std_logic_vector (C*W0 - 1 downto 0);
423
                -- The spheres z position (sphere centers) input vectors.
424
                iSphrCenterz: in std_logic_vector (C*W0 - 1 downto 0);
425
                -- The spheres x position (sphere centers) output vectors.
426
                oSphrCenterx: out std_logic_vector (C*W0 - 1 downto 0);
427
                -- The spheres y positions (sphere centes) output vectors.
428
                oSphrCentery: out std_logic_vector (C*W0 - 1 downto 0);
429
                -- The spheres z positions (sphere centers) output vectors.             
430
                oSphrCenterz: out std_logic_vector (C*W0 - 1 downto 0);
431
                -- Output Values
432
                -- The ray output vector.
433
                oRayx: out std_logic_vector (D*W0 - 1 downto 0);
434
                oRayy: out std_logic_vector (D*W0 - 1 downto 0);
435
                oRayz: out std_logic_vector (D*W0 - 1 downto 0);
436
 
437
                -- R-F1
438
                -- K Input / Output.
439
                kInput  : in std_logic_vector (C*W1 - 1 downto 0);
440 40 jguarin200
                kOutput : out std_logic_vector (C*W1 - 1 downto 0);
441 33 jguarin200
 
442
                --R-F2
443
                -- Input Values
444
                refvd   : in std_logic_vector (D*W1-1 downto 0);
445
                selvd   : out std_logic_vector (D*W1-1 downto 0);
446
                colid   : out std_logic_vector (D*IDW-1 downto 0);
447
                inter   : out std_logic_vector (D-1 downto 0)
448
                );
449
        end component;
450 22 jguarin200
end powerGrid;

powered by: WebSVN 2.1.0

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