$darkmode
#include "sphere_sorting.h"#include "gl_common.h"#include "gl_debug.h"#include "instanced_rendering.h"#include "log.h"#include "platform/platform_utils.h"#include "profiler.h"#include "shader.h"#include <stdbool.h>#include <stdlib.h>#include <string.h>Enumerations | |
| enum | { EXPECTED_SPHERE_INSTANCE_SIZE = 128 } |
| enum | { WORKGROUP_SIZE = 1024 } |
| enum | { DEFAULT_MIN_CAPACITY = 64 } |
| enum | { MAX_SINGLE_PASS_COUNT = 1024 } |
| enum | { RADIX_BITS_PER_PASS = 8 } |
| enum | { RADIX_BUCKETS = 256 } |
| enum | { RADIX_SHIFT_LIMIT = 32 } |
| enum | { RADIX_MASK = 0xFFU } |
Functions | |
| _Static_assert (sizeof(SphereInstance)==EXPECTED_SPHERE_INSTANCE_SIZE, "SphereInstance size must match GLSL std430 layout (128 B)") | |
| static int | next_pow2 (int val) |
| static bool | ensure_cpu_capacity (SphereSorter *sorter, int count) |
Grow CPU scratchpads to hold at least count elements. More... | |
| static GLuint | upload_sorted_to_ssbo (SphereSorter *sorter, int count) |
Upload count sorted instances from the CPU temp buffer to the SSBO. More... | |
| void | sphere_sorter_init (SphereSorter *sorter, int initial_capacity) |
| Allocates internal buffers for the sorter. More... | |
| void | sphere_sorter_cleanup (SphereSorter *sorter) |
| Destroys the sorter context. More... | |
| GLuint | sphere_sorter_sort_gpu (SphereSorter *sorter, const SphereInstance *instances, int count, const vec3 camera_pos) |
| Sorts the array of instances Back-to-Front (descending depth) on GPU. More... | |
| static int | compare_sphere_entries (const void *lhs, const void *rhs) |
| GLuint | sphere_sorter_sort_cpu (SphereSorter *sorter, const SphereInstance *instances, int count, const vec3 camera_pos) |
| Sorts the array of instances Back-to-Front (descending depth) on CPU. More... | |
| static uint32_t | float_to_sortable_uint (float f_val) |
| Converts a float to a uint32_t that preserves order (IEEE 754). This allows sorting floats using integer radix sort. More... | |
| GLuint | sphere_sorter_sort_cpu_radix (SphereSorter *sorter, const SphereInstance *instances, int count, const vec3 camera_pos) |
| Sorts the array of instances Back-to-Front (descending depth) using Radix Sort. More... | |
Variables | |
| static const uint32_t | FLOAT_SIGN_MASK = 0x80000000U |
| static const uint32_t | FLOAT_COMPLEMENT_MASK = 0xFFFFFFFFU |
| static const unsigned int | BIT_SHIFT_8 = 8U |
| static const unsigned int | BIT_SHIFT_16 = 16U |
| static const size_t | GPU_ENTRY_SIZE = 8 |
| _Static_assert | ( | sizeof(SphereInstance) | = =EXPECTED_SPHERE_INSTANCE_SIZE, |
| "SphereInstance size must match GLSL std430 layout (128 B)" | |||
| ) |
|
static |
|
static |
Grow CPU scratchpads to hold at least count elements.
|
inlinestatic |
Converts a float to a uint32_t that preserves order (IEEE 754). This allows sorting floats using integer radix sort.
|
static |
| void sphere_sorter_cleanup | ( | SphereSorter * | sorter | ) |
Destroys the sorter context.
| sorter | Pointer to the struct. |
| void sphere_sorter_init | ( | SphereSorter * | sorter, |
| int | initial_capacity | ||
| ) |
Allocates internal buffers for the sorter.
| sorter | Pointer to the struct. |
| initial_capacity | Expected number of instances. |
| GLuint sphere_sorter_sort_cpu | ( | SphereSorter * | sorter, |
| const SphereInstance * | instances, | ||
| int | count, | ||
| const vec3 | camera_pos | ||
| ) |
Sorts the array of instances Back-to-Front (descending depth) on CPU.
Uses qsort on the host and uploads the result to the SSBO.
| sorter | Memory context. |
| instances | Array of instances (will be copied and sorted internally). |
| count | Active element count. |
| camera_pos | World-space viewer position. |
| GLuint sphere_sorter_sort_cpu_radix | ( | SphereSorter * | sorter, |
| const SphereInstance * | instances, | ||
| int | count, | ||
| const vec3 | camera_pos | ||
| ) |
Sorts the array of instances Back-to-Front (descending depth) using Radix Sort.
| sorter | Memory context. |
| instances | Array of instances. |
| count | Active element count. |
| camera_pos | World-space viewer position (for depth). |
| GLuint sphere_sorter_sort_gpu | ( | SphereSorter * | sorter, |
| const SphereInstance * | instances, | ||
| int | count, | ||
| const vec3 | camera_pos | ||
| ) |
Sorts the array of instances Back-to-Front (descending depth) on GPU.
Uploads instances to an SSBO, sorts them using a compute shader, and prepares them for rendering.
| sorter | Memory context. |
| instances | Pointer to the array of instances to upload. |
| count | Active element count. |
| camera_pos | World-space viewer position. |
|
static |
Upload count sorted instances from the CPU temp buffer to the SSBO.
|
static |
|
static |
Bit-shift constants for next_pow2 (named to satisfy linter).
|
static |
|
static |
|
static |
Size of the Entry struct in the compute shader: int (4) + float (4).