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

Subversion Repositories jart

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

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
                clk,rst,ena,sel         : std_logic; -- The usual  control signals
36
 
37
                d0,d1   : std_logic_vector (W-1 downto 0);       -- The two operands.
38
                q               : std_logic_vector (W-1 downto 0)        -- The selected data.
39
 
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
                enable          :        in std_logic;
56
 
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
 
203 33 jguarin200
                -- This is the reference column identification input.
204 40 jguarin200
                cIdd    : in    std_logic_vector (IDW - 1 downto 0);
205 33 jguarin200
                -- This is the result column identification output.
206 40 jguarin200
                cIdq    : out   std_logic_vector (IDW - 1 downto 0);
207 33 jguarin200
                -- This is the reference projection incoming from the previous cell.
208 40 jguarin200
                refvd   : in    std_logic_vector (W1 - 1 downto 0);
209 33 jguarin200
                -- This is the sphere position over the ray traced vector projection.
210 40 jguarin200
                colvd   : in    std_logic_vector (W1 - 1 downto 0);
211 33 jguarin200
                -- This is the smallest value between refvd and colvd.
212 40 jguarin200
                selvd   : out   std_logic_vector (W1 - 1 downto 0)
213 33 jguarin200
                );
214
        end component;
215
 
216
        component floor0Row
217
                generic (
218
                -- Floor Level Width (V.D width)
219 40 jguarin200
                W1 : integer := 32;
220 33 jguarin200
                -- Vector input Width           
221 40 jguarin200
                W0 : integer := 18;
222 33 jguarin200
                -- Number of Colums
223 40 jguarin200
                C       : integer := 4
224 33 jguarin200
        );
225
        port (
226
                -- The usual control signals. nxtRay should be 0 whenever I want to stop the entire machine.
227
                clk, rst, nxtRay : in std_logic;
228 16 jguarin200
 
229 33 jguarin200
                -- Clk, Rst, the usual control signals.
230
                -- enabled, the machine is running when this input is set.
231
                -- enabled, all the counters begin again.
232 40 jguarin200
                nxtSphere : in std_logic_vector (C-1 downto 0);
233 33 jguarin200
 
234
 
235
                -- Input Values. 
236
                -- The ray input vector.
237 40 jguarin200
                iRayx: in std_logic_vector (W0 - 1 downto 0);
238
                iRayy: in std_logic_vector (W0 - 1 downto 0);
239
                iRayz: in std_logic_vector (W0 - 1 downto 0);
240 33 jguarin200
 
241
                -- The spheres x position (sphere centers) input vectors.
242 40 jguarin200
                iSphrCenterx: in std_logic_vector (C*W0 - 1 downto 0);
243 33 jguarin200
                -- The spheres y position (sphere centers) input vectors.
244 40 jguarin200
                iSphrCentery: in std_logic_vector (C*W0 - 1 downto 0);
245 33 jguarin200
                -- The spheres z position (sphere centers) input vectors.
246 40 jguarin200
                iSphrCenterz: in std_logic_vector (C*W0 - 1 downto 0);
247 33 jguarin200
                -- The spheres x position (sphere centers) output vectors.
248 40 jguarin200
                oSphrCenterx: out std_logic_vector (C*W0 - 1 downto 0);
249 33 jguarin200
                -- The spheres y positions (sphere centes) output vectors.
250 40 jguarin200
                oSphrCentery: out std_logic_vector (C*W0 - 1 downto 0);
251 33 jguarin200
                -- The spheres z positions (sphere centers) output vectors.             
252 40 jguarin200
                oSphrCenterz: out std_logic_vector (C*W0 - 1 downto 0);
253 33 jguarin200
 
254
                -- Output Values
255
                -- The ray output vector.
256 40 jguarin200
                oRayx: out std_logic_vector (W0 - 1 downto 0);
257
                oRayy: out std_logic_vector (W0 - 1 downto 0);
258
                oRayz: out std_logic_vector (W0 - 1 downto 0);
259 33 jguarin200
 
260
                -- The dot product result from each dot prod cell.
261 40 jguarin200
                vdOutput : out std_logic_vector (W1*C - 1 downto 0)
262 33 jguarin200
                );
263
        end component;
264
 
265
        -- 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.
