# GPU Programming / Compute Shaders in Godot — Resources

## Knowledge

### Godot-specific

- [Godot docs: *Using compute shaders*](https://docs.godotengine.org/en/stable/tutorials/shaders/compute_shaders.html)
  The canonical minimal example: `#[compute]` GLSL file, `RenderingDevice` setup, dispatch,
  readback. Use for: exact API names and argument order, renderer requirements
  ("Compute shaders can only be used from RenderingDevice-based renderers — the Forward+ or
  Mobile renderer"), and the warning that `sync()` immediately after `submit()` stalls the CPU.
- [Godot docs: *RenderingDevice* class reference](https://docs.godotengine.org/en/stable/classes/class_renderingdevice.html)
  Every method, every enum. Use for: buffer/texture/uniform creation flags, barrier constants,
  push constants, indirect dispatch/draw calls, asynchronous readback, and checking what a
  method actually returns before guessing.
- [Godot docs: *Shading language* (Godot's own, not GLSL)](https://docs.godotengine.org/en/stable/tutorials/shaders/shader_reference/shading_language.html)
  Use for: telling apart Godot's `.gdshader` language from the raw GLSL used in compute files.
  These are *different languages*; conflating them is the most common early mistake.
- [Godot demo projects: *Compute Shader Heightmap*](https://github.com/godotengine/godot-demo-projects/tree/master/misc/compute_shader_heightmap)
  Official demo generating a heightmap on both CPU and GPU. Use for: a real, maintained
  example of image binding and CPU/GPU comparison.
- [DevPoodle/godot-boids](https://github.com/DevPoodle/godot-boids)
  Godot 4 boids simulation using `RenderingDevice` for both compute and rendering.
  Use for: a worked example of keeping agent state resident on the GPU across frames.

### Local architectural case study

- *Sir, We Have an Orc Problem* — local workspace, especially `globals/gpu_sim.gd`,
  `gpu_sim/rigidbody.gd`, `shaders/bindings.gdshaderinc`, and `shaders/rigidbody/`.
  The target architecture: CPU initialization records; split GPU-resident body buffers;
  multi-pass simulation; indirect body/effect drawing; asynchronous summary readbacks.
  Use for: seeing how each isolated lesson composes into a production system.

### GPU fundamentals

- [Stephen Jones (NVIDIA), *How GPU Computing Works*, GTC 2021](https://archive.org/details/how-gpu-computing-works)
  The best single hour on why GPUs are shaped the way they are: throughput vs latency,
  why bandwidth and not FLOPS is the wall, why occupancy hides memory latency.
  Use for: intuition about *why* a dispatch of a million threads is normal and good.
- [Cornell Virtual Workshop, *SIMT and Warps*](https://cvw.cac.cornell.edu/gpu-architecture/gpu-characteristics/simt_warp)
  Careful, citable treatment of warps ("a bundle of 32 threads with consecutive thread
  indexes"), SIMT vs SIMD, and branch divergence. Use for: anything about lockstep execution
  and why `if` is more expensive on a GPU than on a CPU.
- [NVIDIA, *CUDA C++ Best Practices Guide*](https://docs.nvidia.com/cuda/cuda-c-best-practices-guide/index.html)
  Vendor-authoritative on warp size (32) and on choosing block sizes that are multiples of it.
  Use for: sourcing performance rules of thumb instead of asserting them. Translate CUDA
  vocabulary: block → workgroup, thread → invocation.

### GLSL / compute shaders generally

- [Vulkan Guide: *Shader Memory Layout*](https://docs.vulkan.org/guide/latest/shader_memory_layout.html)
  Khronos-maintained explanation of alignment, offsets, array stride, `std430`, and why a
  12-byte `vec3` still has 16-byte alignment. Use for: every CPU↔GLSL struct contract.
- [Vulkan Guide: *Push Constants*](https://docs.vulkan.org/guide/latest/push_constants.html)
  Primary explanation of the small command-recorded parameter bank and its GLSL declaration.
  Use for: per-frame `dt`, time, counts, world size, and simulation tuning values.

- [Khronos OpenGL Wiki: *Compute Shader*](https://wikis.khronos.org/opengl/Compute_Shader)
  Specification-adjacent reference: `gl_GlobalInvocationID = gl_WorkGroupID * gl_WorkGroupSize
  + gl_LocalInvocationID`, and the warning that "the order might vary arbitrarily and the
  program should not rely on the order in which individual groups are processed".
  Use for: the definitive wording on built-ins and ordering guarantees.
- [LearnOpenGL: *Compute Shaders — Introduction*](https://learnopengl.com/Guest-Articles/2022/Compute-Shaders/Introduction)
  Clear beginner framing of workgroups vs invocations; notes that "individual work groups
  are completely independent" and that implementations must support at least 128 invocations
  per group. Use for: a second explanation when the Khronos wording is too terse.
- [Anton Gerdelan, *Compute Shaders*](https://antongerdelan.net/opengl/compute.html)
  Short, practical, honest about the gotchas. Use for: a quick refresher on memory barriers.
- [vkguide: *Compute Shaders*](https://vkguide.dev/docs/gpudriven/compute_shaders/)
  Vulkan-level view of the same machinery Godot's `RenderingDevice` wraps. Use for:
  understanding what descriptor sets and pipelines are, since Godot's API mirrors them.

## Wisdom (Communities)

- [Godot Engine Discord — `#shaders` channel](https://discord.gg/godotengine)
  The highest-signal place for Godot compute-shader questions; several rendering
  contributors read it. Use for: "my dispatch returns zeros" debugging.
- [r/godot](https://reddit.com/r/godot)
  Broad, friendly, high traffic. Use for: showing off a working simulation and getting
  performance critique.
- [Godot Forum — Shaders category](https://forum.godotengine.org/c/shaders/13)
  Slower, more searchable, better for long-form problems than Discord.
- [Graphics Programming Discord](https://discord.gg/graphicsprogramming)
  Engine-agnostic, deep expertise, strong culture of correctness. Use for: hardware-level
  questions (occupancy, coalescing, barriers) where Godot-specific forums run out of depth.

## Gaps

- No trusted, current, *written* Godot 4 compute-shader tutorial beyond the official docs;
  most community material is video. Worth searching again before the buffer/texture lessons.
- No source yet on profiling compute work inside Godot (RenderDoc cannot capture a *local*
  RenderingDevice, per the official docs).
- Need primary, implementation-oriented references for GPU spatial hashing, parallel
  compaction, and indirect drawing before their respective lessons.
