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.2 KiB
3.2 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_compute_program | function | cpp | gfx | 1.0.0 | impure | ComputeCompileResult compile_compute(const std::string& user_body, int local_size_x, const std::string& preamble); ComputeCompileResult compile_compute_2d(const std::string& user_body, int local_size_x, int local_size_y, const std::string& preamble); void delete_compute_program(unsigned int program) | Compila compute shaders GLSL 4.3 prepending automaticamente #version, layout(local_size_*) y un preamble opcional. Devuelve CompileResult con program GL listo o err_msg/err_line. Pareja para fragments de gl_shader pero para computes. |
|
|
false | error_go_core |
|
false | cpp/functions/gfx/gpu_compute_program.cpp | opengl |
|
ComputeCompileResult con program=GL id si ok=true; si ok=false, err_line apunta al user_body (no al header) y err_msg trae el log completo de glGetShaderInfoLog/glGetProgramInfoLog. |
gpu_compute_program
Mismo patron que gl_shader::compile_fragment, especializado para compute shaders 4.3+.
Estructura del shader resultante
#version 430 core
layout(local_size_x = <local_size_x>) in; // o local_size_x,y para 2D
<preamble> // opcional: rng, helpers
<user_body> // declaraciones + main()
El err_line se ajusta restando las lineas del header para que apunte al texto que el caller escribio.
Ejemplo basico
const char* body = R"glsl(
layout(std430, binding = 0) buffer Out { float vals[]; };
uniform uint u_count;
void main() {
uint i = gl_GlobalInvocationID.x;
if (i >= u_count) return;
vals[i] = float(i) * 0.5;
}
)glsl";
auto r = fn::gfx::compile_compute(body, 64);
if (!r.ok) {
std::fprintf(stderr, "line %d: %s\n", r.err_line, r.err_msg.c_str());
return;
}
glUseProgram(r.program);
Con preamble (RNG inyectado)
auto rng = fn::gfx::glsl_rng_preamble(/*seed_binding=*/9);
auto r = fn::gfx::compile_compute(body, 64, rng);
El user_body ya puede llamar rng_uniform(i), rng_normal(i) etc. — definidas por el preamble.
Notas
- El context GL debe ser current y
gl_loader_init()ya invocado. - Tras un
delete_compute_programel id queda invalido para todos losglUseProgramposteriores. - Liberar siempre con
delete_compute_programpara evitar leaks (el destructor de C++ no lo hace porqueprogrames ununsigned int).