1 |
6 |
Orka |
/*
|
2 |
|
|
ORSoC GFX accelerator core
|
3 |
|
|
Copyright 2012, ORSoC, Per Lenander, Anton Fosselius.
|
4 |
|
|
|
5 |
|
|
The Wishbone slave component accepts incoming register accesses and puts them in a FIFO queue
|
6 |
|
|
|
7 |
|
|
Loosely based on the vga lcds wishbone slave (LGPL) in orpsocv2 by Julius Baxter, julius@opencores.org
|
8 |
|
|
|
9 |
|
|
This file is part of orgfx.
|
10 |
|
|
|
11 |
|
|
orgfx is free software: you can redistribute it and/or modify
|
12 |
|
|
it under the terms of the GNU Lesser 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 |
|
|
orgfx 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 Lesser General Public License for more details.
|
20 |
|
|
|
21 |
|
|
You should have received a copy of the GNU Lesser General Public License
|
22 |
|
|
along with orgfx. If not, see <http://www.gnu.org/licenses/>.
|
23 |
|
|
|
24 |
|
|
*/
|
25 |
|
|
|
26 |
|
|
//synopsys translate_off
|
27 |
|
|
`include "timescale.v"
|
28 |
|
|
|
29 |
|
|
//synopsys translate_on
|
30 |
|
|
|
31 |
|
|
/*
|
32 |
|
|
This module acts as the main control interface of the orgfx core. It is built as a 32-bit wishbone slave interface with read and write capabilities.
|
33 |
|
|
|
34 |
|
|
The module has two states, wait and busy. The module enters busy state when a pipeline operation is triggered by a write to the control register.
|
35 |
|
|
|
36 |
|
|
In the busy state all incoming wishbone writes are queued up in a 64 item fifo. These will be processed in the order they were received when the module returns to wait state.
|
37 |
|
|
|
38 |
|
|
The module leaves the busy state and enters wait state when it receives an ack from the pipeline.
|
39 |
|
|
*/
|
40 |
|
|
module gfx_wbs(
|
41 |
|
|
clk_i, rst_i, adr_i, dat_i, dat_o, sel_i, we_i, stb_i, cyc_i, ack_o, rty_o, err_o, inta_o,
|
42 |
|
|
//src pixels
|
43 |
|
|
src_pixel0_x_o, src_pixel0_y_o, src_pixel1_x_o, src_pixel1_y_o,
|
44 |
|
|
// dest pixels
|
45 |
|
|
dest_pixel_x_o, dest_pixel_y_o, dest_pixel_z_o,
|
46 |
|
|
dest_pixel_id_o,
|
47 |
|
|
// matrix
|
48 |
|
|
aa_o, ab_o, ac_o, tx_o,
|
49 |
|
|
ba_o, bb_o, bc_o, ty_o,
|
50 |
|
|
ca_o, cb_o, cc_o, tz_o,
|
51 |
|
|
transform_point_o,
|
52 |
|
|
forward_point_o,
|
53 |
|
|
// clip pixels
|
54 |
|
|
clip_pixel0_x_o, clip_pixel0_y_o, clip_pixel1_x_o, clip_pixel1_y_o,
|
55 |
|
|
color0_o, color1_o, color2_o,
|
56 |
|
|
u0_o, v0_o, u1_o, v1_o, u2_o, v2_o,
|
57 |
|
|
a0_o, a1_o, a2_o,
|
58 |
|
|
target_base_o, target_size_x_o, target_size_y_o, tex0_base_o, tex0_size_x_o, tex0_size_y_o,
|
59 |
|
|
color_depth_o,
|
60 |
|
|
rect_write_o, line_write_o, triangle_write_o, curve_write_o, interpolate_o,
|
61 |
|
|
writer_sint_i, reader_sint_i,
|
62 |
|
|
|
63 |
|
|
pipeline_ack_i,
|
64 |
|
|
transform_ack_i,
|
65 |
|
|
|
66 |
|
|
texture_enable_o,
|
67 |
|
|
blending_enable_o,
|
68 |
|
|
global_alpha_o,
|
69 |
|
|
colorkey_enable_o,
|
70 |
|
|
colorkey_o,
|
71 |
|
|
clipping_enable_o,
|
72 |
|
|
inside_o,
|
73 |
|
|
zbuffer_enable_o,
|
74 |
|
|
zbuffer_base_o
|
75 |
|
|
);
|
76 |
|
|
|
77 |
|
|
// Load register addresses from gfx_params.v file
|
78 |
|
|
`include "gfx_params.v"
|
79 |
|
|
|
80 |
|
|
// Adjust these parameters in gfx_top!
|
81 |
|
|
parameter REG_ADR_HIBIT = 9;
|
82 |
|
|
parameter point_width = 16;
|
83 |
|
|
parameter subpixel_width = 16;
|
84 |
|
|
parameter fifo_depth = 10;
|
85 |
|
|
|
86 |
|
|
//
|
87 |
|
|
// inputs & outputs
|
88 |
|
|
//
|
89 |
|
|
|
90 |
|
|
// wishbone slave interface
|
91 |
|
|
input clk_i;
|
92 |
|
|
input rst_i;
|
93 |
|
|
input [REG_ADR_HIBIT:0] adr_i;
|
94 |
|
|
input [31:0] dat_i;
|
95 |
|
|
output reg [31:0] dat_o;
|
96 |
|
|
input [ 3:0] sel_i;
|
97 |
|
|
input we_i;
|
98 |
|
|
input stb_i;
|
99 |
|
|
input cyc_i;
|
100 |
|
|
output reg ack_o;
|
101 |
|
|
output reg rty_o;
|
102 |
|
|
output reg err_o;
|
103 |
|
|
output reg inta_o;
|
104 |
|
|
// source pixel
|
105 |
|
|
output [point_width-1:0] src_pixel0_x_o;
|
106 |
|
|
output [point_width-1:0] src_pixel0_y_o;
|
107 |
|
|
output [point_width-1:0] src_pixel1_x_o;
|
108 |
|
|
output [point_width-1:0] src_pixel1_y_o;
|
109 |
|
|
// dest pixel
|
110 |
|
|
output signed [point_width-1:-subpixel_width] dest_pixel_x_o;
|
111 |
|
|
output signed [point_width-1:-subpixel_width] dest_pixel_y_o;
|
112 |
|
|
output signed [point_width-1:-subpixel_width] dest_pixel_z_o;
|
113 |
|
|
output [1:0] dest_pixel_id_o;
|
114 |
|
|
// matrix
|
115 |
|
|
output signed [point_width-1:-subpixel_width] aa_o;
|
116 |
|
|
output signed [point_width-1:-subpixel_width] ab_o;
|
117 |
|
|
output signed [point_width-1:-subpixel_width] ac_o;
|
118 |
|
|
output signed [point_width-1:-subpixel_width] tx_o;
|
119 |
|
|
output signed [point_width-1:-subpixel_width] ba_o;
|
120 |
|
|
output signed [point_width-1:-subpixel_width] bb_o;
|
121 |
|
|
output signed [point_width-1:-subpixel_width] bc_o;
|
122 |
|
|
output signed [point_width-1:-subpixel_width] ty_o;
|
123 |
|
|
output signed [point_width-1:-subpixel_width] ca_o;
|
124 |
|
|
output signed [point_width-1:-subpixel_width] cb_o;
|
125 |
|
|
output signed [point_width-1:-subpixel_width] cc_o;
|
126 |
|
|
output signed [point_width-1:-subpixel_width] tz_o;
|
127 |
|
|
output transform_point_o;
|
128 |
|
|
output forward_point_o;
|
129 |
|
|
// clip pixel
|
130 |
|
|
output [point_width-1:0] clip_pixel0_x_o;
|
131 |
|
|
output [point_width-1:0] clip_pixel0_y_o;
|
132 |
|
|
output [point_width-1:0] clip_pixel1_x_o;
|
133 |
|
|
output [point_width-1:0] clip_pixel1_y_o;
|
134 |
|
|
|
135 |
|
|
output [31:0] color0_o;
|
136 |
|
|
output [31:0] color1_o;
|
137 |
|
|
output [31:0] color2_o;
|
138 |
|
|
|
139 |
|
|
output [point_width-1:0] u0_o;
|
140 |
|
|
output [point_width-1:0] v0_o;
|
141 |
|
|
output [point_width-1:0] u1_o;
|
142 |
|
|
output [point_width-1:0] v1_o;
|
143 |
|
|
output [point_width-1:0] u2_o;
|
144 |
|
|
output [point_width-1:0] v2_o;
|
145 |
|
|
|
146 |
|
|
output [7:0] a0_o;
|
147 |
|
|
output [7:0] a1_o;
|
148 |
|
|
output [7:0] a2_o;
|
149 |
|
|
|
150 |
|
|
output [31:2] target_base_o;
|
151 |
|
|
output [point_width-1:0] target_size_x_o;
|
152 |
|
|
output [point_width-1:0] target_size_y_o;
|
153 |
|
|
output [31:2] tex0_base_o;
|
154 |
|
|
output [point_width-1:0] tex0_size_x_o;
|
155 |
|
|
output [point_width-1:0] tex0_size_y_o;
|
156 |
|
|
|
157 |
|
|
output [1:0] color_depth_o;
|
158 |
|
|
|
159 |
|
|
output rect_write_o;
|
160 |
|
|
output line_write_o;
|
161 |
|
|
output triangle_write_o;
|
162 |
|
|
output curve_write_o;
|
163 |
|
|
output interpolate_o;
|
164 |
|
|
|
165 |
|
|
// status register inputs
|
166 |
|
|
input writer_sint_i; // system error interrupt request
|
167 |
|
|
input reader_sint_i; // system error interrupt request
|
168 |
|
|
|
169 |
|
|
// Pipeline feedback
|
170 |
|
|
input pipeline_ack_i; // operation done
|
171 |
|
|
input transform_ack_i; // transformation done
|
172 |
|
|
|
173 |
|
|
// fragment
|
174 |
|
|
output texture_enable_o;
|
175 |
|
|
// blender
|
176 |
|
|
output blending_enable_o;
|
177 |
|
|
output [7:0] global_alpha_o;
|
178 |
|
|
output colorkey_enable_o;
|
179 |
|
|
output [31:0] colorkey_o;
|
180 |
|
|
|
181 |
|
|
output clipping_enable_o;
|
182 |
|
|
output inside_o;
|
183 |
|
|
output zbuffer_enable_o;
|
184 |
|
|
|
185 |
|
|
output [31:2] zbuffer_base_o;
|
186 |
|
|
|
187 |
|
|
//
|
188 |
|
|
// variable declarations
|
189 |
|
|
//
|
190 |
|
|
|
191 |
|
|
wire [REG_ADR_HIBIT:0] REG_ADR = {adr_i[REG_ADR_HIBIT : 2], 2'b00};
|
192 |
|
|
|
193 |
|
|
// Declaration of local registers
|
194 |
|
|
reg [31:0] control_reg, status_reg, target_base_reg, tex0_base_reg;
|
195 |
|
|
reg [31:0] target_size_x_reg, target_size_y_reg, tex0_size_x_reg, tex0_size_y_reg;
|
196 |
|
|
reg [31:0] src_pixel_pos_0_x_reg, src_pixel_pos_0_y_reg, src_pixel_pos_1_x_reg, src_pixel_pos_1_y_reg;
|
197 |
|
|
reg [31:0] clip_pixel_pos_0_x_reg, clip_pixel_pos_0_y_reg, clip_pixel_pos_1_x_reg, clip_pixel_pos_1_y_reg;
|
198 |
|
|
reg signed [31:0] dest_pixel_pos_x_reg, dest_pixel_pos_y_reg, dest_pixel_pos_z_reg;
|
199 |
|
|
reg signed [31:0] aa_reg, ab_reg, ac_reg, tx_reg;
|
200 |
|
|
reg signed [31:0] ba_reg, bb_reg, bc_reg, ty_reg;
|
201 |
|
|
reg signed [31:0] ca_reg, cb_reg, cc_reg, tz_reg;
|
202 |
|
|
reg [31:0] color0_reg, color1_reg, color2_reg;
|
203 |
|
|
reg [31:0] u0_reg, v0_reg, u1_reg, v1_reg, u2_reg, v2_reg;
|
204 |
|
|
reg [31:0] alpha_reg;
|
205 |
|
|
reg [31:0] colorkey_reg;
|
206 |
|
|
reg [31:0] zbuffer_base_reg;
|
207 |
|
|
|
208 |
|
|
wire [1:0] active_point;
|
209 |
|
|
|
210 |
|
|
// Wishbone access wires
|
211 |
|
|
wire acc, acc32, reg_acc, reg_wacc;
|
212 |
|
|
|
213 |
|
|
// State machine variables
|
214 |
|
|
reg state;
|
215 |
|
|
parameter wait_state = 1'b0, busy_state = 1'b1;
|
216 |
|
|
|
217 |
|
|
//
|
218 |
|
|
// Module body
|
219 |
|
|
//
|
220 |
|
|
|
221 |
|
|
// wishbone access signals
|
222 |
|
|
assign acc = cyc_i & stb_i;
|
223 |
|
|
assign acc32 = (sel_i == 4'b1111);
|
224 |
|
|
assign reg_acc = acc & acc32;
|
225 |
|
|
assign reg_wacc = reg_acc & we_i;
|
226 |
|
|
|
227 |
|
|
// Generate wishbone ack
|
228 |
|
|
always @(posedge clk_i or posedge rst_i)
|
229 |
|
|
if(rst_i)
|
230 |
|
|
ack_o <= 1'b0;
|
231 |
|
|
else
|
232 |
|
|
ack_o <= reg_acc & acc32 & ~ack_o ;
|
233 |
|
|
|
234 |
|
|
// Generate wishbone rty
|
235 |
|
|
always @(posedge clk_i or posedge rst_i)
|
236 |
|
|
if(rst_i)
|
237 |
|
|
rty_o <= 1'b0;
|
238 |
|
|
else
|
239 |
|
|
rty_o <= 1'b0; //reg_acc & acc32 & ~rty_o ;
|
240 |
|
|
|
241 |
|
|
// Generate wishbone err
|
242 |
|
|
always @(posedge clk_i or posedge rst_i)
|
243 |
|
|
if(rst_i)
|
244 |
|
|
err_o <= 1'b0;
|
245 |
|
|
else
|
246 |
|
|
err_o <= acc & ~acc32 & ~err_o;
|
247 |
|
|
|
248 |
|
|
// generate interrupt request signal
|
249 |
|
|
always @(posedge clk_i or posedge rst_i)
|
250 |
|
|
if(rst_i)
|
251 |
|
|
inta_o <= 1'b0;
|
252 |
|
|
else
|
253 |
|
|
inta_o <= writer_sint_i | reader_sint_i; // | other_int | (int_enable & int) | ...
|
254 |
|
|
|
255 |
|
|
// generate registers
|
256 |
|
|
always @(posedge clk_i or posedge rst_i)
|
257 |
|
|
begin : gen_regs
|
258 |
|
|
if (rst_i)
|
259 |
|
|
begin
|
260 |
|
|
control_reg <= 32'h00000000;
|
261 |
|
|
target_base_reg <= 32'h00000000;
|
262 |
|
|
target_size_x_reg <= 32'h00000000;
|
263 |
|
|
target_size_y_reg <= 32'h00000000;
|
264 |
|
|
tex0_base_reg <= 32'h00000000;
|
265 |
|
|
tex0_size_x_reg <= 32'h00000000;
|
266 |
|
|
tex0_size_y_reg <= 32'h00000000;
|
267 |
|
|
src_pixel_pos_0_x_reg <= 32'h00000000;
|
268 |
|
|
src_pixel_pos_0_y_reg <= 32'h00000000;
|
269 |
|
|
src_pixel_pos_1_x_reg <= 32'h00000000;
|
270 |
|
|
src_pixel_pos_1_y_reg <= 32'h00000000;
|
271 |
|
|
dest_pixel_pos_x_reg <= 32'h00000000;
|
272 |
|
|
dest_pixel_pos_y_reg <= 32'h00000000;
|
273 |
|
|
dest_pixel_pos_z_reg <= 32'h00000000;
|
274 |
|
|
aa_reg <= $signed(1'b1 << subpixel_width);
|
275 |
|
|
ab_reg <= 32'h00000000;
|
276 |
|
|
ac_reg <= 32'h00000000;
|
277 |
|
|
tx_reg <= 32'h00000000;
|
278 |
|
|
ba_reg <= 32'h00000000;
|
279 |
|
|
bb_reg <= $signed(1'b1 << subpixel_width);
|
280 |
|
|
bc_reg <= 32'h00000000;
|
281 |
|
|
ty_reg <= 32'h00000000;
|
282 |
|
|
ca_reg <= 32'h00000000;
|
283 |
|
|
cb_reg <= 32'h00000000;
|
284 |
|
|
cc_reg <= $signed(1'b1 << subpixel_width);
|
285 |
|
|
tz_reg <= 32'h00000000;
|
286 |
|
|
clip_pixel_pos_0_x_reg <= 32'h00000000;
|
287 |
|
|
clip_pixel_pos_0_y_reg <= 32'h00000000;
|
288 |
|
|
clip_pixel_pos_1_x_reg <= 32'h00000000;
|
289 |
|
|
clip_pixel_pos_1_y_reg <= 32'h00000000;
|
290 |
|
|
color0_reg <= 32'h00000000;
|
291 |
|
|
color1_reg <= 32'h00000000;
|
292 |
|
|
color2_reg <= 32'h00000000;
|
293 |
|
|
u0_reg <= 32'h00000000;
|
294 |
|
|
v0_reg <= 32'h00000000;
|
295 |
|
|
u1_reg <= 32'h00000000;
|
296 |
|
|
v1_reg <= 32'h00000000;
|
297 |
|
|
u2_reg <= 32'h00000000;
|
298 |
|
|
v2_reg <= 32'h00000000;
|
299 |
|
|
alpha_reg <= 32'hffffffff;
|
300 |
|
|
colorkey_reg <= 32'h00000000;
|
301 |
|
|
zbuffer_base_reg <= 32'h00000000;
|
302 |
|
|
end
|
303 |
|
|
// Read fifo to write to registers
|
304 |
|
|
else if (instruction_fifo_rreq)
|
305 |
|
|
begin
|
306 |
|
|
case (instruction_fifo_q_adr) // synopsis full_case parallel_case
|
307 |
|
|
GFX_CONTROL : control_reg <= instruction_fifo_q_data;
|
308 |
|
|
GFX_TARGET_BASE : target_base_reg <= instruction_fifo_q_data;
|
309 |
|
|
GFX_TARGET_SIZE_X : target_size_x_reg <= instruction_fifo_q_data;
|
310 |
|
|
GFX_TARGET_SIZE_Y : target_size_y_reg <= instruction_fifo_q_data;
|
311 |
|
|
GFX_TEX0_BASE : tex0_base_reg <= instruction_fifo_q_data;
|
312 |
|
|
GFX_TEX0_SIZE_X : tex0_size_x_reg <= instruction_fifo_q_data;
|
313 |
|
|
GFX_TEX0_SIZE_Y : tex0_size_y_reg <= instruction_fifo_q_data;
|
314 |
|
|
GFX_SRC_PIXEL0_X : src_pixel_pos_0_x_reg <= instruction_fifo_q_data;
|
315 |
|
|
GFX_SRC_PIXEL0_Y : src_pixel_pos_0_y_reg <= instruction_fifo_q_data;
|
316 |
|
|
GFX_SRC_PIXEL1_X : src_pixel_pos_1_x_reg <= instruction_fifo_q_data;
|
317 |
|
|
GFX_SRC_PIXEL1_Y : src_pixel_pos_1_y_reg <= instruction_fifo_q_data;
|
318 |
|
|
GFX_DEST_PIXEL_X : dest_pixel_pos_x_reg <= $signed(instruction_fifo_q_data);
|
319 |
|
|
GFX_DEST_PIXEL_Y : dest_pixel_pos_y_reg <= $signed(instruction_fifo_q_data);
|
320 |
|
|
GFX_DEST_PIXEL_Z : dest_pixel_pos_z_reg <= $signed(instruction_fifo_q_data);
|
321 |
|
|
GFX_AA : aa_reg <= $signed(instruction_fifo_q_data);
|
322 |
|
|
GFX_AB : ab_reg <= $signed(instruction_fifo_q_data);
|
323 |
|
|
GFX_AC : ac_reg <= $signed(instruction_fifo_q_data);
|
324 |
|
|
GFX_TX : tx_reg <= $signed(instruction_fifo_q_data);
|
325 |
|
|
GFX_BA : ba_reg <= $signed(instruction_fifo_q_data);
|
326 |
|
|
GFX_BB : bb_reg <= $signed(instruction_fifo_q_data);
|
327 |
|
|
GFX_BC : bc_reg <= $signed(instruction_fifo_q_data);
|
328 |
|
|
GFX_TY : ty_reg <= $signed(instruction_fifo_q_data);
|
329 |
|
|
GFX_CA : ca_reg <= $signed(instruction_fifo_q_data);
|
330 |
|
|
GFX_CB : cb_reg <= $signed(instruction_fifo_q_data);
|
331 |
|
|
GFX_CC : cc_reg <= $signed(instruction_fifo_q_data);
|
332 |
|
|
GFX_TZ : tz_reg <= $signed(instruction_fifo_q_data);
|
333 |
|
|
GFX_CLIP_PIXEL0_X : clip_pixel_pos_0_x_reg <= instruction_fifo_q_data;
|
334 |
|
|
GFX_CLIP_PIXEL0_Y : clip_pixel_pos_0_y_reg <= instruction_fifo_q_data;
|
335 |
|
|
GFX_CLIP_PIXEL1_X : clip_pixel_pos_1_x_reg <= instruction_fifo_q_data;
|
336 |
|
|
GFX_CLIP_PIXEL1_Y : clip_pixel_pos_1_y_reg <= instruction_fifo_q_data;
|
337 |
|
|
GFX_COLOR0 : color0_reg <= instruction_fifo_q_data;
|
338 |
|
|
GFX_COLOR1 : color1_reg <= instruction_fifo_q_data;
|
339 |
|
|
GFX_COLOR2 : color2_reg <= instruction_fifo_q_data;
|
340 |
|
|
GFX_U0 : u0_reg <= instruction_fifo_q_data;
|
341 |
|
|
GFX_V0 : v0_reg <= instruction_fifo_q_data;
|
342 |
|
|
GFX_U1 : u1_reg <= instruction_fifo_q_data;
|
343 |
|
|
GFX_V1 : v1_reg <= instruction_fifo_q_data;
|
344 |
|
|
GFX_U2 : u2_reg <= instruction_fifo_q_data;
|
345 |
|
|
GFX_V2 : v2_reg <= instruction_fifo_q_data;
|
346 |
|
|
GFX_ALPHA : alpha_reg <= instruction_fifo_q_data;
|
347 |
|
|
GFX_COLORKEY : colorkey_reg <= instruction_fifo_q_data;
|
348 |
|
|
GFX_ZBUFFER_BASE : zbuffer_base_reg <= instruction_fifo_q_data;
|
349 |
|
|
endcase
|
350 |
|
|
end
|
351 |
|
|
else
|
352 |
|
|
begin
|
353 |
|
|
/* To prevent entering an infinite write cycle, the bits that start pipeline operations are cleared here */
|
354 |
|
|
control_reg[GFX_CTRL_RECT] <= 1'b0; // Reset rect write
|
355 |
|
|
control_reg[GFX_CTRL_LINE] <= 1'b0; // Reset line write
|
356 |
|
|
control_reg[GFX_CTRL_TRI] <= 1'b0; // Reset triangle write
|
357 |
|
|
// Reset matrix transformation bits
|
358 |
|
|
control_reg[GFX_CTRL_FORWARD_POINT] <= 1'b0;
|
359 |
|
|
control_reg[GFX_CTRL_TRANSFORM_POINT] <= 1'b0;
|
360 |
|
|
end
|
361 |
|
|
end
|
362 |
|
|
|
363 |
|
|
// generate status register
|
364 |
|
|
always @(posedge clk_i or posedge rst_i)
|
365 |
|
|
if (rst_i)
|
366 |
|
|
status_reg <= 32'h00000000;
|
367 |
|
|
else
|
368 |
|
|
begin
|
369 |
|
|
status_reg[GFX_STAT_BUSY] <= (state == busy_state);
|
370 |
|
|
status_reg[31:16] <= instruction_fifo_count;
|
371 |
|
|
end
|
372 |
|
|
|
373 |
|
|
// Assign target and texture signals
|
374 |
|
|
assign target_base_o = target_base_reg[31:2];
|
375 |
|
|
assign target_size_x_o = target_size_x_reg[point_width-1:0];
|
376 |
|
|
assign target_size_y_o = target_size_y_reg[point_width-1:0];
|
377 |
|
|
assign tex0_base_o = tex0_base_reg[31:2];
|
378 |
|
|
assign tex0_size_x_o = tex0_size_x_reg[point_width-1:0];
|
379 |
|
|
assign tex0_size_y_o = tex0_size_y_reg[point_width-1:0];
|
380 |
|
|
|
381 |
|
|
// Assign source pixel signals
|
382 |
|
|
assign src_pixel0_x_o = src_pixel_pos_0_x_reg[point_width-1:0];
|
383 |
|
|
assign src_pixel0_y_o = src_pixel_pos_0_y_reg[point_width-1:0];
|
384 |
|
|
assign src_pixel1_x_o = src_pixel_pos_1_x_reg[point_width-1:0];
|
385 |
|
|
assign src_pixel1_y_o = src_pixel_pos_1_y_reg[point_width-1:0];
|
386 |
|
|
// Assign clipping pixel signals
|
387 |
|
|
assign clip_pixel0_x_o = clip_pixel_pos_0_x_reg[point_width-1:0];
|
388 |
|
|
assign clip_pixel0_y_o = clip_pixel_pos_0_y_reg[point_width-1:0];
|
389 |
|
|
assign clip_pixel1_x_o = clip_pixel_pos_1_x_reg[point_width-1:0];
|
390 |
|
|
assign clip_pixel1_y_o = clip_pixel_pos_1_y_reg[point_width-1:0];
|
391 |
|
|
// Assign destination pixel signals
|
392 |
|
|
assign dest_pixel_x_o[point_width-1:-subpixel_width] = $signed(dest_pixel_pos_x_reg);
|
393 |
|
|
assign dest_pixel_y_o[point_width-1:-subpixel_width] = $signed(dest_pixel_pos_y_reg);
|
394 |
|
|
assign dest_pixel_z_o[point_width-1:-subpixel_width] = $signed(dest_pixel_pos_z_reg);
|
395 |
|
|
assign dest_pixel_id_o = active_point;
|
396 |
|
|
|
397 |
|
|
// Assign matrix signals
|
398 |
|
|
assign aa_o = $signed(aa_reg);
|
399 |
|
|
assign ab_o = $signed(ab_reg);
|
400 |
|
|
assign ac_o = $signed(ac_reg);
|
401 |
|
|
assign tx_o = $signed(tx_reg);
|
402 |
|
|
assign ba_o = $signed(ba_reg);
|
403 |
|
|
assign bb_o = $signed(bb_reg);
|
404 |
|
|
assign bc_o = $signed(bc_reg);
|
405 |
|
|
assign ty_o = $signed(ty_reg);
|
406 |
|
|
assign ca_o = $signed(ca_reg);
|
407 |
|
|
assign cb_o = $signed(cb_reg);
|
408 |
|
|
assign cc_o = $signed(cc_reg);
|
409 |
|
|
assign tz_o = $signed(tz_reg);
|
410 |
|
|
|
411 |
|
|
// Assign color signals
|
412 |
|
|
assign color0_o = color0_reg;
|
413 |
|
|
assign color1_o = color1_reg;
|
414 |
|
|
assign color2_o = color2_reg;
|
415 |
|
|
|
416 |
|
|
assign u0_o = u0_reg[point_width-1:0];
|
417 |
|
|
assign v0_o = v0_reg[point_width-1:0];
|
418 |
|
|
assign u1_o = u1_reg[point_width-1:0];
|
419 |
|
|
assign v1_o = v1_reg[point_width-1:0];
|
420 |
|
|
assign u2_o = u2_reg[point_width-1:0];
|
421 |
|
|
assign v2_o = v2_reg[point_width-1:0];
|
422 |
|
|
|
423 |
|
|
assign a0_o = alpha_reg[31:24];
|
424 |
|
|
assign a1_o = alpha_reg[23:16];
|
425 |
|
|
assign a2_o = alpha_reg[15:8];
|
426 |
|
|
assign global_alpha_o = alpha_reg[7:0];
|
427 |
|
|
assign colorkey_o = colorkey_reg;
|
428 |
|
|
assign zbuffer_base_o = zbuffer_base_reg[31:2];
|
429 |
|
|
|
430 |
|
|
|
431 |
|
|
|
432 |
|
|
// decode control register
|
433 |
|
|
assign color_depth_o = control_reg[GFX_CTRL_COLOR_DEPTH+1:GFX_CTRL_COLOR_DEPTH];
|
434 |
|
|
|
435 |
|
|
assign texture_enable_o = control_reg[GFX_CTRL_TEXTURE ];
|
436 |
|
|
assign blending_enable_o = control_reg[GFX_CTRL_BLENDING];
|
437 |
|
|
assign colorkey_enable_o = control_reg[GFX_CTRL_COLORKEY];
|
438 |
|
|
assign clipping_enable_o = control_reg[GFX_CTRL_CLIPPING];
|
439 |
|
|
assign zbuffer_enable_o = control_reg[GFX_CTRL_ZBUFFER ];
|
440 |
|
|
|
441 |
|
|
assign rect_write_o = control_reg[GFX_CTRL_RECT ];
|
442 |
|
|
assign line_write_o = control_reg[GFX_CTRL_LINE ];
|
443 |
|
|
assign triangle_write_o = control_reg[GFX_CTRL_TRI ];
|
444 |
|
|
assign curve_write_o = control_reg[GFX_CTRL_CURVE ];
|
445 |
|
|
assign interpolate_o = control_reg[GFX_CTRL_INTERP ];
|
446 |
|
|
assign inside_o = control_reg[GFX_CTRL_INSIDE ];
|
447 |
|
|
|
448 |
|
|
assign active_point = control_reg[GFX_CTRL_ACTIVE_POINT+1:GFX_CTRL_ACTIVE_POINT];
|
449 |
|
|
assign forward_point_o = control_reg[GFX_CTRL_FORWARD_POINT];
|
450 |
|
|
assign transform_point_o = control_reg[GFX_CTRL_TRANSFORM_POINT];
|
451 |
|
|
|
452 |
|
|
// decode status register TODO
|
453 |
|
|
|
454 |
|
|
// assign output from wishbone reads. Note that this does not account for pending writes in the fifo!
|
455 |
|
|
always @(posedge clk_i or posedge rst_i)
|
456 |
|
|
if(rst_i)
|
457 |
|
|
dat_o <= 32'h0000_0000;
|
458 |
|
|
else
|
459 |
|
|
case (REG_ADR) // synopsis full_case parallel_case
|
460 |
|
|
GFX_CONTROL : dat_o <= control_reg;
|
461 |
|
|
GFX_STATUS : dat_o <= status_reg;
|
462 |
|
|
GFX_TARGET_BASE : dat_o <= target_base_reg;
|
463 |
|
|
GFX_TARGET_SIZE_X : dat_o <= target_size_x_reg;
|
464 |
|
|
GFX_TARGET_SIZE_Y : dat_o <= target_size_y_reg;
|
465 |
|
|
GFX_TEX0_BASE : dat_o <= tex0_base_reg;
|
466 |
|
|
GFX_TEX0_SIZE_X : dat_o <= tex0_size_x_reg;
|
467 |
|
|
GFX_TEX0_SIZE_Y : dat_o <= tex0_size_y_reg;
|
468 |
|
|
GFX_SRC_PIXEL0_X : dat_o <= src_pixel_pos_0_x_reg;
|
469 |
|
|
GFX_SRC_PIXEL0_Y : dat_o <= src_pixel_pos_0_y_reg;
|
470 |
|
|
GFX_SRC_PIXEL1_X : dat_o <= src_pixel_pos_1_x_reg;
|
471 |
|
|
GFX_SRC_PIXEL1_Y : dat_o <= src_pixel_pos_1_y_reg;
|
472 |
|
|
GFX_DEST_PIXEL_X : dat_o <= dest_pixel_pos_x_reg;
|
473 |
|
|
GFX_DEST_PIXEL_Y : dat_o <= dest_pixel_pos_y_reg;
|
474 |
|
|
GFX_DEST_PIXEL_Z : dat_o <= dest_pixel_pos_z_reg;
|
475 |
|
|
GFX_AA : dat_o <= aa_reg;
|
476 |
|
|
GFX_AB : dat_o <= ab_reg;
|
477 |
|
|
GFX_AC : dat_o <= ac_reg;
|
478 |
|
|
GFX_TX : dat_o <= tx_reg;
|
479 |
|
|
GFX_BA : dat_o <= ba_reg;
|
480 |
|
|
GFX_BB : dat_o <= bb_reg;
|
481 |
|
|
GFX_BC : dat_o <= bc_reg;
|
482 |
|
|
GFX_TY : dat_o <= ty_reg;
|
483 |
|
|
GFX_CA : dat_o <= ca_reg;
|
484 |
|
|
GFX_CB : dat_o <= cb_reg;
|
485 |
|
|
GFX_CC : dat_o <= cc_reg;
|
486 |
|
|
GFX_TZ : dat_o <= tz_reg;
|
487 |
|
|
GFX_CLIP_PIXEL0_X : dat_o <= clip_pixel_pos_0_x_reg;
|
488 |
|
|
GFX_CLIP_PIXEL0_Y : dat_o <= clip_pixel_pos_0_y_reg;
|
489 |
|
|
GFX_CLIP_PIXEL1_X : dat_o <= clip_pixel_pos_1_x_reg;
|
490 |
|
|
GFX_CLIP_PIXEL1_Y : dat_o <= clip_pixel_pos_1_y_reg;
|
491 |
|
|
GFX_COLOR0 : dat_o <= color0_reg;
|
492 |
|
|
GFX_COLOR1 : dat_o <= color1_reg;
|
493 |
|
|
GFX_COLOR2 : dat_o <= color2_reg;
|
494 |
|
|
GFX_U0 : dat_o <= u0_reg;
|
495 |
|
|
GFX_V0 : dat_o <= v0_reg;
|
496 |
|
|
GFX_U1 : dat_o <= u1_reg;
|
497 |
|
|
GFX_V1 : dat_o <= v1_reg;
|
498 |
|
|
GFX_U2 : dat_o <= u2_reg;
|
499 |
|
|
GFX_V2 : dat_o <= v2_reg;
|
500 |
|
|
GFX_ALPHA : dat_o <= alpha_reg;
|
501 |
|
|
GFX_COLORKEY : dat_o <= colorkey_reg;
|
502 |
|
|
GFX_ZBUFFER_BASE : dat_o <= zbuffer_base_reg;
|
503 |
|
|
default : dat_o <= 32'h0000_0000;
|
504 |
|
|
endcase
|
505 |
|
|
|
506 |
|
|
// State machine
|
507 |
|
|
always @(posedge clk_i or posedge rst_i)
|
508 |
|
|
if(rst_i)
|
509 |
|
|
state <= wait_state;
|
510 |
|
|
else
|
511 |
|
|
case (state)
|
512 |
|
|
wait_state:
|
513 |
|
|
// Signals that trigger pipeline operations
|
514 |
|
|
if(rect_write_o | line_write_o | triangle_write_o |
|
515 |
|
|
forward_point_o | transform_point_o)
|
516 |
|
|
state <= busy_state;
|
517 |
|
|
|
518 |
|
|
busy_state:
|
519 |
|
|
// If a pipeline operation is finished, go back to wait state
|
520 |
|
|
if(pipeline_ack_i | transform_ack_i)
|
521 |
|
|
state <= wait_state;
|
522 |
|
|
endcase
|
523 |
|
|
|
524 |
|
|
/* Instruction fifo */
|
525 |
|
|
wire instruction_fifo_wreq;
|
526 |
|
|
wire [31:0] instruction_fifo_q_data;
|
527 |
|
|
wire instruction_fifo_rreq;
|
528 |
|
|
wire instruction_fifo_valid_out;
|
529 |
|
|
reg fifo_read_ack;
|
530 |
|
|
reg fifo_write_ack;
|
531 |
|
|
wire [REG_ADR_HIBIT:0] instruction_fifo_q_adr;
|
532 |
|
|
wire [fifo_depth:0] instruction_fifo_count;
|
533 |
|
|
|
534 |
|
|
always @(posedge clk_i or posedge rst_i)
|
535 |
|
|
if(rst_i)
|
536 |
|
|
fifo_read_ack <= 1'b0;
|
537 |
|
|
else
|
538 |
|
|
fifo_read_ack <= instruction_fifo_rreq & !fifo_read_ack;
|
539 |
|
|
|
540 |
|
|
wire ready_next_cycle = (state == wait_state) & ~rect_write_o & ~line_write_o & ~triangle_write_o & ~forward_point_o & ~transform_point_o;
|
541 |
|
|
assign instruction_fifo_rreq = instruction_fifo_valid_out & ~fifo_read_ack & ready_next_cycle;
|
542 |
|
|
|
543 |
|
|
always @(posedge clk_i or posedge rst_i)
|
544 |
|
|
if(rst_i)
|
545 |
|
|
fifo_write_ack <= 1'b0;
|
546 |
|
|
else
|
547 |
|
|
fifo_write_ack <= instruction_fifo_wreq ? !fifo_write_ack : reg_wacc;
|
548 |
|
|
|
549 |
|
|
assign instruction_fifo_wreq = reg_wacc & ~fifo_write_ack;
|
550 |
|
|
|
551 |
|
|
// TODO: 1024 places large enough?
|
552 |
|
|
basic_fifo instruction_fifo(
|
553 |
|
|
.clk_i ( clk_i ),
|
554 |
|
|
.rst_i ( rst_i ),
|
555 |
|
|
|
556 |
|
|
.data_i ( {REG_ADR, dat_i} ),
|
557 |
|
|
.enq_i ( instruction_fifo_wreq ),
|
558 |
|
|
.full_o ( ), // TODO: use?
|
559 |
|
|
.count_o ( instruction_fifo_count ),
|
560 |
|
|
|
561 |
|
|
.data_o ( {instruction_fifo_q_adr, instruction_fifo_q_data} ),
|
562 |
|
|
.valid_o ( instruction_fifo_valid_out ),
|
563 |
|
|
.deq_i ( instruction_fifo_rreq )
|
564 |
|
|
);
|
565 |
|
|
|
566 |
|
|
defparam instruction_fifo.fifo_width = REG_ADR_HIBIT+1+32;
|
567 |
|
|
defparam instruction_fifo.fifo_bit_depth = fifo_depth;
|
568 |
|
|
|
569 |
|
|
endmodule
|
570 |
|
|
|
571 |
|
|
|
572 |
|
|
|