Skip to content

Commit e950ea8

Browse files
committed
Small cleanup
1 parent 4551838 commit e950ea8

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

src/common/ray_intersection.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <algorithm>
66
#include <cassert>
7+
#include <cstdint>
78

89
namespace pt
910
{
@@ -63,9 +64,9 @@ RayAabbIntersector::RayAabbIntersector(const Ray& ray)
6364
{
6465
origin = ray.origin;
6566
invDir = 1.0f / ray.direction;
66-
dirNeg[0] = static_cast<uint32_t>(invDir.x < 0.0f);
67-
dirNeg[1] = static_cast<uint32_t>(invDir.y < 0.0f);
68-
dirNeg[2] = static_cast<uint32_t>(invDir.z < 0.0f);
67+
dirNeg[0] = static_cast<std::uint32_t>(invDir.x < 0.0f);
68+
dirNeg[1] = static_cast<std::uint32_t>(invDir.y < 0.0f);
69+
dirNeg[2] = static_cast<std::uint32_t>(invDir.z < 0.0f);
6970
}
7071

7172
bool rayIntersectAabb(
@@ -117,13 +118,13 @@ bool rayIntersectBvh(
117118
{
118119
const RayAabbIntersector intersector(ray);
119120

120-
constexpr size_t STACK_SIZE = 32;
121+
constexpr std::size_t STACK_SIZE = 32;
121122

122-
uint32_t nodesVisited = 0;
123-
size_t toVisitOffset = 0;
124-
size_t currentNodeIdx = 0;
125-
size_t nodesToVisit[STACK_SIZE];
126-
bool didIntersect = false;
123+
std::uint32_t nodesVisited = 0;
124+
std::size_t toVisitOffset = 0;
125+
std::size_t currentNodeIdx = 0;
126+
std::size_t nodesToVisit[STACK_SIZE];
127+
bool didIntersect = false;
127128

128129
while (true)
129130
{
@@ -136,7 +137,7 @@ bool rayIntersectBvh(
136137
if (node.triangleCount > 0)
137138
{
138139
// Check for intersection with primitives in BVH node
139-
for (size_t idx = 0; idx < node.triangleCount; ++idx)
140+
for (std::size_t idx = 0; idx < node.triangleCount; ++idx)
140141
{
141142
const Triangle48& triangle = bvh.triangles[node.trianglesOffset + idx];
142143
if (rayIntersectTriangle(ray, triangle, rayTMax, intersect))

src/pt/gpu_buffer.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,11 @@ GpuBuffer::GpuBuffer(
6464
const WGPUBufferUsageFlags usage,
6565
const std::span<const T> data)
6666
: mBuffer(nullptr),
67-
mByteSize(0),
67+
mByteSize(sizeof(T) * data.size()),
6868
mUsage(usage)
6969
{
7070
assert(device != nullptr);
7171

72-
mByteSize = sizeof(T) * data.size();
73-
7472
const WGPUBufferDescriptor bufferDesc{
7573
.nextInChain = nullptr,
7674
.label = label,

src/pt/raytracer.wgsl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,12 +269,14 @@ fn rayPointAtParameter(ray: Ray, t: f32) -> vec3f {
269269
return ray.origin + t * ray.direction;
270270
}
271271

272+
@must_use
272273
fn initRng(pixel: vec2u, resolution: vec2u, frame: u32) -> u32 {
273274
// Adapted from https://github.com/boksajak/referencePT
274275
let seed = dot(pixel, vec2u(1u, resolution.x)) ^ jenkinsHash(frame);
275276
return jenkinsHash(seed);
276277
}
277278

279+
@must_use
278280
fn jenkinsHash(input: u32) -> u32 {
279281
var x = input;
280282
x += x << 10u;

0 commit comments

Comments
 (0)