Repository: godotengine/godot
File: servers/rendering/renderer_rd/renderer_scene_render_rd.cpp (C++)

Code before:
		if (spatial_upscaler != nullptr || use_smaa) {
			// If we use a spatial upscaler to upscale or SMAA to antialias we need to write our result into an intermediate buffer.
			// Note that this is cached so we only create the texture the first time.
			dest_fb_format = rb->get_base_data_format();
			RID dest_texture = rb->create_texture(SNAME("Tonemapper"), SNAME("destination"), dest_fb_format, RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_STORAGE_BIT | RD::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT, RD::TEXTURE_SAMPLES_1, Size2i(), 0, 1, true, true);
			dest_fb = FramebufferCacheRD::get_singleton()->get_cache(dest_texture);
			tonemap.dest_texture_size = rb->get_internal_size();
		} else {
			// If we do a bilinear upscale we just render into our render target and our shader will upscale automatically.
			// Target size in this case is lying as we never get our real target size communicated.
			// Bit nasty but...

			if (dest_is_msaa_2d) {
				dest_fb = FramebufferCacheRD::get_singleton()->get_cache(texture_storage->render_target_get_rd_texture_msaa(render_target));
				texture_storage->render_target_set_msaa_needs_resolve(render_target, true); // Make sure this gets resolved.
			} else {
				dest_fb = texture_storage->render_target_get_rd_framebuffer(render_target);
			}
			tonemap.dest_texture_size = texture_storage->render_target_get_size(render_target);
		}

		tonemap.debanding_mode = RendererRD::ToneMapper::TonemapSettings::DebandingMode::DEBANDING_MODE_DISABLED;
		if (rb->get_use_debanding() && !using_hdr) {
			if (use_smaa) {
				// SMAA will apply 8-bit debanding, so tonemap debanding must match its intermediate destination buffer,
				// which is 16 bit float for can_use_storage (i.e. Forward+) and 10 bit integer otherwise (i.e. Mobile).
				// This stage of debanding is especially needed for glow effects.
				if (!can_use_storage) {
					tonemap.debanding_mode = RendererRD::ToneMapper::TonemapSettings::DebandingMode::DEBANDING_MODE_10_BIT;
				}
			} else {
				// The final destination buffer of this viewport will be 8-bit integer, so match that format.
				tonemap.debanding_mode = RendererRD::ToneMapper::TonemapSettings::DebandingMode::DEBANDING_MODE_8_BIT;
			}
		}

		if (can_use_storage) {
			tone_mapper->tonemapper(color_texture, dest_fb, tonemap);
		} else {
			tone_mapper->tonemapper_mobile(color_texture, dest_fb, tonemap);
		}

		RD::get_singleton()->draw_command_end_label();
	}

	if (use_smaa) {
		RENDER_TIMESTAMP("SMAA");
		RD::get_singleton()->draw_command_begin_label("SMAA");

		bool using_hdr = texture_storage->render_target_is_using_hdr(render_target);


Review comment (suggestion):
The comment makes it sound like debanding is being performed whether we are using Forward+ or Mobile. From what I understand, it isn't supposed to happen on Forward+. I would say either specify it doesn't happen on Forward+ or remove the `if` statement, because I don't think `DEBANDING_MODE_10_BIT` does anything on Forward+ anyways.

Code after:
		if (spatial_upscaler != nullptr || use_smaa) {
			// If we use a spatial upscaler to upscale or SMAA to antialias we need to write our result into an intermediate buffer.
			// Note that this is cached so we only create the texture the first time.
			dest_fb_format = rb->get_base_data_format();
			RID dest_texture = rb->create_texture(SNAME("Tonemapper"), SNAME("destination"), dest_fb_format, RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_STORAGE_BIT | RD::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT, RD::TEXTURE_SAMPLES_1, Size2i(), 0, 1, true, true);
			dest_fb = FramebufferCacheRD::get_singleton()->get_cache(dest_texture);
			tonemap.dest_texture_size = rb->get_internal_size();
		} else {
			// If we do a bilinear upscale we just render into our render target and our shader will upscale automatically.
			// Target size in this case is lying as we never get our real target size communicated.
			// Bit nasty but...

			if (dest_is_msaa_2d) {
				dest_fb = FramebufferCacheRD::get_singleton()->get_cache(texture_storage->render_target_get_rd_texture_msaa(render_target));
				texture_storage->render_target_set_msaa_needs_resolve(render_target, true); // Make sure this gets resolved.
			} else {
				dest_fb = texture_storage->render_target_get_rd_framebuffer(render_target);
			}
			tonemap.dest_texture_size = texture_storage->render_target_get_size(render_target);
		}

		tonemap.debanding_mode = RendererRD::ToneMapper::TonemapSettings::DebandingMode::DEBANDING_MODE_DISABLED;
		if (rb->get_use_debanding() && !using_hdr) {
			if (use_smaa) {
				// SMAA will apply 8-bit debanding.
				if (!can_use_storage) {
					// When can_use_storage is false, the intermediate destination buffer will be 10 bit, so
					// additional tonemap debanding is needed.
					// This stage of debanding is especially needed for glow effects.
					tonemap.debanding_mode = RendererRD::ToneMapper::TonemapSettings::DebandingMode::DEBANDING_MODE_10_BIT;
				}
			} else {
				// The final destination buffer of this viewport will be 8-bit integer, so match that format.
				tonemap.debanding_mode = RendererRD::ToneMapper::TonemapSettings::DebandingMode::DEBANDING_MODE_8_BIT;
			}
		}

		if (can_use_storage) {
			tone_mapper->tonemapper(color_texture, dest_fb, tonemap);
		} else {
			tone_mapper->tonemapper_mobile(color_texture, dest_fb, tonemap);
		}

		RD::get_singleton()->draw_command_end_label();
	}

	if (use_smaa) {
		RENDER_TIMESTAMP("SMAA");
		RD::get_singleton()->draw_command_begin_label("SMAA");

		bool using_hdr = texture_storage->render_target_is_using_hdr(render_target);