Posts

Showing posts from August, 2014

D3D11 Compute Shader - Part 2

Image
To understand the concept of Compute Shader, let's start from basic. Compute Shader (CS) Threads A thread is basic CS processing element. 1. CPU kicks off CS thread groups. // Total number of thread groups = nX * nY * nZ pDevice->Dispatch( nX, nY, nZ ); 2. Each CS declares the number of threads on the "thread group". // Total number of threads per thread group = X * Y * Z [numthreads(X,Y,Z)] void cs_main(...) { ... } Example // CPU pDevice->Dispatch( 3, 2, 1 ); // CS [numthreads(4, 4, 1)] void cs_main(...) { ... } // # of thread groups = 3*2*1 = 6 // # of threads per group = 4*4*1 = 16 // # of total threads = 6 * 16 = 96 N.B: Picture taken from GDC09 Slide "Shader Model 5.0 and Compute Shader" CS Parameter Input void cs_main(uint3 groupID : SV_GroupID, uint3 groupThreadID : SV_GroupThreadID, uint3 dispatchThreadID : SV_DispatchThreadID, uint groupIndex : SV_GroupIndex) {