Also fixes a case where the D3D code path did not initialize num_layers leading to undefined behaviour.