1.3.72
 
Loading...
Searching...
No Matches
RayTracingTypes.cpp
Go to the documentation of this file.
1
16#include "RayTracingTypes.h"
17#include "global.h"
18#include <algorithm>
19#include <climits>
20
21namespace helios {
22
24#ifndef NDEBUG
25
26 // ========== UUID / Position Validation ==========
27
28 if (primitive_UUIDs.size() != primitive_count) {
29 helios_runtime_error("RayTracingGeometry validation failed: primitive_UUIDs.size()=" + std::to_string(primitive_UUIDs.size()) + " != primitive_count=" + std::to_string(primitive_count));
30 }
31
32 // UUID lookup table validation
33 // NOTE: primitive_positions now includes bbox UUIDs (safe due to bbox_UUID_base = max_UUID + 1)
34 if (!primitive_UUIDs.empty()) {
35 uint max_uuid = *std::max_element(primitive_UUIDs.begin(), primitive_UUIDs.end());
36
37 // Include bbox UUIDs in expected size if present
38 if (bbox_count > 0) {
39 uint bbox_max_uuid = bbox_UUID_base + bbox_count - 1;
40 if (bbox_max_uuid > max_uuid) {
41 max_uuid = bbox_max_uuid;
42 }
43 }
44
45 size_t expected_size = max_uuid + 1;
46
47 if (primitive_positions.size() != expected_size) {
48 helios_runtime_error("RayTracingGeometry validation failed: primitive_positions.size()=" + std::to_string(primitive_positions.size()) + " != max_UUID+1=" + std::to_string(expected_size) + " (max_UUID=" + std::to_string(max_uuid) +
49 ")");
50 }
51
52 // Validate UUID→position mapping consistency
53 for (size_t pos = 0; pos < primitive_UUIDs.size(); pos++) {
54 uint UUID = primitive_UUIDs[pos];
55
56 if (UUID >= primitive_positions.size()) {
57 helios_runtime_error("RayTracingGeometry validation failed: primitive_UUIDs[" + std::to_string(pos) + "]=" + std::to_string(UUID) + " >= primitive_positions.size()=" + std::to_string(primitive_positions.size()));
58 }
59
60 uint mapped_pos = primitive_positions[UUID];
61 if (mapped_pos == UINT_MAX) {
62 helios_runtime_error("RayTracingGeometry validation failed: primitive_positions[" + std::to_string(UUID) + "] == UINT_MAX (should map to position " + std::to_string(pos) + ")");
63 }
64
65 if (mapped_pos != pos) {
66 helios_runtime_error("RayTracingGeometry validation failed: primitive_positions[" + std::to_string(UUID) + "]=" + std::to_string(mapped_pos) + " but UUID is at position " + std::to_string(pos) +
67 " (bidirectional mapping inconsistent)");
68 }
69 }
70 }
71
72 // ========== Per-Primitive Buffer Sizing ==========
73 // Shared per-primitive arrays are sized to primitive_count only.
74 // Bbox data is stored separately in bboxes.UUIDs / bboxes.vertices and is NOT
75 // included in the shared arrays (see RadiationModel::buildGeometryData()).
76
77 if (transform_matrices.size() != primitive_count * 16) {
78 helios_runtime_error("RayTracingGeometry validation failed: transform_matrices.size()=" + std::to_string(transform_matrices.size()) + " != primitive_count*16=" + std::to_string(primitive_count * 16));
79 }
80
81 if (primitive_types.size() != primitive_count) {
82 helios_runtime_error("RayTracingGeometry validation failed: primitive_types.size()=" + std::to_string(primitive_types.size()) + " != primitive_count=" + std::to_string(primitive_count));
83 }
84
86 helios_runtime_error("RayTracingGeometry validation failed: object_subdivisions.size()=" + std::to_string(object_subdivisions.size()) + " != primitive_count=" + std::to_string(primitive_count));
87 }
88
89 if (twosided_flags.size() != primitive_count) {
90 helios_runtime_error("RayTracingGeometry validation failed: twosided_flags.size()=" + std::to_string(twosided_flags.size()) + " != primitive_count=" + std::to_string(primitive_count));
91 }
92
93 if (solid_fractions.size() != primitive_count) {
94 helios_runtime_error("RayTracingGeometry validation failed: solid_fractions.size()=" + std::to_string(solid_fractions.size()) + " != primitive_count=" + std::to_string(primitive_count));
95 }
96
97 // ========== Object ID Validation ==========
98
99 if (object_IDs.size() != primitive_count) {
100 helios_runtime_error("RayTracingGeometry validation failed: object_IDs.size()=" + std::to_string(object_IDs.size()) + " != primitive_count=" + std::to_string(primitive_count));
101 }
102
103 if (primitive_IDs.size() != primitive_count) {
104 helios_runtime_error("RayTracingGeometry validation failed: primitive_IDs.size()=" + std::to_string(primitive_IDs.size()) + " != primitive_count=" + std::to_string(primitive_count) +
105 " (COMMON BUG: Did you size by Nobjects instead of Nprimitives?)");
106 }
107
108 // ========== Per-Type Buffer Sizing ==========
109
110 if (patches.UUIDs.size() != patch_count) {
111 helios_runtime_error("RayTracingGeometry validation failed: patches.UUIDs.size()=" + std::to_string(patches.UUIDs.size()) + " != patch_count=" + std::to_string(patch_count));
112 }
113
114 if (patches.vertices.size() != patch_count * 4) {
115 helios_runtime_error("RayTracingGeometry validation failed: patches.vertices.size()=" + std::to_string(patches.vertices.size()) + " != patch_count*4=" + std::to_string(patch_count * 4));
116 }
117
118 if (triangles.UUIDs.size() != triangle_count) {
119 helios_runtime_error("RayTracingGeometry validation failed: triangles.UUIDs.size()=" + std::to_string(triangles.UUIDs.size()) + " != triangle_count=" + std::to_string(triangle_count));
120 }
121
122 if (triangles.vertices.size() != triangle_count * 3) {
123 helios_runtime_error("RayTracingGeometry validation failed: triangles.vertices.size()=" + std::to_string(triangles.vertices.size()) + " != triangle_count*3=" + std::to_string(triangle_count * 3));
124 }
125
126 if (tiles.UUIDs.size() != tile_count) {
127 helios_runtime_error("RayTracingGeometry validation failed: tiles.UUIDs.size()=" + std::to_string(tiles.UUIDs.size()) + " != tile_count=" + std::to_string(tile_count));
128 }
129
130 if (tiles.vertices.size() != tile_count * 4) {
131 helios_runtime_error("RayTracingGeometry validation failed: tiles.vertices.size()=" + std::to_string(tiles.vertices.size()) + " != tile_count*4=" + std::to_string(tile_count * 4));
132 }
133
134 if (voxels.UUIDs.size() != voxel_count) {
135 helios_runtime_error("RayTracingGeometry validation failed: voxels.UUIDs.size()=" + std::to_string(voxels.UUIDs.size()) + " != voxel_count=" + std::to_string(voxel_count));
136 }
137
138 if (voxels.vertices.size() != voxel_count * 8) {
139 helios_runtime_error("RayTracingGeometry validation failed: voxels.vertices.size()=" + std::to_string(voxels.vertices.size()) + " != voxel_count*8=" + std::to_string(voxel_count * 8));
140 }
141
142 if (bboxes.UUIDs.size() != bbox_count) {
143 helios_runtime_error("RayTracingGeometry validation failed: bboxes.UUIDs.size()=" + std::to_string(bboxes.UUIDs.size()) + " != bbox_count=" + std::to_string(bbox_count));
144 }
145
146 if (bboxes.vertices.size() != bbox_count * 4) {
147 helios_runtime_error("RayTracingGeometry validation failed: bboxes.vertices.size()=" + std::to_string(bboxes.vertices.size()) + " != bbox_count*4=" + std::to_string(bbox_count * 4));
148 }
149
150 if (disk_UUIDs.size() != disk_count) {
151 helios_runtime_error("RayTracingGeometry validation failed: disk_UUIDs.size()=" + std::to_string(disk_UUIDs.size()) + " != disk_count=" + std::to_string(disk_count));
152 }
153
154 if (disk_centers.size() != disk_count) {
155 helios_runtime_error("RayTracingGeometry validation failed: disk_centers.size()=" + std::to_string(disk_centers.size()) + " != disk_count=" + std::to_string(disk_count));
156 }
157
158 if (disk_radii.size() != disk_count) {
159 helios_runtime_error("RayTracingGeometry validation failed: disk_radii.size()=" + std::to_string(disk_radii.size()) + " != disk_count=" + std::to_string(disk_count));
160 }
161
162 if (disk_normals.size() != disk_count) {
163 helios_runtime_error("RayTracingGeometry validation failed: disk_normals.size()=" + std::to_string(disk_normals.size()) + " != disk_count=" + std::to_string(disk_count));
164 }
165
166 // ========== Subdivision Validation ==========
167
168 for (size_t i = 0; i < object_subdivisions.size(); i++) {
170 if (subdiv.x < 1 || subdiv.y < 1) {
171 helios_runtime_error("RayTracingGeometry validation failed: object_subdivisions[" + std::to_string(i) + "] = (" + std::to_string(subdiv.x) + "," + std::to_string(subdiv.y) + ") has zero or negative subdivision count");
172 }
173 }
174
175 // Heuristic check: warn if many primitives have subdivisions > (1,1)
176 // This often indicates subdivision inheritance bug (subpatches should be (1,1))
177 size_t subdivision_anomalies = 0;
178 for (size_t i = 0; i < object_subdivisions.size(); i++) {
179 if (object_subdivisions[i].x > 1 || object_subdivisions[i].y > 1) {
180 subdivision_anomalies++;
181 }
182 }
183
184 if (subdivision_anomalies > primitive_count / 2) {
185 std::cerr << "WARNING [RayTracingGeometry]: " << subdivision_anomalies << " / " << primitive_count << " primitives have subdivisions > (1,1). "
186 << "Check for subdivision inheritance bug - subpatches should have (1,1), "
187 << "only parent geometry should have actual subdivision counts.\n";
188 }
189
190#endif // NDEBUG
191 }
192
193} // namespace helios