Posted by jdoe on
The Compute API provides low‑level access to the Windows kernel for high‑performance numeric workloads. Below is a minimal example that creates a compute buffer and runs a simple kernel.
#include <windows.h>
#include <computeapi.h>
int main() {
ComputeDevice device = ComputeOpenDevice(0);
ComputeBuffer buf = ComputeCreateBuffer(device, 1024 * sizeof(float));
// kernel code omitted for brevity
ComputeRunKernel(device, buf);
ComputeReleaseBuffer(buf);
ComputeCloseDevice(device);
return 0;
}
Key points to remember:
HRESULT for error handling.ComputeSetDebugMode during development to get detailed validation messages.For a deeper dive, see the official Compute API Overview.
Comments (3)
Great starter example! I ran into an issue where the buffer wasn't aligned on a 64‑byte boundary. Adding
ComputeCreateAlignedBuffersolved it for me.Remember to call
ComputeFlushbefore releasing the device if you have pending submissions.Anyone has a good guide on integrating this with DirectX 12?
Leave a comment