我对FPGA RAM有问题。我想在我的3D渲染器项目中进行Z缓冲。这涉及对存储器的一次读取和一次有条件的写入访问。
在一个周期中同时进行读取和写入会产生错误的图形结果(写入ram的数据显示在屏幕上)。当我等待3个周期时,图形结果正确。
when st_render =>
put_pixel_out_next <= '0';
depth_buf_in <= depth_buf_out;
if cnty <= render_rect_latch.y1 then
if cntx < render_rect_latch.x1 then
e0 := cross_product(cntx, cnty, triangle_latch(0), triangle_latch(1));
e1 := cross_product(cntx, cnty, triangle_latch(1), triangle_latch(2));
e2 := cross_product(cntx, cnty, triangle_latch(2), triangle_latch(0));
if e0 <= 0 and e1 <= 0 and e2 <= 0 then
depth := (e0 * depths_in.z + e1 * depths_in.x + e2 * depths_in.y) / area_in;
depth_buf_in <= unsigned(std_logic_vector(depth + 127))(15 downto 0); -- ram write
state_next <= st_wait_0;
end if;
cntx_next <= cntx + 1;
else
cntx_next <= render_rect_latch.x0;
cnty_next <= cnty + 1;
end if;
else
ready_out_next <= '1';
put_pixel_out_next <= '0';
state_next <= st_idle;
end if;
when st_wait_0 => -- good results with this delay
state_next <= st_wait_1;
when st_wait_1 =>
state_next <= st_wait_2;
when st_wait_2 =>
color_out <= (
r => std_logic_vector(depth_buf_out(7 downto 0) ), -- ram read
g => std_logic_vector(depth_buf_out(7 downto 0)),
b => std_logic_vector(depth_buf_out(7 downto 0))
);
put_pixel_out_next <= '1';
state_next <= st_render;
我读到读写可以在一个周期内完成。在这种FPGA架构中,是否存在大于一个周期的延迟?