Skip to content

Commit

Permalink
Small cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Nelarius committed Nov 6, 2023
1 parent 4551838 commit e950ea8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
21 changes: 11 additions & 10 deletions src/common/ray_intersection.cpp
Expand Up @@ -4,6 +4,7 @@

#include <algorithm>
#include <cassert>
#include <cstdint>

namespace pt
{
Expand Down Expand Up @@ -63,9 +64,9 @@ RayAabbIntersector::RayAabbIntersector(const Ray& ray)
{
origin = ray.origin;
invDir = 1.0f / ray.direction;
dirNeg[0] = static_cast<uint32_t>(invDir.x < 0.0f);
dirNeg[1] = static_cast<uint32_t>(invDir.y < 0.0f);
dirNeg[2] = static_cast<uint32_t>(invDir.z < 0.0f);
dirNeg[0] = static_cast<std::uint32_t>(invDir.x < 0.0f);
dirNeg[1] = static_cast<std::uint32_t>(invDir.y < 0.0f);
dirNeg[2] = static_cast<std::uint32_t>(invDir.z < 0.0f);
}

bool rayIntersectAabb(
Expand Down Expand Up @@ -117,13 +118,13 @@ bool rayIntersectBvh(
{
const RayAabbIntersector intersector(ray);

constexpr size_t STACK_SIZE = 32;
constexpr std::size_t STACK_SIZE = 32;

uint32_t nodesVisited = 0;
size_t toVisitOffset = 0;
size_t currentNodeIdx = 0;
size_t nodesToVisit[STACK_SIZE];
bool didIntersect = false;
std::uint32_t nodesVisited = 0;
std::size_t toVisitOffset = 0;
std::size_t currentNodeIdx = 0;
std::size_t nodesToVisit[STACK_SIZE];
bool didIntersect = false;

while (true)
{
Expand All @@ -136,7 +137,7 @@ bool rayIntersectBvh(
if (node.triangleCount > 0)
{
// Check for intersection with primitives in BVH node
for (size_t idx = 0; idx < node.triangleCount; ++idx)
for (std::size_t idx = 0; idx < node.triangleCount; ++idx)
{
const Triangle48& triangle = bvh.triangles[node.trianglesOffset + idx];
if (rayIntersectTriangle(ray, triangle, rayTMax, intersect))
Expand Down
4 changes: 1 addition & 3 deletions src/pt/gpu_buffer.hpp
Expand Up @@ -64,13 +64,11 @@ GpuBuffer::GpuBuffer(
const WGPUBufferUsageFlags usage,
const std::span<const T> data)
: mBuffer(nullptr),
mByteSize(0),
mByteSize(sizeof(T) * data.size()),
mUsage(usage)
{
assert(device != nullptr);

mByteSize = sizeof(T) * data.size();

const WGPUBufferDescriptor bufferDesc{
.nextInChain = nullptr,
.label = label,
Expand Down
2 changes: 2 additions & 0 deletions src/pt/raytracer.wgsl
Expand Up @@ -269,12 +269,14 @@ fn rayPointAtParameter(ray: Ray, t: f32) -> vec3f {
return ray.origin + t * ray.direction;
}

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

@must_use
fn jenkinsHash(input: u32) -> u32 {
var x = input;
x += x << 10u;
Expand Down

0 comments on commit e950ea8

Please sign in to comment.