Fix T48732: New GGX breaks OpenCL kernel
Make sure we don't perform any implicit address space conversion. A bit annoying, but less intrusive approaches (like using temp private variable in .cl kernel) do not work correct here. Using generic address space will help from code side here, but will be somewhat slower due to extra things happening as far as i know.
This commit is contained in:
parent
0d7817d1a4
commit
23cc453975
Notes:
blender-bot
2023-02-14 07:47:57 +01:00
Referenced by issue #48732, New GGX breaks OpenCL kernel
|
@ -98,9 +98,10 @@ ccl_device float3 MF_FUNCTION_FULL_NAME(mf_eval)(float3 wi, float3 wo, const boo
|
|||
|
||||
for(int order = 0; order < 10; order++) {
|
||||
/* Sample microfacet height and normal */
|
||||
if(!mf_sample_height(wr, &hr, &C1_r, &G1_r, &lambda_r, lcg_step_float(lcg_state)))
|
||||
if(!mf_sample_height(wr, &hr, &C1_r, &G1_r, &lambda_r, lcg_step_float_addrspace(lcg_state)))
|
||||
break;
|
||||
float3 wm = mf_sample_vndf(-wr, alpha, make_float2(lcg_step_float(lcg_state), lcg_step_float(lcg_state)));
|
||||
float3 wm = mf_sample_vndf(-wr, alpha, make_float2(lcg_step_float_addrspace(lcg_state),
|
||||
lcg_step_float_addrspace(lcg_state)));
|
||||
|
||||
#ifdef MF_MULTI_DIFFUSE
|
||||
if(order == 0) {
|
||||
|
@ -128,14 +129,16 @@ ccl_device float3 MF_FUNCTION_FULL_NAME(mf_eval)(float3 wi, float3 wo, const boo
|
|||
/* Bounce from the microfacet. */
|
||||
#ifdef MF_MULTI_GLASS
|
||||
bool next_outside;
|
||||
wr = mf_sample_phase_glass(-wr, outside? eta: 1.0f/eta, wm, lcg_step_float(lcg_state), &next_outside);
|
||||
wr = mf_sample_phase_glass(-wr, outside? eta: 1.0f/eta, wm, lcg_step_float_addrspace(lcg_state), &next_outside);
|
||||
if(!next_outside) {
|
||||
outside = !outside;
|
||||
wr = -wr;
|
||||
hr = -hr;
|
||||
}
|
||||
#elif defined(MF_MULTI_DIFFUSE)
|
||||
wr = mf_sample_phase_diffuse(wm, lcg_step_float(lcg_state), lcg_step_float(lcg_state));
|
||||
wr = mf_sample_phase_diffuse(wm,
|
||||
lcg_step_float_addrspace(lcg_state),
|
||||
lcg_step_float_addrspace(lcg_state));
|
||||
#else /* MF_MULTI_GLOSSY */
|
||||
wr = mf_sample_phase_glossy(-wr, n, k, &throughput, wm);
|
||||
#endif
|
||||
|
@ -179,13 +182,14 @@ ccl_device float3 MF_FUNCTION_FULL_NAME(mf_sample)(float3 wi, float3 *wo, const
|
|||
int order;
|
||||
for(order = 0; order < 10; order++) {
|
||||
/* Sample microfacet height. */
|
||||
if(!mf_sample_height(wr, &hr, &C1_r, &G1_r, &lambda_r, lcg_step_float(lcg_state))) {
|
||||
if(!mf_sample_height(wr, &hr, &C1_r, &G1_r, &lambda_r, lcg_step_float_addrspace(lcg_state))) {
|
||||
/* The random walk has left the surface. */
|
||||
*wo = outside? wr: -wr;
|
||||
return throughput;
|
||||
}
|
||||
/* Sample microfacet normal. */
|
||||
float3 wm = mf_sample_vndf(-wr, alpha, make_float2(lcg_step_float(lcg_state), lcg_step_float(lcg_state)));
|
||||
float3 wm = mf_sample_vndf(-wr, alpha, make_float2(lcg_step_float_addrspace(lcg_state),
|
||||
lcg_step_float_addrspace(lcg_state)));
|
||||
|
||||
/* First-bounce color is already accounted for in mix weight. */
|
||||
if(order > 0)
|
||||
|
@ -194,14 +198,16 @@ ccl_device float3 MF_FUNCTION_FULL_NAME(mf_sample)(float3 wi, float3 *wo, const
|
|||
/* Bounce from the microfacet. */
|
||||
#ifdef MF_MULTI_GLASS
|
||||
bool next_outside;
|
||||
wr = mf_sample_phase_glass(-wr, outside? eta: 1.0f/eta, wm, lcg_step_float(lcg_state), &next_outside);
|
||||
wr = mf_sample_phase_glass(-wr, outside? eta: 1.0f/eta, wm, lcg_step_float_addrspace(lcg_state), &next_outside);
|
||||
if(!next_outside) {
|
||||
hr = -hr;
|
||||
wr = -wr;
|
||||
outside = !outside;
|
||||
}
|
||||
#elif defined(MF_MULTI_DIFFUSE)
|
||||
wr = mf_sample_phase_diffuse(wm, lcg_step_float(lcg_state), lcg_step_float(lcg_state));
|
||||
wr = mf_sample_phase_diffuse(wm,
|
||||
lcg_step_float_addrspace(lcg_state),
|
||||
lcg_step_float_addrspace(lcg_state));
|
||||
#else /* MF_MULTI_GLOSSY */
|
||||
wr = mf_sample_phase_glossy(-wr, n, k, &throughput, wm);
|
||||
#endif
|
||||
|
|
|
@ -232,14 +232,14 @@ ccl_device void path_rng_end(KernelGlobals *kg, ccl_global uint *rng_state, RNG
|
|||
|
||||
/* Linear Congruential Generator */
|
||||
|
||||
ccl_device uint lcg_step_uint(ccl_addr_space uint *rng)
|
||||
ccl_device uint lcg_step_uint(uint *rng)
|
||||
{
|
||||
/* implicit mod 2^32 */
|
||||
*rng = (1103515245*(*rng) + 12345);
|
||||
return *rng;
|
||||
}
|
||||
|
||||
ccl_device float lcg_step_float(ccl_addr_space uint *rng)
|
||||
ccl_device float lcg_step_float(uint *rng)
|
||||
{
|
||||
/* implicit mod 2^32 */
|
||||
*rng = (1103515245*(*rng) + 12345);
|
||||
|
@ -314,5 +314,21 @@ ccl_device_inline uint lcg_state_init(RNG *rng, const ccl_addr_space PathState *
|
|||
return lcg_init(*rng + state->rng_offset + state->sample*scramble);
|
||||
}
|
||||
|
||||
/* TODO(sergey): For until we can use generic address space from OpenCL 2.0. */
|
||||
|
||||
ccl_device_inline uint lcg_state_init_addrspace(ccl_addr_space RNG *rng,
|
||||
const ccl_addr_space PathState *state,
|
||||
uint scramble)
|
||||
{
|
||||
return lcg_init(*rng + state->rng_offset + state->sample*scramble);
|
||||
}
|
||||
|
||||
ccl_device float lcg_step_float_addrspace(ccl_addr_space uint *rng)
|
||||
{
|
||||
/* implicit mod 2^32 */
|
||||
*rng = (1103515245*(*rng) + 12345);
|
||||
return (float)*rng * (1.0f/(float)0xFFFFFFFF);
|
||||
}
|
||||
|
||||
CCL_NAMESPACE_END
|
||||
|
||||
|
|
|
@ -827,7 +827,7 @@ ccl_device float3 shader_holdout_eval(KernelGlobals *kg, ShaderData *sd)
|
|||
|
||||
/* Surface Evaluation */
|
||||
|
||||
ccl_device void shader_eval_surface(KernelGlobals *kg, ShaderData *sd, RNG *rng,
|
||||
ccl_device void shader_eval_surface(KernelGlobals *kg, ShaderData *sd, ccl_addr_space RNG *rng,
|
||||
ccl_addr_space PathState *state, float randb, int path_flag, ShaderContext ctx)
|
||||
{
|
||||
ccl_fetch(sd, num_closure) = 0;
|
||||
|
@ -851,7 +851,7 @@ ccl_device void shader_eval_surface(KernelGlobals *kg, ShaderData *sd, RNG *rng,
|
|||
}
|
||||
|
||||
if(rng && (ccl_fetch(sd, flag) & SD_BSDF_NEEDS_LCG)) {
|
||||
ccl_fetch(sd, lcg_state) = lcg_state_init(rng, state, 0xb4bc3953);
|
||||
ccl_fetch(sd, lcg_state) = lcg_state_init_addrspace(rng, state, 0xb4bc3953);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue