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

Code before:
		default: {
			ERR_FAIL_MSG("This RD texture can't be used as a render texture");
		} break;
	}

	texture.width = tf.width;
	texture.height = tf.height;
	texture.depth = tf.depth;
	texture.layers = tf.array_layers;
	texture.mipmaps = tf.mipmaps;
	texture.format = imfmt.image_format;
	texture.validated_format = texture.format; // ??

	RD::TextureView rd_view;
	rd_view.format_override = imfmt.rd_format == tf.format ? RD::DATA_FORMAT_MAX : imfmt.rd_format;
	rd_view.swizzle_r = imfmt.swizzle_r;
	rd_view.swizzle_g = imfmt.swizzle_g;
	rd_view.swizzle_b = imfmt.swizzle_b;
	rd_view.swizzle_a = imfmt.swizzle_a;

	texture.rd_type = tf.texture_type;
	texture.rd_format = imfmt.rd_format;
	texture.rd_view = rd_view;

	if (imfmt.rd_format_srgb != RD::DATA_FORMAT_MAX) {
		// Allow creating shared srgb texture even users didn't explicitly add them.
		RD::get_singleton()->_texture_ensure_shareable_format(p_rd_texture, texture.rd_format);
		RD::get_singleton()->_texture_ensure_shareable_format(p_rd_texture, texture.rd_format_srgb);
	}

	// We create a shared texture here even if our view matches, so we don't obtain ownership.
	texture.rd_texture = RD::get_singleton()->texture_create_shared(rd_view, p_rd_texture);
	if (imfmt.rd_format_srgb != RD::DATA_FORMAT_MAX ) {
		// The texture support srgb override, create it for 3D usage.
		rd_view.format_override = imfmt.rd_format_srgb == tf.format ? RD::DATA_FORMAT_MAX : imfmt.rd_format_srgb;
		texture.rd_format_srgb = imfmt.rd_format_srgb;
		texture.rd_texture_srgb = RD::get_singleton()->texture_create_shared(rd_view, p_rd_texture);
	}

	// TODO figure out what to do with slices

	texture.width_2d = texture.width;
	texture.height_2d = texture.height;
	texture.is_render_target = false;
	texture.is_proxy = false;

	texture_owner.initialize_rid(p_texture, texture);
}

RID TextureStorage::texture_get_rd_texture(RID p_texture, bool p_srgb) const {
	if (p_texture.is_null()) {

Review comment (suggestion):
```suggestion
		// Allow creating a shared sRGB texture even if users didn't explicitly add them.
```

Code after:
				ERR_FAIL_COND_MSG(texture_2d_get_size(p_textures[i - 1]) != texture_2d_get_size(p_textures[i]), "All Blit_Rect output textures must be same size.");
			}
			tar_textures[i] = tex->cached_rd_slices[p_to_mipmap];
		}

		// Load and bind source textures, load default Black if source is bad.
		RD::Uniform u;
		u.uniform_type = RD::UNIFORM_TYPE_TEXTURE;
		u.binding = i;
		if (i < p_source_textures.size()) {
			src_textures[i] = get_texture(p_source_textures[i]);
			if (!src_textures[i]) {
				u.append_id(default_tex_rid);
			} else {
				u.append_id(src_textures[i]->rd_texture);
			}
		} else {
			u.append_id(default_tex_rid);
		}
		texture_uniforms.push_back(u);

		i += 1;
	}

	// Calculates the Rects Offset & Size in UV space for Shader to scale Vertex Quad correctly
	Vector2i size = texture_2d_get_size(p_textures[0]);
	Vector2 offset = Vector2(float(p_rect.position.x) / size.x, float(p_rect.position.y) / size.y);
	Vector2 rect_size = Vector2(float(p_rect.size.x) / size.x, float(p_rect.size.y) / size.y);

	// Select Pipeline based on # of targets.
	RID tex_blit_fb;
	PipelineCacheRD *pipeline;
	switch (p_textures.size()) {
		case 1:
			tex_blit_fb = FramebufferCacheRD::get_singleton()->get_cache(tar_textures[0]);
			pipeline = &shader_data->pipelines[0];
			break;
		case 2:
			tex_blit_fb = FramebufferCacheRD::get_singleton()->get_cache(tar_textures[0], tar_textures[1]);
			pipeline = &shader_data->pipelines[1];
			break;
		case 3:
			tex_blit_fb = FramebufferCacheRD::get_singleton()->get_cache(tar_textures[0], tar_textures[1], tar_textures[2]);
			pipeline = &shader_data->pipelines[2];
			break;
		case 4:
			tex_blit_fb = FramebufferCacheRD::get_singleton()->get_cache(tar_textures[0], tar_textures[1], tar_textures[2], tar_textures[3]);
			pipeline = &shader_data->pipelines[3];
			break;
		default:
			tex_blit_fb = FramebufferCacheRD::get_singleton()->get_cache(tar_textures[0], tar_textures[1], tar_textures[2], tar_textures[3]);