summaryrefslogtreecommitdiff
path: root/drivers/gles_common/batch_diagnose.inc
blob: 88a8792edb065b3b9b0477921b7a31d24b945b5f (plain)
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
void _debug_write_garbage() {
	// extremely slow, writes garbage over arrays to detect using
	// uninitialized in graphical output. Do not enable in normal use!!
#ifdef RASTERIZER_EXTRA_CHECKS
	int num_verts = MIN(bdata.vertices.max_size(), 32);
	for (int n = 0; n < num_verts; n++) {
		bdata.vertices[n].pos.set(Math::random(-200.0f, 200.0f), Math::random(-200.0f, 200.0f));
		bdata.vertices[n].uv.set(Math::random(0.0f, 1.0f), Math::random(0.0f, 1.0f));
	}

	int num_colors = MIN(bdata.vertex_colors.max_size(), 32);
	for (int n = 0; n < num_colors; n++) {
		bdata.vertex_colors[n].set(Math::randf(), Math::randf(), Math::randf(), 1.0f);
	}

	int num_modulates = MIN(bdata.vertex_modulates.max_size(), 32);
	for (int n = 0; n < num_modulates; n++) {
		bdata.vertex_modulates[n].set(Math::randf(), Math::randf(), Math::randf(), 1.0f);
	}

	int num_light_angles = MIN(bdata.light_angles.max_size(), 32);
	for (int n = 0; n < num_light_angles; n++) {
		bdata.light_angles[n] = Math::random(-3.0f, +3.0f);
	}

	int num_transforms = MIN(bdata.vertex_transforms.max_size(), 32);
	for (int n = 0; n < num_transforms; n++) {
		bdata.vertex_transforms[n].translate.set(Math::random(-200.0f, 200.0f), Math::random(-200.0f, 200.0f));
		bdata.vertex_transforms[n].basis[0].set(Math::random(-2.0f, 2.0f), Math::random(-2.0f, 2.0f));
		bdata.vertex_transforms[n].basis[1].set(Math::random(-2.0f, 2.0f), Math::random(-2.0f, 2.0f));
	}

	int num_unit_verts = MIN(bdata.unit_vertices.max_size(), 32);
	for (int n = 0; n < num_unit_verts; n++) {
		uint8_t *data = bdata.unit_vertices.get_unit(n);
		for (int b = 0; b > bdata.unit_vertices.get_unit_size_bytes(); b++) {
			data[b] = Math::random(0, 255);
		}
	}

#endif
}

String get_command_type_string(const RendererCanvasRender::Item::Command &p_command) const {
	String sz = "";

	switch (p_command.type) {
		default:
			break;
#ifdef GODOT_3
		case RendererCanvasRender::Item::Command::GD_TYPE_LINE: {
			sz = "l";
		} break;
		case RendererCanvasRender::Item::Command::GD_TYPE_POLYLINE: {
			sz = "PL";
		} break;
		case RendererCanvasRender::Item::Command::GD_TYPE_CIRCLE: {
			sz = "c";
		} break;
#endif
		case RendererCanvasRender::Item::Command::TYPE_RECT: {
			sz = "r";
		} break;
		case RendererCanvasRender::Item::Command::TYPE_NINEPATCH: {
			sz = "n";
		} break;
		case RendererCanvasRender::Item::Command::TYPE_PRIMITIVE: {
			sz = "PR";
		} break;
		case RendererCanvasRender::Item::Command::TYPE_POLYGON: {
			sz = "p";
		} break;
		case RendererCanvasRender::Item::Command::TYPE_MESH: {
			sz = "m";
		} break;
		case RendererCanvasRender::Item::Command::TYPE_MULTIMESH: {
			sz = "MM";
		} break;
		case RendererCanvasRender::Item::Command::TYPE_PARTICLES: {
			sz = "PA";
		} break;
		case RendererCanvasRender::Item::Command::TYPE_TRANSFORM: {
			sz = "t";

			// add a bit more info in debug build
			const RendererCanvasRender::Item::CommandTransform *transform = static_cast<const RendererCanvasRender::Item::CommandTransform *>(&p_command);
			const Transform2D &mat = transform->xform;

			sz += " ";
			sz += String(Variant(mat.elements[2]));
			sz += " ";
		} break;
		case RendererCanvasRender::Item::Command::TYPE_CLIP_IGNORE: {
			sz = "CI";
		} break;
	} // switch

	return sz;
}

void diagnose_batches(RendererCanvasRender::Item::Command *const *p_commands) {
	int num_batches = bdata.batches.size();

	BatchColor curr_color;
	curr_color.set(Color(-1, -1, -1, -1));
	bool first_color_change = true;

	for (int batch_num = 0; batch_num < num_batches; batch_num++) {
		const Batch &batch = bdata.batches[batch_num];
		bdata.frame_string += "\t\t\tbatch ";

		switch (batch.type) {
			case RasterizerStorageCommon::BT_POLY: {
				bdata.frame_string += "P ";
				bdata.frame_string += itos(batch.first_command) + "-";
				bdata.frame_string += itos(batch.num_commands);

				bdata.frame_string += " " + batch.color.to_string();

				if (batch.num_commands > 1) {
					bdata.frame_string += " MULTI";
				}
				if (curr_color != batch.color) {
					curr_color = batch.color;
					if (!first_color_change) {
						bdata.frame_string += " color";
					} else {
						first_color_change = false;
					}
				}
				bdata.frame_string += "\n";
			} break;
			case RasterizerStorageCommon::BT_LINE:
			case RasterizerStorageCommon::BT_LINE_AA: {
				bdata.frame_string += "L ";
				bdata.frame_string += itos(batch.first_command) + "-";
				bdata.frame_string += itos(batch.num_commands);

				bdata.frame_string += " " + batch.color.to_string();

				if (batch.num_commands > 1) {
					bdata.frame_string += " MULTI";
				}
				if (curr_color != batch.color) {
					curr_color = batch.color;
					if (!first_color_change) {
						bdata.frame_string += " color";
					} else {
						first_color_change = false;
					}
				}
				bdata.frame_string += "\n";
			} break;
			case RasterizerStorageCommon::BT_RECT: {
				bdata.frame_string += "R ";
				bdata.frame_string += itos(batch.first_command) + "-";
				bdata.frame_string += itos(batch.num_commands);

				int tex_id = (int)bdata.batch_textures[batch.batch_texture_id].RID_texture.get_id();
				bdata.frame_string += " [" + itos(batch.batch_texture_id) + " - " + itos(tex_id) + "]";

				bdata.frame_string += " " + batch.color.to_string();

				if (batch.num_commands > 1) {
					bdata.frame_string += " MULTI";
				}
				if (curr_color != batch.color) {
					curr_color = batch.color;
					if (!first_color_change) {
						bdata.frame_string += " color";
					} else {
						first_color_change = false;
					}
				}
				bdata.frame_string += "\n";
			} break;
			default: {
				bdata.frame_string += "D ";
				bdata.frame_string += itos(batch.first_command) + "-";
				bdata.frame_string += itos(batch.num_commands) + " ";

				int num_show = MIN(batch.num_commands, 16);
				for (int n = 0; n < num_show; n++) {
					const RendererCanvasRender::Item::Command &comm = *p_commands[batch.first_command + n];
					bdata.frame_string += get_command_type_string(comm) + " ";
				}

				bdata.frame_string += "\n";
			} break;
		}
	}
}