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

Subversion Repositories jart

[/] [jart/] [trunk/] [BLRT/] [powerGrid.vhd] - Blame information for rev 40

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

powered by: WebSVN 2.1.0

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