Skip to content

Commit

Permalink
Some refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
sergcpp committed Mar 12, 2024
1 parent b1db0dc commit bd7f0c7
Show file tree
Hide file tree
Showing 33 changed files with 276 additions and 393 deletions.
427 changes: 187 additions & 240 deletions internal/CoreRef.cpp

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions internal/CoreRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,6 @@ force_inline float construct_float(uint32_t m) {
}

force_inline float fract(const float v) {
// float _unused;
// return modff(v, &_unused);
return v - floorf(v);
}

Expand Down
36 changes: 1 addition & 35 deletions internal/SmallVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,9 @@
#include <utility>

#include "../Span.h"
#include "simd/aligned_allocator.h"

namespace Ray {
#ifndef RAY_ALIGNED_MALLOC_DEFINED
inline void *aligned_malloc(size_t size, size_t alignment) {
while (alignment < sizeof(void *)) {
alignment *= 2;
}
size_t space = size + (alignment - 1);

void *ptr = malloc(space + sizeof(void *));
void *original_ptr = ptr;

char *ptr_bytes = static_cast<char *>(ptr);
ptr_bytes += sizeof(void *);

auto off = static_cast<size_t>(reinterpret_cast<uintptr_t>(ptr_bytes) % alignment);
if (off) {
off = alignment - off;
}
ptr_bytes += off;

ptr = static_cast<void *>(ptr_bytes);
ptr_bytes -= sizeof(void *);

memcpy(ptr_bytes, &original_ptr, sizeof(void *));

return ptr;
}

inline void aligned_free(void *p) {
if (p) {
free(static_cast<void **>(p)[-1]);
}
}
#define RAY_ALIGNED_MALLOC_DEFINED
#endif

template <typename T, int AlignmentOfT = alignof(T)> class SmallVectorImpl {
T *begin_, *end_;
size_t capacity_;
Expand Down
14 changes: 1 addition & 13 deletions internal/Vk/ContextVK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,11 @@ void Ray::Vk::Context::Destroy() {
api_.vkFreeCommandBuffers(device_, command_pool_, 1, &setup_cmd_buf_);
api_.vkFreeCommandBuffers(device_, command_pool_, MaxFramesInFlight, draw_cmd_bufs_);

// for (int i = 0; i < StageBufferCount; ++i) {
// default_stage_bufs_.fences[i].ClientWaitSync();
// default_stage_bufs_.fences[i] = {};
// default_stage_bufs_.bufs[i] = {};
// }

api_.vkDestroyCommandPool(device_, command_pool_, nullptr);
api_.vkDestroyCommandPool(device_, temp_command_pool_, nullptr);

// for (size_t i = 0; i < api_ctx_->present_image_views.size(); ++i) {
// vkDestroyImageView(api_ctx_->device, api_ctx_->present_image_views[i], nullptr);
// }

// vkDestroySwapchainKHR(device_, api_ctx_->swapchain, nullptr);

api_.vkDestroyDevice(device_, nullptr);
// vkDestroySurfaceKHR(instance_, surface_, nullptr);

if (debug_callback_) {
api_.vkDestroyDebugReportCallbackEXT(instance_, debug_callback_, nullptr);
}
Expand Down
28 changes: 8 additions & 20 deletions internal/shaders/common.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -75,27 +75,15 @@ vec3 normalize_len(const vec3 v, out float len) {
}

vec3 safe_invert(vec3 v) {
vec3 inv_v = 1.0f / v;

if (v.x <= FLT_EPS && v.x >= 0) {
inv_v.x = FLT_MAX;
} else if (v.x >= -FLT_EPS && v.x < 0) {
inv_v.x = -FLT_MAX;
}

if (v.y <= FLT_EPS && v.y >= 0) {
inv_v.y = FLT_MAX;
} else if (v.y >= -FLT_EPS && v.y < 0) {
inv_v.y = -FLT_MAX;
}

if (v.z <= FLT_EPS && v.z >= 0) {
inv_v.z = FLT_MAX;
} else if (v.z >= -FLT_EPS && v.z < 0) {
inv_v.z = -FLT_MAX;
vec3 ret;
[[unroll]] for (int i = 0; i < 3; ++i) {
[[flatten]] if (abs(v[i]) > FLT_EPS) {
ret[i] = 1.0 / v[i];
} else {
ret[i] = (v[i] >= 0.0) ? FLT_MAX : -FLT_MAX;
}
}

return inv_v;
return ret;
}

vec3 srgb_to_rgb(vec3 col) {
Expand Down
6 changes: 3 additions & 3 deletions internal/shaders/output/debug_rt.comp.cso.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/debug_rt.comp.spv.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/intersect_area_lights.comp.cso.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/intersect_area_lights.comp.spv.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/intersect_scene.rgen.spv.inl

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/intersect_scene_indirect.rgen.spv.inl

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions internal/simd/aligned_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <stdexcept>

namespace Ray {
#ifndef RAY_ALIGNED_MALLOC_DEFINED
inline void *aligned_malloc(size_t size, size_t alignment) {
while (alignment < sizeof(void *)) {
alignment *= 2;
Expand Down Expand Up @@ -48,9 +47,6 @@ inline void aligned_free(void *p) {
}
}

#define RAY_ALIGNED_MALLOC_DEFINED
#endif

template <typename T, size_t Alignment> class aligned_allocator {
public:
// The following will be the same for virtually all allocators.
Expand Down

0 comments on commit bd7f0c7

Please sign in to comment.