c74fd4ae0d
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>
37 lines
1.2 KiB
C++
37 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include <string>
|
|
|
|
namespace fn::gfx {
|
|
|
|
// Devuelve un preamble GLSL que define primitivas RNG PCG32 para inyectar
|
|
// en un compute shader. El preamble incluye:
|
|
//
|
|
// layout(std430, binding = <seed_binding>) buffer RngSeeds { uint rng_seeds[]; };
|
|
//
|
|
// uint pcg32(inout uint state) // step + scramble
|
|
// float rng_uniform(inout uint state) // [0, 1)
|
|
// float rng_normal(inout uint state) // N(0, 1) Box-Muller
|
|
// uint rng_below(inout uint state, uint n) // [0, n)
|
|
//
|
|
// Patron de uso en el shader:
|
|
// void main() {
|
|
// uint i = gl_GlobalInvocationID.x;
|
|
// uint s = rng_seeds[i];
|
|
// float x = rng_normal(s);
|
|
// ...
|
|
// rng_seeds[i] = s; // persistir para siguientes dispatches
|
|
// }
|
|
//
|
|
// Pasar el resultado a gpu_compute_program::compile_compute(..., preamble).
|
|
std::string glsl_rng_preamble(int seed_binding);
|
|
|
|
// Genera count seeds no-cero deterministas a partir de master_seed usando
|
|
// SplitMix64. Util para inicializar el SSBO rng_seeds antes del primer
|
|
// dispatch. Garantiza out[i] != 0 (PCG32 requiere state != 0 para no
|
|
// quedarse atascado).
|
|
void seed_walkers_init(unsigned long long master_seed,
|
|
unsigned int* out, int count);
|
|
|
|
} // namespace fn::gfx
|