Eager Load Matrix Field with Assets Field Type
The line {% set img = entry.primaryImage[0] ?? null %} is looking for the primaryImage field on the entry inside your for loop. It is not looking for primaryImage for the current matrix field.

If primaryImage is a field within your matrix blog you will need to change the line to 

{% set img = block.primaryImage[0] ?? null %}