cc.v.bug
13.3 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
////////////////////////////////////////////////////////////////////////
//
// Project Reality
//
// module: cc
// description: Top level for color combine unit.
//
// designer: Phil Gossett
// date: 6/26/94
//
////////////////////////////////////////////////////////////////////////
module cc (gclk, st_span, ncyc, antialias_en, key_en, cvg,
cc_x_sel_0_r, cc_y_sel_0_r, cc_a_sel_0_r, cc_c_sel_0_r,
cc_x_sel_0_a, cc_y_sel_0_a, cc_a_sel_0_a, cc_c_sel_0_a,
cc_x_sel_1_r, cc_y_sel_1_r, cc_a_sel_1_r, cc_c_sel_1_r,
cc_x_sel_1_a, cc_y_sel_1_a, cc_a_sel_1_a, cc_c_sel_1_a,
st_r, st_g, st_b, st_a,
tf_r, tf_g, tf_b, tf_a,
tf_lod_frac, prim_lod_frac,
prim_r, prim_g, prim_b, prim_a,
env_r, env_g, env_b, env_a,
center_r, center_g, center_b,
scale_r, scale_g, scale_b,
width_r, width_g, width_b,
k4_coeff, k5_coeff,
noise, // for now, later inside?
pixel_r, pixel_g, pixel_b, pixel_a, pixel_cvg);
input gclk;
input st_span;
input ncyc;
input antialias_en;
input key_en;
input [3:0] cvg;
input [3:0] cc_x_sel_0_r;
input [3:0] cc_y_sel_0_r;
input [4:0] cc_a_sel_0_r;
input [2:0] cc_c_sel_0_r;
input [2:0] cc_x_sel_0_a;
input [2:0] cc_y_sel_0_a;
input [2:0] cc_a_sel_0_a;
input [2:0] cc_c_sel_0_a;
input [3:0] cc_x_sel_1_r;
input [3:0] cc_y_sel_1_r;
input [4:0] cc_a_sel_1_r;
input [2:0] cc_c_sel_1_r;
input [2:0] cc_x_sel_1_a;
input [2:0] cc_y_sel_1_a;
input [2:0] cc_a_sel_1_a;
input [2:0] cc_c_sel_1_a;
input [7:0] st_r;
input [7:0] st_g;
input [7:0] st_b;
input [7:0] st_a;
input [8:0] tf_r;
input [8:0] tf_g;
input [8:0] tf_b;
input [8:0] tf_a;
input [8:0] tf_lod_frac;
input [8:0] prim_lod_frac;
input [7:0] prim_r;
input [7:0] prim_g;
input [7:0] prim_b;
input [7:0] prim_a;
input [7:0] env_r;
input [7:0] env_g;
input [7:0] env_b;
input [7:0] env_a;
input [7:0] center_r;
input [7:0] center_g;
input [7:0] center_b;
input [7:0] scale_r;
input [7:0] scale_g;
input [7:0] scale_b;
input [11:0] width_r;
input [11:0] width_g;
input [11:0] width_b;
input [8:0] k4_coeff;
input [8:0] k5_coeff;
input [8:0] noise;
reg force_cycle;
reg pre_cycle;
reg [7:0] st_reg_r;
reg [7:0] st_reg_g;
reg [7:0] st_reg_b;
reg [7:0] st_reg_a;
reg [8:0] tf_reg_r;
reg [8:0] tf_reg_g;
reg [8:0] tf_reg_b;
reg [8:0] tf_reg_a;
reg [8:0] tf_rg2_r;
reg [8:0] tf_rg2_g;
reg [8:0] tf_rg2_b;
reg [8:0] tf_rg2_a;
reg [8:0] lod_frac;
wire [7:0] shade_r;
wire [7:0] shade_g;
wire [7:0] shade_b;
wire [7:0] shade_a;
wire [8:0] tex_0_r;
wire [8:0] tex_0_g;
wire [8:0] tex_0_b;
wire [8:0] tex_0_a;
wire [8:0] tex_1_r;
wire [8:0] tex_1_g;
wire [8:0] tex_1_b;
wire [8:0] tex_1_a;
wire [3:0] cc_x_sel_rgb;
wire [3:0] cc_y_sel_rgb;
wire [4:0] cc_a_sel_rgb;
wire [2:0] cc_c_sel_rgb;
wire [2:0] cc_x_sel_alf;
wire [2:0] cc_y_sel_alf;
wire [2:0] cc_a_sel_alf;
wire [2:0] cc_c_sel_alf;
reg shad_cycle;
reg tex0_cycle;
reg tex1_cycle;
reg [3:0] cc_x_sel_reg_rgb;
reg [3:0] cc_y_sel_reg_rgb;
reg [4:0] cc_a_sel_reg_rgb;
reg [2:0] cc_c_sel_reg_rgb;
reg [2:0] cc_x_sel_reg_alf;
reg [2:0] cc_y_sel_reg_alf;
reg [2:0] cc_a_sel_reg_alf;
reg [2:0] cc_c_sel_reg_alf;
wire [8:0] r_x; // positive subtract input
wire [8:0] g_x;
wire [8:0] b_x;
wire [8:0] a_x;
wire [8:0] r_y; // negative subtract input
wire [8:0] g_y;
wire [8:0] b_y;
wire [8:0] a_y;
wire [8:0] r_a; // multiply input
wire [8:0] g_a;
wire [8:0] b_a;
wire [8:0] a_a;
wire [8:0] r_c; // final lerp add
wire [8:0] g_c;
wire [8:0] b_c;
wire [8:0] a_c;
wire [16:0] r_mp; // final carry-propagated sum
wire [16:0] g_mp;
wire [16:0] b_mp;
wire [16:0] a_mp;
reg key_cycle;
reg [16:0] cc_r; // registered color combine loopback
reg [16:0] cc_g;
reg [16:0] cc_b;
reg [16:0] cc_a;
reg [8:0] r_x_reg; // registered positive subtract input
reg [8:0] g_x_reg;
reg [8:0] b_x_reg;
wire [7:0] key_mux;
//reg force_zero_r;
//reg [7:0] pre_clamp_r;
//reg force_one_r;
reg [7:0] clamp_r;
//reg force_zero_g;
//reg [7:0] pre_clamp_g;
//reg force_one_g;
reg [7:0] clamp_g;
//reg force_zero_b;
//reg [7:0] pre_clamp_b;
//reg force_one_b;
reg [7:0] clamp_b;
//reg force_zero_a;
//reg [7:0] pre_clamp_a;
//reg force_one_a;
reg [7:0] clamp_a;
reg [8:0] alpha_cvg;
reg key_sel;
reg [8:0] key_r;
reg [8:0] key_g;
reg [8:0] key_b;
reg [8:0] key_a;
output [7:0] pixel_r;
output [7:0] pixel_g;
output [7:0] pixel_b;
output [8:0] pixel_a; // 1.8
output [3:0] pixel_cvg; // 1.3
reg [7:0] pixel_r;
reg [7:0] pixel_g;
reg [7:0] pixel_b;
reg [8:0] pixel_a; // 1.8
reg [3:0] pixel_cvg; // 1.3
always @(posedge gclk)
begin
force_cycle = st_span || pre_cycle;
pre_cycle <= !(force_cycle && ncyc);
tf_reg_r <= tf_r;
tf_reg_g <= tf_g;
tf_reg_b <= tf_b;
tf_reg_a <= tf_a;
end
// don't optimize the following instanced stuff:
cc_mux4 muxxselr (.s(pre_cycle), .i0i(cc_x_sel_0_r), .i1i(cc_x_sel_1_r),
.z(cc_x_sel_rgb));
cc_mux4 muxyselr (.s(pre_cycle), .i0i(cc_y_sel_0_r), .i1i(cc_y_sel_1_r),
.z(cc_y_sel_rgb));
cc_mux5 muxaselr (.s(pre_cycle), .i0i(cc_a_sel_0_r), .i1i(cc_a_sel_1_r),
.z(cc_a_sel_rgb));
cc_mux3 muxcselr (.s(pre_cycle), .i0i(cc_c_sel_0_r), .i1i(cc_c_sel_1_r),
.z(cc_c_sel_rgb));
cc_mux3 muxxsela (.s(pre_cycle), .i0i(cc_x_sel_0_a), .i1i(cc_x_sel_1_a),
.z(cc_x_sel_alf));
cc_mux3 muxysela (.s(pre_cycle), .i0i(cc_y_sel_0_a), .i1i(cc_y_sel_1_a),
.z(cc_y_sel_alf));
cc_mux3 muxasela (.s(pre_cycle), .i0i(cc_a_sel_0_a), .i1i(cc_a_sel_1_a),
.z(cc_a_sel_alf));
cc_mux3 muxcsela (.s(pre_cycle), .i0i(cc_c_sel_0_a), .i1i(cc_c_sel_1_a),
.z(cc_c_sel_alf));
always @(posedge gclk)
begin
shad_cycle <= pre_cycle; // replicated for loading
tex0_cycle <= pre_cycle;
tex1_cycle <= pre_cycle;
cc_x_sel_reg_rgb <= cc_x_sel_rgb;
cc_y_sel_reg_rgb <= cc_y_sel_rgb;
cc_a_sel_reg_rgb <= cc_a_sel_rgb;
cc_c_sel_reg_rgb <= cc_c_sel_rgb;
cc_x_sel_reg_alf <= cc_x_sel_alf;
cc_y_sel_reg_alf <= cc_y_sel_alf;
cc_a_sel_reg_alf <= cc_a_sel_alf;
cc_c_sel_reg_alf <= cc_c_sel_alf;
lod_frac <= tf_lod_frac;
st_reg_r <= st_r;
st_reg_g <= st_g;
st_reg_b <= st_b;
st_reg_a <= st_a;
tf_rg2_r <= tf_reg_r;
tf_rg2_g <= tf_reg_g;
tf_rg2_b <= tf_reg_b;
tf_rg2_a <= tf_reg_a;
end
// don't optimize the following instanced stuff:
cc_mux8 muxshadr (.s(shad_cycle), .i0i(st_r), .i1i(st_reg_r), .z(shade_r));
cc_mux8 muxshadg (.s(shad_cycle), .i0i(st_g), .i1i(st_reg_g), .z(shade_g));
cc_mux8 muxshadb (.s(shad_cycle), .i0i(st_b), .i1i(st_reg_b), .z(shade_b));
cc_mux8 muxshada (.s(shad_cycle), .i0i(st_a), .i1i(st_reg_a), .z(shade_a));
cc_mux9 muxtex0r (.s(tex0_cycle), .i0i(tf_reg_r), .i1i(tf_rg2_r), .z(tex_0_r));
cc_mux9 muxtex0g (.s(tex0_cycle), .i0i(tf_reg_g), .i1i(tf_rg2_g), .z(tex_0_g));
cc_mux9 muxtex0b (.s(tex0_cycle), .i0i(tf_reg_b), .i1i(tf_rg2_b), .z(tex_0_b));
cc_mux9 muxtex0a (.s(tex0_cycle), .i0i(tf_reg_a), .i1i(tf_rg2_a), .z(tex_0_a));
cc_mux9 muxtex1r (.s(tex1_cycle), .i0i(tf_r), .i1i(tf_reg_r), .z(tex_1_r));
cc_mux9 muxtex1g (.s(tex1_cycle), .i0i(tf_g), .i1i(tf_reg_g), .z(tex_1_g));
cc_mux9 muxtex1b (.s(tex1_cycle), .i0i(tf_b), .i1i(tf_reg_b), .z(tex_1_b));
cc_mux9 muxtex1a (.s(tex1_cycle), .i0i(tf_a), .i1i(tf_reg_a), .z(tex_1_a));
cc_mxxr muxxr (.s(cc_x_sel_reg_rgb), .i0i(cc_r[16:8]),
.i1i(tex_0_r),
.i2i(tex_1_r),
.i3i({1'b0,prim_r}),
.i4i({1'b0,shade_r}),
.i5i({1'b0,env_r}),
.i6i(noise),
.i7i(9'b100000000), .z(r_x));
cc_mxxr muxxg (.s(cc_x_sel_reg_rgb), .i0i(cc_g[16:8]),
.i1i(tex_0_g),
.i2i(tex_1_g),
.i3i({1'b0,prim_g}),
.i4i({1'b0,shade_g}),
.i5i({1'b0,env_g}),
.i6i(noise),
.i7i(9'b100000000), .z(g_x));
cc_mxxr muxxb (.s(cc_x_sel_reg_rgb), .i0i(cc_b[16:8]),
.i1i(tex_0_b),
.i2i(tex_1_b),
.i3i({1'b0,prim_b}),
.i4i({1'b0,shade_b}),
.i5i({1'b0,env_b}),
.i6i(noise),
.i7i(9'b100000000), .z(b_x));
cc_mxxa muxxa (.s(cc_x_sel_reg_alf), .i0i(cc_a[16:8]),
.i1i(tex_0_a),
.i2i(tex_1_a),
.i3i({1'b0,prim_a}),
.i4i({1'b0,shade_a}),
.i5i({1'b0,env_a}),
.i6i(9'b100000000),
.i7i(9'b000000000), .z(a_x));
cc_mxyr muxyr (.s(cc_y_sel_reg_rgb), .i0i(cc_r[16:8]),
.i1i(tex_0_r),
.i2i(tex_1_r),
.i3i({1'b0,prim_r}),
.i4i({1'b0,shade_r}),
.i5i({1'b0,env_r}),
.i6i({1'b0,center_r}),
.i7i(k4_coeff), .z(r_y));
cc_mxyr muxyg (.s(cc_y_sel_reg_rgb), .i0i(cc_g[16:8]),
.i1i(tex_0_g),
.i2i(tex_1_g),
.i3i({1'b0,prim_g}),
.i4i({1'b0,shade_g}),
.i5i({1'b0,env_g}),
.i6i({1'b0,center_g}),
.i7i(k4_coeff), .z(g_y));
cc_mxyr muxyb (.s(cc_y_sel_reg_rgb), .i0i(cc_b[16:8]),
.i1i(tex_0_b),
.i2i(tex_1_b),
.i3i({1'b0,prim_b}),
.i4i({1'b0,shade_b}),
.i5i({1'b0,env_b}),
.i6i({1'b0,center_b}),
.i7i(k4_coeff), .z(b_y));
cc_mxya muxya (.s(cc_y_sel_reg_alf), .i0i(cc_a[16:8]),
.i1i(tex_0_a),
.i2i(tex_1_a),
.i3i({1'b0,prim_a}),
.i4i({1'b0,shade_a}),
.i5i({1'b0,env_a}),
.i6i(9'b100000000),
.i7i(9'b000000000), .z(a_y));
cc_mxar muxar (.s(cc_a_sel_reg_rgb), .i0i(cc_r[16:8]),
.i1i(tex_0_r),
.i2i(tex_1_r),
.i3i({1'b0,prim_r}),
.i4i({1'b0,shade_r}),
.i5i({1'b0,env_r}),
.i6i({1'b0,scale_r}),
.i7i(cc_a[16:8]),
.i8i(tex_0_a),
.i9i(tex_1_a),
.iai({1'b0,prim_a}),
.ibi({1'b0,shade_a}),
.ici({1'b0,env_a}),
.idi(lod_frac),
.iei(prim_lod_frac),
.ifi(k5_coeff), .z(r_a));
cc_mxar muxag (.s(cc_a_sel_reg_rgb), .i0i(cc_g[16:8]),
.i1i(tex_0_g),
.i2i(tex_1_g),
.i3i({1'b0,prim_g}),
.i4i({1'b0,shade_g}),
.i5i({1'b0,env_g}),
.i6i({1'b0,scale_g}),
.i7i(cc_a[16:8]),
.i8i(tex_0_a),
.i9i(tex_1_a),
.iai({1'b0,prim_a}),
.ibi({1'b0,shade_a}),
.ici({1'b0,env_a}),
.idi(lod_frac),
.iei(prim_lod_frac),
.ifi(k5_coeff), .z(g_a));
cc_mxar muxab (.s(cc_a_sel_reg_rgb), .i0i(cc_b[16:8]),
.i1i(tex_0_b),
.i2i(tex_1_b),
.i3i({1'b0,prim_b}),
.i4i({1'b0,shade_b}),
.i5i({1'b0,env_b}),
.i6i({1'b0,scale_b}),
.i7i(cc_a[16:8]),
.i8i(tex_0_a),
.i9i(tex_1_a),
.iai({1'b0,prim_a}),
.ibi({1'b0,shade_a}),
.ici({1'b0,env_a}),
.idi(lod_frac),
.iei(prim_lod_frac),
.ifi(k5_coeff), .z(b_a));
cc_mxaa muxaa (.s(cc_a_sel_reg_alf), .i0i(tex_0_a),
.i1i(tex_1_a),
.i2i({1'b0,prim_a}),
.i3i({1'b0,shade_a}),
.i4i({1'b0,env_a}),
.i5i(lod_frac),
.i6i(prim_lod_frac),
.i7i(9'b000000000), .z(a_a));
cc_mxcr muxcr (.s(cc_c_sel_reg_rgb), .i0i(cc_r[16:8]),
.i1i(tex_0_r),
.i2i(tex_1_r),
.i3i({1'b0,prim_r}),
.i4i({1'b0,shade_r}),
.i5i({1'b0,env_r}),
.i6i(9'b100000000),
.i7i(9'b000000000), .z(r_c));
cc_mxcr muxcg (.s(cc_c_sel_reg_rgb), .i0i(cc_g[16:8]),
.i1i(tex_0_g),
.i2i(tex_1_g),
.i3i({1'b0,prim_g}),
.i4i({1'b0,shade_g}),
.i5i({1'b0,env_g}),
.i6i(9'b100000000),
.i7i(9'b000000000), .z(g_c));
cc_mxcr muxcb (.s(cc_c_sel_reg_rgb), .i0i(cc_b[16:8]),
.i1i(tex_0_b),
.i2i(tex_1_b),
.i3i({1'b0,prim_b}),
.i4i({1'b0,shade_b}),
.i5i({1'b0,env_b}),
.i6i(9'b100000000),
.i7i(9'b000000000), .z(b_c));
cc_mxca muxca (.s(cc_c_sel_reg_alf), .i0i(cc_a[16:8]),
.i1i(tex_0_a),
.i2i(tex_1_a),
.i3i({1'b0,prim_a}),
.i4i({1'b0,shade_a}),
.i5i({1'b0,env_a}),
.i6i(9'b100000000),
.i7i(9'b000000000), .z(a_c));
cc_lerp cclerpr (.x(r_x), .y(r_y), .a(r_a), .c(r_c), .mp(r_mp));
cc_lerp cclerpg (.x(g_x), .y(g_y), .a(g_a), .c(g_c), .mp(g_mp));
cc_lerp cclerpb (.x(b_x), .y(b_y), .a(b_a), .c(b_c), .mp(b_mp));
cc_lerp cclerpa (.x(a_x), .y(a_y), .a(a_a), .c(a_c), .mp(a_mp));
always @(posedge gclk)
begin
key_cycle <= shad_cycle;
cc_r <= r_mp;
cc_g <= g_mp;
cc_b <= b_mp;
cc_a <= a_mp;
r_x_reg <= r_x;
g_x_reg <= g_x;
b_x_reg <= b_x;
end
// don't optimize the following instanced stuff:
// for now:
assign key_mux = 9'b000000000;
always @(posedge gclk)
begin
// force_zero_a = cc_a[16] & cc_a[15];
// pre_clamp_a = cc_a[15:8] & {8{(~force_zero_a)}};
// force_one_a = cc_a[16] & (~(cc_a[15]));
// clamp_a = pre_clamp_a | {8{force_one_a}};
case (cc_a[16:15])
2'b00: clamp_a = cc_a[15:8];
2'b01: clamp_a = cc_a[15:8];
2'b10: clamp_a = 8'b11111111;
2'b11: clamp_a = 8'b00000000;
default: clamp_a = 'bx;
endcase
alpha_cvg = antialias_en ? {cvg,5'b00000} : {1'b0,clamp_a};
key_sel = key_cycle && key_en;
key_r = key_sel ? r_x_reg : cc_r[16:8];
key_g = key_sel ? g_x_reg : cc_g[16:8];
key_b = key_sel ? b_x_reg : cc_b[16:8];
key_a = key_sel ? key_mux : alpha_cvg;
// force_zero_r = key_r[8] & key_r[7];
// pre_clamp_r = key_r[7:0] & {8{(~force_zero_r)}};
// force_one_r = key_r[8] & (~(key_r[7]));
// clamp_r = pre_clamp_r | {8{force_one_r}};
case (key_r[8:7])
2'b00: clamp_r = key_r[7:0];
2'b01: clamp_r = key_r[7:0];
2'b10: clamp_r = 8'b11111111;
2'b11: clamp_r = 8'b00000000;
default: clamp_r = 'bx;
endcase
// force_zero_g = key_g[8] & key_g[7];
// pre_clamp_g = key_g[7:0] & {8{(~force_zero_g)}};
// force_one_g = key_g[8] & (~(key_g[7]));
// clamp_g = pre_clamp_g | {8{force_one_g}};
case (key_g[8:7])
2'b00: clamp_g = key_g[7:0];
2'b01: clamp_g = key_g[7:0];
2'b10: clamp_g = 8'b11111111;
2'b11: clamp_g = 8'b00000000;
default: clamp_g = 'bx;
endcase
// force_zero_b = key_b[8] & key_b[7];
// pre_clamp_b = key_b[7:0] & {8{(~force_zero_b)}};
// force_one_b = key_b[8] & (~(key_b[7]));
// clamp_b = pre_clamp_b | {8{force_one_b}};
case (key_b[8:7])
2'b00: clamp_b = key_b[7:0];
2'b01: clamp_b = key_b[7:0];
2'b10: clamp_b = 8'b11111111;
2'b11: clamp_b = 8'b00000000;
default: clamp_b = 'bx;
endcase
pixel_r <= clamp_r;
pixel_g <= clamp_g;
pixel_b <= clamp_b;
pixel_a <= key_a;
pixel_cvg <= cvg;
end
endmodule // cc