Why does my image has a square pattern in cuda path tracer? I am writting a path tracer in cuda following the Shirley's book. I am having a square pattern as an output.
The size of the block change if I change the block dimensions. For this image, the block dimensions follow the aspect ratio, basically 16 * 9 is block size. I know that without actually showing the entire code, it is difficult to debug it. I am just asking if you have any idea where I should start debugging it. My hunch is that there is a problem with my random number generator.
Here is its code in case I am doing something wrong. Here is the host code:
int total_pixel_size = WIDTH * HEIGHT;
size_t frameSize = 3 * total_pixel_size;

// declare random state
int SEED = time(NULL);
thrust::device_ptr&lt;curandState&gt; randState1 = thrust::device_malloc&lt;curandState&gt;(frameSize);
CUDA_CONTROL(cudaGetLastError());

// declare random state 2
thrust::device_ptr&lt;curandState&gt; randState2 = thrust::device_malloc&lt;curandState&gt;(1);
CUDA_CONTROL(cudaGetLastError());
rand_init&lt;&lt;&lt;1, 1&gt;&gt;&gt;(thrust::raw_pointer_cast(randState2),
                      SEED);
CUDA_CONTROL(cudaGetLastError());
CUDA_CONTROL(cudaDeviceSynchronize());

dim3 blocks(WIDTH / BLOCK_WIDTH + 1,
              HEIGHT / BLOCK_HEIGHT + 1);
  dim3 threads(BLOCK_WIDTH, BLOCK_HEIGHT);
  render_init&lt;&lt;&lt;blocks, threads&gt;&gt;&gt;(
      WIDTH, HEIGHT, thrust::raw_pointer_cast(randState1),
      SEED);

Here is the device code:

__global__ void rand_init(curandState *randState,
                          int seed) {
  if (threadIdx.x == 0 &amp;&amp; blockIdx.x == 0) {
    curand_init(seed, 0, 0, randState);
  }
}

__global__ void render_init(int mx, int my,
                            curandState *randState,
                            int seed) {
  if (threadIdx.x == 0 &amp;&amp; threadIdx.y == 0) {
    curand_init(seed, 0, 0, randState);
  }
  int i = threadIdx.x + blockIdx.x * blockDim.x;
  int j = threadIdx.y + blockIdx.y * blockDim.y;

  if ((i &gt;= mx) || (j &gt;= my)) {
    return;
  }
  int pixel_index = j * mx + i;
  // same seed, different index
  curand_init(seed + pixel_index, pixel_index, 0,
              &amp;randState[pixel_index]);
}

I would really appreciate any pointers to the problem.
.
Here is another image with different block size and dimensions but with the same problem:
I managed to fix it. It was indeed related to repeating random sequences.
The problem was the following. curandState* randState is an array of curandStates, and most calls to curand_* require a pointer of a curandState.
I was sending the randState, the array, to curand_* functions and not for example, a pointer of one of its members.
Now most of my images are like this: