07d06d5e7d
Stack base de compute shaders OpenGL 4.3 para cargas Monte Carlo intensivas en GPU. Reutiliza el patron de graph_force_layout_gpu (SSBO + compute) y se integra con el resto del registry sin nuevos simbolos en gl_loader (todo lo que se necesita ya estaba expuesto). - gpu_ssbo: lifecycle de Shader Storage Buffer Objects. - gpu_compute_program: compila compute GLSL 4.3 con preamble inyectable (mismo pattern de gl_shader::compile_fragment). - gpu_dispatch: dispatch_1d/2d/3d con ceil(N/local) automatico + barrier helpers (storage, uniform, image, buffer_update, all). - gpu_rng_glsl: PCG32 GLSL (uniform/normal/below) + SplitMix64 seed walkers para sembrar deterministicamente N walkers desde un master seed. - gpu_histogram_1d: SSBO float[N] -> uint[nbins] via atomicAdd. - gpu_histogram_2d: SSBO float[2N] xy-interleaved -> uint[nx*ny] + to_density helper para alimentar heatmap_cpp_viz. - gpu_reduce: workgroup-shared sum/min/max/mean (local 256, partials CPU). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
40 lines
1.3 KiB
C++
40 lines
1.3 KiB
C++
#include "gfx/gl_loader.h"
|
|
#include "gfx/gpu_dispatch.h"
|
|
|
|
namespace fn::gfx {
|
|
|
|
static inline GLuint groups(int n, int local) {
|
|
if (n <= 0 || local <= 0) return 0;
|
|
return static_cast<GLuint>((n + local - 1) / local);
|
|
}
|
|
|
|
void dispatch_1d(int num_invocations, int local_size_x) {
|
|
GLuint gx = groups(num_invocations, local_size_x);
|
|
if (gx == 0) return;
|
|
glDispatchCompute(gx, 1, 1);
|
|
}
|
|
|
|
void dispatch_2d(int width, int height, int local_size_x, int local_size_y) {
|
|
GLuint gx = groups(width, local_size_x);
|
|
GLuint gy = groups(height, local_size_y);
|
|
if (gx == 0 || gy == 0) return;
|
|
glDispatchCompute(gx, gy, 1);
|
|
}
|
|
|
|
void dispatch_3d(int x, int y, int z,
|
|
int local_size_x, int local_size_y, int local_size_z) {
|
|
GLuint gx = groups(x, local_size_x);
|
|
GLuint gy = groups(y, local_size_y);
|
|
GLuint gz = groups(z, local_size_z);
|
|
if (gx == 0 || gy == 0 || gz == 0) return;
|
|
glDispatchCompute(gx, gy, gz);
|
|
}
|
|
|
|
void barrier_storage() { glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT); }
|
|
void barrier_uniform() { glMemoryBarrier(GL_UNIFORM_BARRIER_BIT); }
|
|
void barrier_image() { glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT); }
|
|
void barrier_buffer_update() { glMemoryBarrier(GL_BUFFER_UPDATE_BARRIER_BIT); }
|
|
void barrier_all() { glMemoryBarrier(GL_ALL_BARRIER_BITS); }
|
|
|
|
} // namespace fn::gfx
|