266
        -- 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)
267
        -- distance value.
268
 
269
        component floor1Row
270
        generic (
271
 
272
                -- Vector input Width   
273 40 jguarin200
                W1 : integer := 32;
274 33 jguarin200
                -- Number of Colums
275 40 jguarin200
                C       : integer := 4
276 33 jguarin200
        );
277
        port (
278
 
279
                -- Input Control Signals, pipe on is one when raysr going on. 
280
                clk, rst        : in std_logic;
281
                pipeOn          : in std_logic;
282
 
283
                -- Clk, Rst, the usual control signals.
284 40 jguarin200
                nxtSphere       : in std_logic_vector (C-1 downto 0);
285 33 jguarin200
 
286
                -- VD Input / Output.
287 40 jguarin200
                vdInput : in std_logic_vector (W1*C-1 downto 0);
288
                vdOutput: out std_logic_vector (W1*C-1 downto 0);
289 33 jguarin200
 
290
                -- K Input / Output.
291 40 jguarin200
                kInput  : in std_logic_vector (W1*C - 1 downto 0);
292
                kOutput : out std_logic_vector (W1*C - 1 downto 0)
293 33 jguarin200
        );
294
        end component;
295
 
296
        -- 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. 
297
 
298
        component floor2Row
299
        generic (
300
                -- Vector input Width
301 40 jguarin200
                W1 : integer := 32;
302 33 jguarin200
                -- ID Column width
303 40 jguarin200
                IDW : integer := 2;
304 33 jguarin200
                -- Number of Colums
305 40 jguarin200
                C       : integer := 4
306 33 jguarin200
        );
307
        port (
308
                -- Input Control Signal
309
                -- Clk, Rst, the usual control signals.
310
                clk, rst, pipeOn: in std_logic;
311
 
312
                -- Input Values
313
                -- Reference VD, the "at the moment" smallest VD sphere ray projection value.
314 40 jguarin200
                refvd   : in std_logic_vector (W1-1 downto 0);
315 33 jguarin200
 
316
                -- The smallest VD, value found.
317 40 jguarin200
                selvd   : out std_logic_vector (W1-1 downto 0);
318 33 jguarin200
 
319
                -- The column's sphere ray projection value.
320 40 jguarin200
                colvd   : in std_logic_vector (W1*C-1 downto 0);
321 33 jguarin200
                -- The smallest VD projection value column id.
322 40 jguarin200
                colid   : out std_logic_vector (IDW-1 downto 0);
323 33 jguarin200
                -- The intersection signal (1 on intersection else 0).
324
                inter   : out std_logic
325
        );
326
        end component;
327
 
328
        component rayxsphereGrid
329
        generic (
330
                -- Width of Column identificator.
331
                IDW     : integer := 2;
332
                -- Number of Columns.
333
                C       : integer := 4;
334
                -- Input rays width.
335
                W0      : integer := 18;
336
                -- Dot products and spheres constant width
337 40 jguarin200
                W1      : integer := 32
338 33 jguarin200
 
339
                );
340
        port (
341
                -- The usual control signals.
342
                clk,rst         : in std_logic;
343
 
344
                -- Grid, rays and sphere flow through control signals.
345
                pipeOn          : in std_logic;
346
                nxtSphere       : in std_logic_vector (C-1 downto 0);
347
 
348
                -- R-F0
349
                -- Input Values. 
350
                -- The ray input vector.
351
                iRayx: in std_logic_vector (W0 - 1 downto 0);
352
                iRayy: in std_logic_vector (W0 - 1 downto 0);
353
                iRayz: in std_logic_vector (W0 - 1 downto 0);
354
                -- The spheres x position (sphere centers) input vectors.
355
                iSphrCenterx: in std_logic_vector (C*W0 - 1 downto 0);
356
                -- The spheres y position (sphere centers) input vectors.
357
                iSphrCentery: in std_logic_vector (C*W0 - 1 downto 0);
358
                -- The spheres z position (sphere centers) input vectors.
359
                iSphrCenterz: in std_logic_vector (C*W0 - 1 downto 0);
360
                -- The spheres x position (sphere centers) output vectors.
361
                oSphrCenterx: out std_logic_vector (C*W0 - 1 downto 0);
362
                -- The spheres y positions (sphere centes) output vectors.
363
                oSphrCentery: out std_logic_vector (C*W0 - 1 downto 0);
364
                -- The spheres z positions (sphere centers) output vectors.             
365
                oSphrCenterz: out std_logic_vector (C*W0 - 1 downto 0);
366
                -- Output Values
367
                -- The ray output vector.
368
                oRayx: out std_logic_vector (W0 - 1 downto 0);
369
                oRayy: out std_logic_vector (W0 - 1 downto 0);
370
                oRayz: out std_logic_vector (W0 - 1 downto 0);
371
 
372
                -- R-F1
373
                -- K Input / Output.
374
                kInput  : in std_logic_vector (C*W1 - 1 downto 0);
375 40 jguarin200
                kOutput : out std_logic_vector (C*W1 - 1 downto 0);
376 33 jguarin200
 
377
                --R-F2
378
                -- Input Values
379
                refvd   : in std_logic_vector (W1-1 downto 0);
380
                selvd   : out std_logic_vector (W1-1 downto 0);
381
                colid   : out std_logic_vector (IDW-1 downto 0);
382
                inter   : out std_logic
383
                );
