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>
3.4 KiB
3.4 KiB
name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, tested, tests, test_file_path, file_path, framework, params, output
| name | kind | lang | domain | version | purity | signature | description | tags | uses_functions | uses_types | returns | returns_optional | error_type | imports | tested | tests | test_file_path | file_path | framework | params | output | |||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| gpu_ssbo | function | cpp | gfx | 1.0.0 | impure | Ssbo ssbo_create(size_t bytes, const void* initial_data, GLenum usage); void ssbo_bind(const Ssbo&, unsigned binding); void ssbo_upload(const Ssbo&, size_t offset, size_t bytes, const void* data); void ssbo_readback(const Ssbo&, size_t offset, size_t bytes, void* out); void ssbo_destroy(Ssbo&) | Lifecycle de Shader Storage Buffer Objects (SSBO) para datos arbitrarios CPU<->GPU. create/bind/upload/readback/destroy. Pareja generica de mesh_gpu para computes y Monte Carlo intensivo. |
|
|
false | error_go_core |
|
false | cpp/functions/gfx/gpu_ssbo.cpp | opengl |
|
Ssbo con id GL valido (o 0 si bytes=0). El caller mantiene la struct y la pasa a las demas funciones; ssbo_destroy resetea id/bytes a 0. |
gpu_ssbo
Wrapper canonico de Shader Storage Buffer Objects para uso con compute shaders. Pensado como base de Monte Carlo / MCMC en GPU: el SSBO es el medio para llevar samples, walkers, contadores e histogramas entre passes y de vuelta a CPU para visualizacion con histogram_cpp_viz, heatmap_cpp_viz, etc.
Ciclo de vida
fn::gfx::Ssbo samples = fn::gfx::ssbo_create(N * sizeof(float));
// Bind antes de cada dispatch que quiera leer/escribir el buffer:
fn::gfx::ssbo_bind(samples, /*binding=*/0);
glDispatchCompute( ... );
glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
// Lectura sincrona a CPU:
std::vector<float> host(N);
fn::gfx::ssbo_readback(samples, 0, N * sizeof(float), host.data());
fn::gfx::ssbo_destroy(samples);
Subir datos iniciales
std::vector<unsigned int> seeds(N);
fn::gfx::seed_walkers_init(0xDEADBEEF, seeds.data(), N);
fn::gfx::Ssbo seed_buf = fn::gfx::ssbo_create(
N * sizeof(unsigned int),
seeds.data(),
GL_STATIC_DRAW
);
O bien crear vacio y rellenar luego:
fn::gfx::Ssbo buf = fn::gfx::ssbo_create(N * sizeof(unsigned int));
fn::gfx::ssbo_upload(buf, 0, N * sizeof(unsigned int), seeds.data());
Notas
ssbo_readbackbloquea el pipeline. Para readbacks frecuentes considerar PBO oglFenceSync(no implementado aqui — añadirlo cuando haga falta).- El caller es responsable de los
glMemoryBarrierentre dispatches que leen lo que un dispatch anterior escribio. - El buffer se enlaza a
GL_SHADER_STORAGE_BUFFERpara create/upload/readback y al binding indexado viaglBindBufferBasesolo enssbo_bind. Esto evita estado pegajoso entre llamadas. - Tamano maximo en GL 4.3:
GL_MAX_SHADER_STORAGE_BLOCK_SIZE(en RTX 3070 ~ 2 GB). Para Monte Carlo de 10^7 samples float fp32 son 40 MB — sobrado.