diff options
author | Brecht Van Lommel <brecht> | 2021-10-17 17:22:20 +0300 |
---|---|---|
committer | Brecht Van Lommel <brecht@blender.org> | 2021-10-19 16:09:29 +0300 |
commit | 943e73b07e26d64c04ccb7d8f656e3818a57cca0 (patch) | |
tree | 870e21cb9b8c49878138e16360178ee293b78f6c /intern/cycles/kernel/osl | |
parent | 6e473a897ce563ad04224bdd731387b0dbd22235 (diff) |
Cycles: decouple shadow paths from main path on GPU
The motivation for this is twofold. It improves performance (5-10% on most
benchmark scenes), and will help to bring back transparency support for the
ambient occlusion pass.
* Duplicate some members from the main path state in the shadow path state.
* Add shadow paths incrementally to the array similar to what we do for
the shadow catchers.
* For the scheduling, allow running shade surface and shade volume kernels
as long as there is enough space in the shadow paths array. If not, execute
shadow kernels until it is empty.
* Add IntegratorShadowState and ConstIntegratorShadowState typedefs that
can be different between CPU and GPU. For GPU both main and shadow paths
juse have an integer for SoA access. Bt with CPU it's a different pointer
type so we get type safety checks in code shared between CPU and GPU.
* For CPU, add a separate IntegratorShadowStateCPU struct embedded in
IntegratorShadowState.
* Update various functions to take the shadow state, and make SVM take either
type of state using templates.
Differential Revision: https://developer.blender.org/D12889
Diffstat (limited to 'intern/cycles/kernel/osl')
-rw-r--r-- | intern/cycles/kernel/osl/osl_services.cpp | 69 | ||||
-rw-r--r-- | intern/cycles/kernel/osl/osl_shader.cpp | 19 | ||||
-rw-r--r-- | intern/cycles/kernel/osl/osl_shader.h | 10 |
3 files changed, 58 insertions, 40 deletions
diff --git a/intern/cycles/kernel/osl/osl_services.cpp b/intern/cycles/kernel/osl/osl_services.cpp index bb7655fbe9a..cbe1bf1bfc0 100644 --- a/intern/cycles/kernel/osl/osl_services.cpp +++ b/intern/cycles/kernel/osl/osl_services.cpp @@ -1015,31 +1015,44 @@ bool OSLRenderServices::get_background_attribute(const KernelGlobalsCPU *kg, else if (name == u_path_ray_depth) { /* Ray Depth */ const IntegratorStateCPU *state = sd->osl_path_state; - int f = state->path.bounce; + const IntegratorShadowStateCPU *shadow_state = sd->osl_shadow_path_state; + int f = (state) ? state->path.bounce : (shadow_state) ? shadow_state->shadow_path.bounce : 0; return set_attribute_int(f, type, derivatives, val); } else if (name == u_path_diffuse_depth) { /* Diffuse Ray Depth */ const IntegratorStateCPU *state = sd->osl_path_state; - int f = state->path.diffuse_bounce; + const IntegratorShadowStateCPU *shadow_state = sd->osl_shadow_path_state; + int f = (state) ? state->path.diffuse_bounce : + (shadow_state) ? shadow_state->shadow_path.diffuse_bounce : + 0; return set_attribute_int(f, type, derivatives, val); } else if (name == u_path_glossy_depth) { /* Glossy Ray Depth */ const IntegratorStateCPU *state = sd->osl_path_state; - int f = state->path.glossy_bounce; + const IntegratorShadowStateCPU *shadow_state = sd->osl_shadow_path_state; + int f = (state) ? state->path.glossy_bounce : + (shadow_state) ? shadow_state->shadow_path.glossy_bounce : + 0; return set_attribute_int(f, type, derivatives, val); } else if (name == u_path_transmission_depth) { /* Transmission Ray Depth */ const IntegratorStateCPU *state = sd->osl_path_state; - int f = state->path.transmission_bounce; + const IntegratorShadowStateCPU *shadow_state = sd->osl_shadow_path_state; + int f = (state) ? state->path.transmission_bounce : + (shadow_state) ? shadow_state->shadow_path.transmission_bounce : + 0; return set_attribute_int(f, type, derivatives, val); } else if (name == u_path_transparent_depth) { /* Transparent Ray Depth */ const IntegratorStateCPU *state = sd->osl_path_state; - int f = state->path.transparent_bounce; + const IntegratorShadowStateCPU *shadow_state = sd->osl_shadow_path_state; + int f = (state) ? state->path.transparent_bounce : + (shadow_state) ? shadow_state->shadow_path.transparent_bounce : + 0; return set_attribute_int(f, type, derivatives, val); } else if (name == u_ndc) { @@ -1228,34 +1241,38 @@ bool OSLRenderServices::texture(ustring filename, /* Bevel shader hack. */ if (nchannels >= 3) { const IntegratorStateCPU *state = sd->osl_path_state; - int num_samples = (int)s; - float radius = t; - float3 N = svm_bevel(kernel_globals, state, sd, radius, num_samples); - result[0] = N.x; - result[1] = N.y; - result[2] = N.z; - status = true; + if (state) { + int num_samples = (int)s; + float radius = t; + float3 N = svm_bevel(kernel_globals, state, sd, radius, num_samples); + result[0] = N.x; + result[1] = N.y; + result[2] = N.z; + status = true; + } } break; } case OSLTextureHandle::AO: { /* AO shader hack. */ const IntegratorStateCPU *state = sd->osl_path_state; - int num_samples = (int)s; - float radius = t; - float3 N = make_float3(dsdx, dtdx, dsdy); - int flags = 0; - if ((int)dtdy) { - flags |= NODE_AO_INSIDE; - } - if ((int)options.sblur) { - flags |= NODE_AO_ONLY_LOCAL; - } - if ((int)options.tblur) { - flags |= NODE_AO_GLOBAL_RADIUS; + if (state) { + int num_samples = (int)s; + float radius = t; + float3 N = make_float3(dsdx, dtdx, dsdy); + int flags = 0; + if ((int)dtdy) { + flags |= NODE_AO_INSIDE; + } + if ((int)options.sblur) { + flags |= NODE_AO_ONLY_LOCAL; + } + if ((int)options.tblur) { + flags |= NODE_AO_GLOBAL_RADIUS; + } + result[0] = svm_ao(kernel_globals, state, sd, N, radius, num_samples, flags); + status = true; } - result[0] = svm_ao(kernel_globals, state, sd, N, radius, num_samples, flags); - status = true; break; } case OSLTextureHandle::SVM: { diff --git a/intern/cycles/kernel/osl/osl_shader.cpp b/intern/cycles/kernel/osl/osl_shader.cpp index 4c067e88ab6..fba207e7230 100644 --- a/intern/cycles/kernel/osl/osl_shader.cpp +++ b/intern/cycles/kernel/osl/osl_shader.cpp @@ -89,7 +89,7 @@ void OSLShader::thread_free(KernelGlobalsCPU *kg) static void shaderdata_to_shaderglobals(const KernelGlobalsCPU *kg, ShaderData *sd, - const IntegratorStateCPU *state, + const void *state, uint32_t path_flag, OSLThreadData *tdata) { @@ -134,7 +134,12 @@ static void shaderdata_to_shaderglobals(const KernelGlobalsCPU *kg, /* Used by render-services. */ sd->osl_globals = kg; - sd->osl_path_state = state; + if (path_flag & PATH_RAY_SHADOW) { + sd->osl_shadow_path_state = (const IntegratorShadowStateCPU *)state; + } + else { + sd->osl_path_state = (const IntegratorStateCPU *)state; + } } /* Surface */ @@ -175,7 +180,7 @@ static void flatten_surface_closure_tree(ShaderData *sd, } void OSLShader::eval_surface(const KernelGlobalsCPU *kg, - const IntegratorStateCPU *state, + const void *state, ShaderData *sd, uint32_t path_flag) { @@ -283,7 +288,7 @@ static void flatten_background_closure_tree(ShaderData *sd, } void OSLShader::eval_background(const KernelGlobalsCPU *kg, - const IntegratorStateCPU *state, + const void *state, ShaderData *sd, uint32_t path_flag) { @@ -341,7 +346,7 @@ static void flatten_volume_closure_tree(ShaderData *sd, } void OSLShader::eval_volume(const KernelGlobalsCPU *kg, - const IntegratorStateCPU *state, + const void *state, ShaderData *sd, uint32_t path_flag) { @@ -366,9 +371,7 @@ void OSLShader::eval_volume(const KernelGlobalsCPU *kg, /* Displacement */ -void OSLShader::eval_displacement(const KernelGlobalsCPU *kg, - const IntegratorStateCPU *state, - ShaderData *sd) +void OSLShader::eval_displacement(const KernelGlobalsCPU *kg, const void *state, ShaderData *sd) { /* setup shader globals from shader data */ OSLThreadData *tdata = kg->osl_tdata; diff --git a/intern/cycles/kernel/osl/osl_shader.h b/intern/cycles/kernel/osl/osl_shader.h index 2b3810b0a33..037a18a1f19 100644 --- a/intern/cycles/kernel/osl/osl_shader.h +++ b/intern/cycles/kernel/osl/osl_shader.h @@ -55,20 +55,18 @@ class OSLShader { /* eval */ static void eval_surface(const KernelGlobalsCPU *kg, - const IntegratorStateCPU *state, + const void *state, ShaderData *sd, uint32_t path_flag); static void eval_background(const KernelGlobalsCPU *kg, - const IntegratorStateCPU *state, + const void *state, ShaderData *sd, uint32_t path_flag); static void eval_volume(const KernelGlobalsCPU *kg, - const IntegratorStateCPU *state, + const void *state, ShaderData *sd, uint32_t path_flag); - static void eval_displacement(const KernelGlobalsCPU *kg, - const IntegratorStateCPU *state, - ShaderData *sd); + static void eval_displacement(const KernelGlobalsCPU *kg, const void *state, ShaderData *sd); /* attributes */ static int find_attribute(const KernelGlobalsCPU *kg, |