384
        end component;
385
        component gridCube
386
        generic (
387
                -- Depth
388
                D       : integer := 4;
389
                -- ID width.
390
                IDW     : integer := 2;
391
                -- Number of Columns.
392
                C       : integer := 4;
393
                -- Input rays width.
394
                W0      : integer := 18;
395
                -- Dot products and spheres constant width
396 40 jguarin200
                W1      : integer := 32
397 33 jguarin200
 
398
                );
399
        port (
400
                        -- The usual control signals.
401
                clk,rst : in std_logic;
402
 
403
                -- Grid, rays and sphere flow through control signals.
404
                pipeOn                  : in std_logic;
405
                -- The same column nxtSphere signal control..... regardless the Cube Depth.
406
                nxtSphere               : in std_logic_vector (C-1 downto 0);
407
 
408
                -- R-F0
409
                -- Input Values. 
410
                -- The ray input vector. 
411
                iRayx: in std_logic_vector (D*W0 - 1 downto 0);
412
                iRayy: in std_logic_vector (D*W0 - 1 downto 0);
413
                iRayz: in std_logic_vector (D*W0 - 1 downto 0);
414
                -- The spheres x position (sphere centers) input vectors.
415
                iSphrCenterx: in std_logic_vector (C*W0 - 1 downto 0);
416
                -- The spheres y position (sphere centers) input vectors.
417
                iSphrCentery: in std_logic_vector (C*W0 - 1 downto 0);
418
                -- The spheres z position (sphere centers) input vectors.
419
                iSphrCenterz: in std_logic_vector (C*W0 - 1 downto 0);
420
                -- The spheres x position (sphere centers) output vectors.
421
                oSphrCenterx: out std_logic_vector (C*W0 - 1 downto 0);
422
                -- The spheres y positions (sphere centes) output vectors.
423
                oSphrCentery: out std_logic_vector (C*W0 - 1 downto 0);
424
                -- The spheres z positions (sphere centers) output vectors.             
425
                oSphrCenterz: out std_logic_vector (C*W0 - 1 downto 0);
426
                -- Output Values
427
                -- The ray output vector.
428
                oRayx: out std_logic_vector (D*W0 - 1 downto 0);
429
                oRayy: out std_logic_vector (D*W0 - 1 downto 0);
430
                oRayz: out std_logic_vector (D*W0 - 1 downto 0);
431
 
432
                -- R-F1
433
                -- K Input / Output.
434
                kInput  : in std_logic_vector (C*W1 - 1 downto 0);
435 40 jguarin200
                kOutput : out std_logic_vector (C*W1 - 1 downto 0);
436 33 jguarin200
 
437
                --R-F2
438
                -- Input Values
439
                refvd   : in std_logic_vector (D*W1-1 downto 0);
440
                selvd   : out std_logic_vector (D*W1-1 downto 0);
441
                colid   : out std_logic_vector (D*IDW-1 downto 0);
442
                inter   : out std_logic_vector (D-1 downto 0)
443
                );
444
        end component;
445 22 jguarin200
end powerGrid;

powered by: WebSVN 2.1.0

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