Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random Sample Issue in OpenCL Kernel #184

Open
zjxeditor opened this issue Aug 13, 2018 · 0 comments
Open

Random Sample Issue in OpenCL Kernel #184

zjxeditor opened this issue Aug 13, 2018 · 0 comments

Comments

@zjxeditor
Copy link

Hi, please pay attention to this piece of code in monte_carlo_renderer.cl (actually, this pattern appears in many kernels):

        int idx = pixel_idx[global_id];
        int y = idx / output_width;
        int x = idx % output_width;

        // Get pointer to ray & path handles
        GLOBAL ray* my_ray = rays + global_id;

        // Initialize sampler
        Sampler sampler;
#if SAMPLER == SOBOL
        uint scramble = random[x + output_width * y] * 0x1fe3434f;

        if (frame & 0xF)
        {
            random[x + output_width * y] = WangHash(scramble);
        }

        Sampler_Init(&sampler, frame, SAMPLE_DIM_CAMERA_OFFSET, scramble);
#elif SAMPLER == RANDOM
        uint scramble = x + output_width * y * rng_seed;
        Sampler_Init(&sampler, scramble);
#elif SAMPLER == CMJ
        uint rnd = random[x + output_width * y];
        uint scramble = rnd * 0x1fe3434f * ((frame + 133 * rnd) / (CMJ_DIM * CMJ_DIM));
        Sampler_Init(&sampler, frame % (CMJ_DIM * CMJ_DIM), SAMPLE_DIM_CAMERA_OFFSET, scramble);
#endif

We know that MonteCarloRenderer call RenderTile method to render. When the output size is bigger than kTileSizeX * kTileSizeY, then each time we only render a tile. That is why we use pixel_idx buffer to establish the relationship between ray index and output index.
We use x + output_width * y to read or write data in the random buffer, however, the random buffer size is kTileSizeX * kTileSizeY. So the index may be out of bound. It should be correct to just use the global_id to read or write the random buffer.
I don't know how OpenCL handle the out of range problem. There is something wrong with the logic. Hope for reply, thanks :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant