-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathzculling_top.cpp
More file actions
100 lines (88 loc) · 2.09 KB
/
zculling_top.cpp
File metadata and controls
100 lines (88 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "../host/typedefs.h"
// filter hidden pixels
void zculling_top (
hls::stream<ap_uint<32> > & Input_1,
hls::stream<ap_uint<32> > & Input_2,
hls::stream<ap_uint<32> > & Output_1
)
{
#pragma HLS INTERFACE axis register port=Input_1
#pragma HLS INTERFACE axis register port=Input_2
#pragma HLS INTERFACE axis register port=Output_1
#pragma HLS INLINE off
CandidatePixel fragment;
static bit16 counter=0;
int i, j;
Pixel pixels[500];
bit16 size;
bit32 in_tmp;
bit32 out_tmp;
static bit1 odd_even = 0;
if(odd_even == 0) {
size = Input_1.read();
#ifdef PROFILE
zculling_top_in_1++;
#endif
} else {
size = Input_2.read();
#ifdef PROFILE
zculling_top_in_2++;
#endif
}
// initilize the z-buffer in rendering first triangle for an image
static bit8 z_buffer[MAX_X/2][MAX_Y];
if (counter == 0)
{
ZCULLING_INIT_ROW: for ( bit16 i = 0; i < MAX_X/2; i++)
{
ZCULLING_INIT_COL: for ( bit16 j = 0; j < MAX_Y; j++)
{
z_buffer[i][j] = 255;
}
}
}
// pixel counter
bit16 pixel_cntr = 0;
// update z-buffer and pixels
ZCULLING: for ( bit16 n = 0; n < size; n++ )
{
#pragma HLS PIPELINE II=1
if (odd_even == 0){
in_tmp = Input_1.read();
}
else {
in_tmp = Input_2.read();
}
fragment.x(7,0) = in_tmp(7, 0);
fragment.y(7,0) = in_tmp(15, 8);
fragment.z(7,0) = in_tmp(23, 16);
fragment.color(7,0) = in_tmp(31, 24);
if( fragment.z < z_buffer[fragment.y-128][fragment.x] )
{
pixels[pixel_cntr].x = fragment.x;
pixels[pixel_cntr].y = fragment.y;
pixels[pixel_cntr].color = fragment.color;
pixel_cntr++;
z_buffer[fragment.y-128][fragment.x] = fragment.z;
}
}
Output_1.write(pixel_cntr);
#ifdef PROFILE
zculling_top_out_1++;
#endif
for(j=0; j<pixel_cntr; j++){
#pragma HLS PIPELINE II=1
out_tmp(7, 0) = pixels[j].x;
out_tmp(15, 8) = pixels[j].y;
out_tmp(23, 16) = pixels[j].color;
out_tmp(31, 24) = 0;
Output_1.write(out_tmp);
#ifdef PROFILE
zculling_top_out_1++;
#endif
}
counter++;
odd_even = ~odd_even;
if(counter==NUM_3D_TRI){counter=0;}
return;
}