Skip to content

Commit f063aec

Browse files
committed
vpr: Encapsulate block color drawing state
The drawing code now directly looks-up the default block color based on the placement state. This avoids having to synchronize it manually and fixes a crash when graphics is turned off.
1 parent ee51cbe commit f063aec

File tree

4 files changed

+46
-36
lines changed

4 files changed

+46
-36
lines changed

vpr/src/draw/draw.cpp

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -499,11 +499,6 @@ void update_screen(ScreenUpdatePriority priority, const char* msg, enum pic_type
499499
}
500500
}
501501

502-
//Block placements may have changed since previous invocation,
503-
//so we need to update the block colors in case blocks have changed
504-
//the tiles where they are implemented
505-
draw_reset_blk_colors();
506-
507502
if (draw_state->show_graphics) {
508503
application.update_message(msg);
509504
application.refresh_drawing();
@@ -830,7 +825,8 @@ void alloc_draw_structs(const t_arch* arch) {
830825
draw_internal_alloc_blk();
831826

832827
draw_state->net_color.resize(cluster_ctx.clb_nlist.nets().size());
833-
draw_state->block_color.resize(cluster_ctx.clb_nlist.blocks().size());
828+
draw_state->block_color_.resize(cluster_ctx.clb_nlist.blocks().size());
829+
draw_state->use_default_block_color_.resize(cluster_ctx.clb_nlist.blocks().size());
834830

835831
/* Space is allocated for draw_rr_node but not initialized because we do *
836832
* not yet know information about the routing resources. */
@@ -968,7 +964,7 @@ static void drawplace(ezgl::renderer* g) {
968964
ezgl::color block_color;
969965
t_logical_block_type_ptr logical_block_type = nullptr;
970966
if (bnum != EMPTY_BLOCK_ID) {
971-
block_color = draw_state->block_color[bnum];
967+
block_color = draw_state->block_color(bnum);
972968
logical_block_type = cluster_ctx.clb_nlist.block_type(bnum);
973969
} else {
974970
block_color = get_block_type_color(device_ctx.grid[i][j].type);
@@ -2675,7 +2671,7 @@ void draw_highlight_blocks_color(t_logical_block_type_ptr type, ClusterBlockId b
26752671
iclass = physical_tile->pin_class[physical_pin];
26762672

26772673
if (physical_tile->class_inf[iclass].type == DRIVER) { /* Fanout */
2678-
if (draw_state->block_color[blk_id] == SELECTED_COLOR) {
2674+
if (draw_state->block_color(blk_id) == SELECTED_COLOR) {
26792675
/* If block already highlighted, de-highlight the fanout. (the deselect case)*/
26802676
draw_state->net_color[net_id] = ezgl::BLACK;
26812677
for (auto pin_id : cluster_ctx.clb_nlist.net_sinks(net_id)) {
@@ -2687,11 +2683,11 @@ void draw_highlight_blocks_color(t_logical_block_type_ptr type, ClusterBlockId b
26872683
draw_state->net_color[net_id] = DRIVES_IT_COLOR;
26882684
for (auto pin_id : cluster_ctx.clb_nlist.net_sinks(net_id)) {
26892685
fanblk = cluster_ctx.clb_nlist.pin_block(pin_id);
2690-
draw_state->block_color[fanblk] = DRIVES_IT_COLOR;
2686+
draw_state->set_block_color(fanblk, DRIVES_IT_COLOR);
26912687
}
26922688
}
26932689
} else { /* This net is fanin to the block. */
2694-
if (draw_state->block_color[blk_id] == SELECTED_COLOR) {
2690+
if (draw_state->block_color(blk_id) == SELECTED_COLOR) {
26952691
/* If block already highlighted, de-highlight the fanin. (the deselect case)*/
26962692
draw_state->net_color[net_id] = ezgl::BLACK;
26972693
fanblk = cluster_ctx.clb_nlist.net_driver_block(net_id); /* DRIVER to net */
@@ -2700,17 +2696,17 @@ void draw_highlight_blocks_color(t_logical_block_type_ptr type, ClusterBlockId b
27002696
/* Highlight the fanin */
27012697
draw_state->net_color[net_id] = DRIVEN_BY_IT_COLOR;
27022698
fanblk = cluster_ctx.clb_nlist.net_driver_block(net_id); /* DRIVER to net */
2703-
draw_state->block_color[fanblk] = DRIVEN_BY_IT_COLOR;
2699+
draw_state->set_block_color(fanblk, DRIVEN_BY_IT_COLOR);
27042700
}
27052701
}
27062702
}
27072703

2708-
if (draw_state->block_color[blk_id] == SELECTED_COLOR) {
2704+
if (draw_state->block_color(blk_id) == SELECTED_COLOR) {
27092705
/* If block already highlighted, de-highlight the selected block. */
27102706
draw_reset_blk_color(blk_id);
27112707
} else {
27122708
/* Highlight the selected block. */
2713-
draw_state->block_color[blk_id] = SELECTED_COLOR;
2709+
draw_state->set_block_color(blk_id, SELECTED_COLOR);
27142710
}
27152711
}
27162712

@@ -2740,26 +2736,7 @@ void deselect_all() {
27402736

27412737
static void draw_reset_blk_color(ClusterBlockId blk_id) {
27422738
t_draw_state* draw_state = get_draw_state_vars();
2743-
2744-
auto& place_ctx = g_vpr_ctx.placement();
2745-
2746-
t_physical_tile_type_ptr tile_type = nullptr;
2747-
if (place_ctx.block_locs.empty()) {
2748-
//No placement, use best guess tile type color
2749-
auto& cluster_ctx = g_vpr_ctx.clustering();
2750-
2751-
tile_type = pick_best_physical_type(cluster_ctx.clb_nlist.block_type(blk_id));
2752-
} else {
2753-
//Color the block to match the tile where it is placed
2754-
auto& device_ctx = g_vpr_ctx.device();
2755-
auto& grid = device_ctx.grid;
2756-
2757-
t_pl_loc loc = place_ctx.block_locs[blk_id].loc;
2758-
2759-
tile_type = grid[loc.x][loc.y].type;
2760-
}
2761-
2762-
draw_state->block_color[blk_id] = get_block_type_color(tile_type);
2739+
draw_state->reset_block_color(blk_id);
27632740
}
27642741

27652742
/**
@@ -3360,7 +3337,7 @@ static void draw_block_pin_util() {
33603337

33613338
for (auto blk : blks) {
33623339
ezgl::color color = to_ezgl_color(cmap->color(pin_util[blk]));
3363-
draw_state->block_color[blk] = color;
3340+
draw_state->set_block_color(blk, color);
33643341
}
33653342

33663343
draw_state->color_map = std::move(cmap);

vpr/src/draw/draw_types.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,34 @@
44
# include "draw_types.h"
55
# include "globals.h"
66
# include "vpr_utils.h"
7+
# include "draw.h"
78
# include <utility>
89

910
/*******************************************
1011
* begin t_draw_state function definitions *
1112
*******************************************/
13+
ezgl::color t_draw_state::block_color(ClusterBlockId blk) const {
14+
if (use_default_block_color_[blk]) {
15+
t_physical_tile_type_ptr tile_type = get_physical_tile_type(blk);
16+
return get_block_type_color(tile_type);
17+
} else {
18+
return block_color_[blk];
19+
}
20+
}
21+
22+
void t_draw_state::set_block_color(ClusterBlockId blk, ezgl::color color) {
23+
block_color_[blk] = color;
24+
use_default_block_color_[blk] = false;
25+
}
26+
27+
void t_draw_state::reset_block_color(ClusterBlockId blk) {
28+
use_default_block_color_[blk] = true;
29+
}
30+
void t_draw_state::reset_block_colors() {
31+
std::fill(use_default_block_color_.begin(),
32+
use_default_block_color_.end(),
33+
true);
34+
}
1235

1336
void t_draw_state::reset_nets_congestion_and_rr() {
1437
show_nets = DRAW_NO_NETS;
@@ -19,6 +42,7 @@ void t_draw_state::reset_nets_congestion_and_rr() {
1942
bool t_draw_state::showing_sub_blocks() {
2043
return show_blk_internal > 0;
2144
}
45+
2246
/**************************************************
2347
* begin t_draw_pb_type_info function definitions *
2448
**************************************************/

vpr/src/draw/draw_types.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ struct t_draw_state {
172172
e_route_type draw_route_type = GLOBAL;
173173
char default_message[vtr::bufsize];
174174
vtr::vector<ClusterNetId, ezgl::color> net_color;
175-
vtr::vector<ClusterBlockId, ezgl::color> block_color;
176175
t_draw_rr_node* draw_rr_node = nullptr;
177176
std::shared_ptr<const SetupTimingInfo> setup_timing_info;
178177
const t_arch* arch_info = nullptr;
@@ -185,6 +184,16 @@ struct t_draw_state {
185184
void reset_nets_congestion_and_rr();
186185

187186
bool showing_sub_blocks();
187+
188+
ezgl::color block_color(ClusterBlockId blk) const;
189+
void set_block_color(ClusterBlockId blk, ezgl::color color);
190+
void reset_block_color(ClusterBlockId blk);
191+
void reset_block_colors();
192+
193+
private:
194+
friend void alloc_draw_structs(const t_arch* arch);
195+
vtr::vector<ClusterBlockId, ezgl::color> block_color_;
196+
vtr::vector<ClusterBlockId, bool> use_default_block_color_;
188197
};
189198

190199
/* For each cluster type, this structure stores drawing

vpr/src/draw/intra_logic_block.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ static void draw_internal_pb(const ClusterBlockId clb_index, t_pb* pb, const ezg
353353
} else if (sel_sub_info.is_source_of_selected(pb->pb_graph_node, clb_index)) {
354354
g->set_color(DRIVEN_BY_IT_COLOR);
355355
} else {
356-
g->set_color(draw_state->block_color[clb_index]);
356+
g->set_color(draw_state->block_color(clb_index));
357357
}
358358
} else {
359359
// If block is not used, draw as empty block (ie. white

0 commit comments

Comments
 (0)