feat(cpp/gfx): GPU compute primitives for Monte Carlo (G1-G7)
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>
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
#include "gfx/gpu_ssbo.h"
|
||||
#include <cstddef>
|
||||
|
||||
namespace fn::gfx {
|
||||
|
||||
// Binner 2D. nx*ny bins; SSBO interno uint[nx*ny] row-major (idx = y*nx + x).
|
||||
struct GpuHistogram2D {
|
||||
unsigned int program = 0;
|
||||
unsigned int loc_count = 0;
|
||||
unsigned int loc_nx = 0;
|
||||
unsigned int loc_ny = 0;
|
||||
unsigned int loc_min = 0;
|
||||
unsigned int loc_inv_range = 0;
|
||||
Ssbo bins;
|
||||
int nx = 0;
|
||||
int ny = 0;
|
||||
};
|
||||
|
||||
GpuHistogram2D gpu_histogram_2d_create(int nx, int ny);
|
||||
|
||||
void gpu_histogram_2d_clear(GpuHistogram2D& h);
|
||||
|
||||
// Acumula un SSBO vec2[count] (interpretado como float pares) en bins 2D.
|
||||
// Samples es un Ssbo float[2*count] (xy interleaved). xmin/xmax/ymin/ymax
|
||||
// definen el rango; samples fuera se descartan.
|
||||
//
|
||||
// Tras esta llamada se requiere barrier_storage()/barrier_buffer_update()
|
||||
// segun lo que vaya despues.
|
||||
void gpu_histogram_2d_accumulate(GpuHistogram2D& h,
|
||||
const Ssbo& samples_xy,
|
||||
int count,
|
||||
float xmin, float xmax,
|
||||
float ymin, float ymax);
|
||||
|
||||
// Lee bins a CPU. out debe tener al menos nx*ny enteros.
|
||||
void gpu_histogram_2d_readback(const GpuHistogram2D& h, unsigned int* out);
|
||||
|
||||
// Convertir uint[nx*ny] a float[nx*ny] normalizado (max=1.0). Helper CPU
|
||||
// para alimentar heatmap_cpp_viz / contour_cpp_viz que esperan z[].
|
||||
void gpu_histogram_2d_to_density(const unsigned int* counts, int nx, int ny,
|
||||
float* out_density);
|
||||
|
||||
void gpu_histogram_2d_destroy(GpuHistogram2D& h);
|
||||
|
||||
} // namespace fn::gfx
|
||||
Reference in New Issue
Block a user