Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions apps/rtiow/cpu/main_hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ inline float random_float(float min, float max) {
return min + (max - min) * random_float();
}

inline vec3_float min(const vec3_float &a, const vec3_float &b) {
return vec3_float{std::fminf(a[0], b[0]), std::fminf(a[1], b[1]),
inline float3 min(const float3 &a, const float3 &b) {
return float3{std::fminf(a[0], b[0]), std::fminf(a[1], b[1]),
std::fminf(a[2], b[2])};
}

inline vec3_float max(const vec3_float &a, const vec3_float &b) {
return vec3_float{std::fmaxf(a[0], b[0]), std::fmaxf(a[1], b[1]),
inline float3 max(const float3 &a, const float3 &b) {
return float3{std::fmaxf(a[0], b[0]), std::fmaxf(a[1], b[1]),
std::fmaxf(a[2], b[2])};
}

Expand Down Expand Up @@ -81,16 +81,16 @@ _tree_layout0 build_tree_simple(std::vector<MaterialSphere> &spheres,
// Internal node
tree.group0_index[this_index].nPrims = 0;

vec3_float min_bound = spheres[low].s.center;
vec3_float max_bound = spheres[low].s.center;
float3 min_bound = spheres[low].s.center;
float3 max_bound = spheres[low].s.center;

for (uint32_t i = low + 1; i < high; ++i) {
min_bound = min(min_bound, spheres[i].s.center);
max_bound = max(max_bound, spheres[i].s.center);
}

// Choose axis with greatest extent
vec3_float extent = max_bound - min_bound;
float3 extent = max_bound - min_bound;
int axis = 0;
if (extent[1] > extent[0])
axis = 1;
Expand Down Expand Up @@ -159,29 +159,29 @@ int main(int argc, char *argv[]) {
for (int a = -11; a < 11; a++) {
for (int b = -11; b < 11; b++) {
auto choose_mat = random_float();
vec3_float center = {static_cast<float>(a + 0.9 * random_float()),
float3 center = {static_cast<float>(a + 0.9 * random_float()),
0.2,
static_cast<float>(b + 0.9 * random_float())};

vec3_float a = {4, 0.2, 0};
float3 a = {4, 0.2, 0};

vec3_float diff = (center - a);
float3 diff = (center - a);
float len =
sqrt(diff[0] * diff[0] + diff[1] * diff[1] + diff[2] * diff[2]);

if (len > 0.9) {
if (choose_mat < 0.8) {
// diffuse
vec3_float r0 = {random_float(), random_float(),
float3 r0 = {random_float(), random_float(),
random_float()};
vec3_float r1 = {random_float(), random_float(),
float3 r1 = {random_float(), random_float(),
random_float()};
auto albedo = r0 * r1;
spheres.push_back(
{Sphere{center, 0.2}, LAMBERTIAN, albedo, 0.0});
} else if (choose_mat < 0.95) {
// metal
vec3_float albedo = {random_float(0.5, 1),
float3 albedo = {random_float(0.5, 1),
random_float(0.5, 1),
random_float(0.5, 1)};
float fuzz = random_float(0, 0.5);
Expand Down
2 changes: 1 addition & 1 deletion runtime/bonsai_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct vector {
}

// TODO(cgyurgyik): this leads to subtle bugs, e.g.,
// `vec3_float{1}` will be `{1, 0, 0}`. Remove this.
// `float3{1}` will be `{1, 0, 0}`. Remove this.
vector(std::initializer_list<T> list) {
if (list.size() == 0) {
for (int i = 0; i < N; ++i) {
Expand Down
7 changes: 7 additions & 0 deletions src/CodeGen/CodeGen_LLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,13 @@ void CodeGen_LLVM::print_helper(const ir::Expr &node,
llvm::Value *f = builder->CreateGlobalStringPtr("false");
expr = builder->CreateSelect(expr, t, f);
}
if (t.is<ir::Float_t>() && expr->getType() != f64_t) {
// printf is variadic, so the default argument promotions apply: any
// float narrower than a double arrives as a double, and that is what
// the "%f" specifier reads. Passing the narrow value straight through
// leaves the upper half of the argument undefined and prints garbage.
expr = builder->CreateFPExt(expr, f64_t);
}
args.push_back(expr);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/bonsai/correctness/cpp/main_vec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// Used in struct.bonsai
int main() {
vec3_float v;
float3 v;
v[0] = -1;
v[1] = -2;
v[2] = 5;
Expand Down
2 changes: 1 addition & 1 deletion tests/bonsai/error/generic_fib.expect
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---CODE---
1
---STDERR---
[internal] Error: src/IR/Expr.cpp:340
[internal] Error: src/IR/Expr.cpp:341

--> a.type().is_numeric() || a.type().is_bool()
BinOp of non-number or boolean types: fib[[T -> T]](i - 1) : T + fib[[T -> T]](i - 2) : T
2 changes: 1 addition & 1 deletion tests/bonsai/error/mismatched_types.expect
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---CODE---
1
---STDERR---
[internal] Error: src/IR/Expr.cpp:276
[internal] Error: src/IR/Expr.cpp:277

--> is_const(a) || is_const(b)
Implicit casting of types: x is not the same type as y: i32 versus f32
2 changes: 1 addition & 1 deletion tests/bonsai/error/struct_duplicate_default.expect
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---CODE---
1
---STDERR---
[internal] Error: src/Parser/Parser.cpp:451
[internal] Error: src/Parser/Parser.cpp:469

--> !defaults.contains(field_name)
Duplicate default value for field o of element Ray individually marked: f32x3(2f) and group marked: f32x3(1f)
Loading