Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/integrator/pass_accessor.cpp
| Show First 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | PassAccessor::Destination::Destination(const PassType pass_type, half4 *pixels) | ||||
| : Destination(pass_type) | : Destination(pass_type) | ||||
| { | { | ||||
| pixels_half_rgba = pixels; | pixels_half_rgba = pixels; | ||||
| } | } | ||||
| PassAccessor::Destination::Destination(const PassType pass_type) | PassAccessor::Destination::Destination(const PassType pass_type) | ||||
| { | { | ||||
| const PassInfo pass_info = Pass::get_info(pass_type); | const PassInfo pass_info = Pass::get_info(pass_type); | ||||
| if (pass_info.divide_type != PASS_NONE) { | |||||
| /* Divide is used for colors, which has 3 destination components. | |||||
| * The passes which use division are stored as aligned float4 internally, and there is no | |||||
| * implementation of divide_even_color for float4. So we force it here. | |||||
| * The rest of the aligned float3 passes should be fine, because they have float4 | |||||
| * implementation. */ | |||||
| num_components = 3; | |||||
| } | |||||
| else { | |||||
| num_components = pass_info.num_components; | num_components = pass_info.num_components; | ||||
| } | } | ||||
| } | |||||
| /* -------------------------------------------------------------------- | /* -------------------------------------------------------------------- | ||||
| * Pass source. | * Pass source. | ||||
| */ | */ | ||||
| PassAccessor::Source::Source(const float *pixels, int num_components) | PassAccessor::Source::Source(const float *pixels, int num_components) | ||||
| : pixels(pixels), num_components(num_components) | : pixels(pixels), num_components(num_components) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | bool PassAccessor::get_render_tile_pixels(const RenderBuffers *render_buffers, | ||||
| if (render_buffers == nullptr || render_buffers->buffer.data() == nullptr) { | if (render_buffers == nullptr || render_buffers->buffer.data() == nullptr) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| const PassType type = pass_access_info_.type; | const PassType type = pass_access_info_.type; | ||||
| const PassMode mode = pass_access_info_.mode; | const PassMode mode = pass_access_info_.mode; | ||||
| const PassInfo pass_info = Pass::get_info(type); | const PassInfo pass_info = Pass::get_info(type); | ||||
| if (destination.num_components == 1) { | |||||
| DCHECK_LE(pass_info.num_components, destination.num_components) | DCHECK_LE(pass_info.num_components, destination.num_components) | ||||
| << "Number of components mismatch for " << pass_type_as_string(type); | << "Number of components mismatch for " << pass_type_as_string(type); | ||||
| if (pass_info.num_components == 1) { | |||||
| if (mode == PassMode::DENOISED) { | if (mode == PassMode::DENOISED) { | ||||
| /* Denoised passes store their final pixels, no need in special calculation. */ | /* Denoised passes store their final pixels, no need in special calculation. */ | ||||
| get_pass_float(render_buffers, buffer_params, destination); | get_pass_float(render_buffers, buffer_params, destination); | ||||
| } | } | ||||
| else if (type == PASS_RENDER_TIME) { | else if (type == PASS_RENDER_TIME) { | ||||
| /* TODO(sergey): Needs implementation. */ | /* TODO(sergey): Needs implementation. */ | ||||
| } | } | ||||
| else if (type == PASS_DEPTH) { | else if (type == PASS_DEPTH) { | ||||
| get_pass_depth(render_buffers, buffer_params, destination); | get_pass_depth(render_buffers, buffer_params, destination); | ||||
| } | } | ||||
| else if (type == PASS_MIST) { | else if (type == PASS_MIST) { | ||||
| get_pass_mist(render_buffers, buffer_params, destination); | get_pass_mist(render_buffers, buffer_params, destination); | ||||
| } | } | ||||
| else if (type == PASS_SAMPLE_COUNT) { | else if (type == PASS_SAMPLE_COUNT) { | ||||
| get_pass_sample_count(render_buffers, buffer_params, destination); | get_pass_sample_count(render_buffers, buffer_params, destination); | ||||
| } | } | ||||
| else { | else { | ||||
| get_pass_float(render_buffers, buffer_params, destination); | get_pass_float(render_buffers, buffer_params, destination); | ||||
| } | } | ||||
| } | } | ||||
| else if (destination.num_components == 3) { | else if (pass_info.num_components == 3) { | ||||
| if (pass_info.is_aligned) { | |||||
| DCHECK_LE(pass_info.num_components, 4) | |||||
| << "Number of components mismatch for pass " << pass_type_as_string(type); | |||||
| } | |||||
| else { | |||||
| DCHECK_LE(pass_info.num_components, 3) | |||||
| << "Number of components mismatch for pass " << pass_type_as_string(type); | |||||
| } | |||||
| if (mode == PassMode::DENOISED) { | if (mode == PassMode::DENOISED) { | ||||
| /* Denoised passes store their final pixels, no need in special calculation. */ | /* Denoised passes store their final pixels, no need in special calculation. */ | ||||
| get_pass_float3(render_buffers, buffer_params, destination); | get_pass_float3(render_buffers, buffer_params, destination); | ||||
| } | } | ||||
| else if (pass_info.divide_type != PASS_NONE) { | else if (pass_info.divide_type != PASS_NONE) { | ||||
| /* RGB lighting passes that need to divide out color */ | /* RGB lighting passes that need to divide out color */ | ||||
| get_pass_divide_even_color(render_buffers, buffer_params, destination); | get_pass_divide_even_color(render_buffers, buffer_params, destination); | ||||
| } | } | ||||
| else if (type == PASS_SHADOW_CATCHER) { | else if (type == PASS_SHADOW_CATCHER) { | ||||
| get_pass_shadow_catcher(render_buffers, buffer_params, destination); | get_pass_shadow_catcher(render_buffers, buffer_params, destination); | ||||
| } | } | ||||
| else { | else { | ||||
| /* RGB/vector */ | /* RGB/vector */ | ||||
| get_pass_float3(render_buffers, buffer_params, destination); | get_pass_float3(render_buffers, buffer_params, destination); | ||||
| } | } | ||||
| } | } | ||||
| else if (destination.num_components == 4) { | else if (pass_info.num_components == 4) { | ||||
| DCHECK_EQ(pass_info.num_components, 4) | |||||
| << "Number of components mismatch for pass " << pass_type_as_string(type); | |||||
| if (type == PASS_SHADOW_CATCHER_MATTE && pass_access_info_.use_approximate_shadow_catcher) { | if (type == PASS_SHADOW_CATCHER_MATTE && pass_access_info_.use_approximate_shadow_catcher) { | ||||
| /* Denoised matte with shadow needs to do calculation (will use denoised shadow catcher pass | /* Denoised matte with shadow needs to do calculation (will use denoised shadow catcher pass | ||||
| * to approximate shadow with). */ | * to approximate shadow with). */ | ||||
| get_pass_shadow_catcher_matte_with_shadow(render_buffers, buffer_params, destination); | get_pass_shadow_catcher_matte_with_shadow(render_buffers, buffer_params, destination); | ||||
| } | } | ||||
| else if (mode == PassMode::DENOISED) { | else if (mode == PassMode::DENOISED) { | ||||
| /* Denoised passes store their final pixels, no need in special calculation. */ | /* Denoised passes store their final pixels, no need in special calculation. */ | ||||
| if (type == PASS_COMBINED || type == PASS_SHADOW_CATCHER || | if (type == PASS_COMBINED || type == PASS_SHADOW_CATCHER || | ||||
| ▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| bool PassAccessor::set_render_tile_pixels(RenderBuffers *render_buffers, const Source &source) | bool PassAccessor::set_render_tile_pixels(RenderBuffers *render_buffers, const Source &source) | ||||
| { | { | ||||
| if (render_buffers == nullptr || render_buffers->buffer.data() == nullptr) { | if (render_buffers == nullptr || render_buffers->buffer.data() == nullptr) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| const PassType type = pass_access_info_.type; | |||||
| const PassInfo pass_info = Pass::get_info(type); | |||||
| const BufferParams &buffer_params = render_buffers->params; | const BufferParams &buffer_params = render_buffers->params; | ||||
| float *buffer_data = render_buffers->buffer.data(); | float *buffer_data = render_buffers->buffer.data(); | ||||
| const int pass_stride = buffer_params.pass_stride; | |||||
| const int size = buffer_params.width * buffer_params.height; | const int size = buffer_params.width * buffer_params.height; | ||||
| const int num_components = source.num_components; | |||||
| const int out_stride = buffer_params.pass_stride; | |||||
| const int in_stride = source.num_components; | |||||
| const int num_components_to_copy = min(source.num_components, pass_info.num_components); | |||||
| float *out = buffer_data + pass_access_info_.offset; | float *out = buffer_data + pass_access_info_.offset; | ||||
| const float *in = source.pixels + source.offset * num_components; | const float *in = source.pixels + source.offset * in_stride; | ||||
| for (int i = 0; i < size; i++, out += pass_stride, in += num_components) { | for (int i = 0; i < size; i++, out += out_stride, in += in_stride) { | ||||
| memcpy(out, in, sizeof(float) * num_components); | memcpy(out, in, sizeof(float) * num_components_to_copy); | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| CCL_NAMESPACE_END | CCL_NAMESPACE_END | ||||