mirror of
				https://git.tardis.systems/mirrors/yuzu
				synced 2025-11-04 04:34:07 +01:00 
			
		
		
		
	Texture Cache: Rescale conversions between depth and color
This commit is contained in:
		
							parent
							
								
									ef1dc42635
								
							
						
					
					
						commit
						d4f5193bd3
					
				@ -84,7 +84,7 @@ public:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    void CopyImage(Image& dst, Image& src, std::span<const VideoCommon::ImageCopy> copies);
 | 
					    void CopyImage(Image& dst, Image& src, std::span<const VideoCommon::ImageCopy> copies);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void ConvertImage(Framebuffer* dst, ImageView& dst_view, ImageView& src_view) {
 | 
					    void ConvertImage(Framebuffer* dst, ImageView& dst_view, ImageView& src_view, bool rescaled) {
 | 
				
			||||||
        UNIMPLEMENTED();
 | 
					        UNIMPLEMENTED();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -418,40 +418,45 @@ void BlitImageHelper::BlitDepthStencil(const Framebuffer* dst_framebuffer,
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void BlitImageHelper::ConvertD32ToR32(const Framebuffer* dst_framebuffer,
 | 
					void BlitImageHelper::ConvertD32ToR32(const Framebuffer* dst_framebuffer,
 | 
				
			||||||
                                      const ImageView& src_image_view) {
 | 
					                                      const ImageView& src_image_view, u32 up_scale,
 | 
				
			||||||
 | 
					                                      u32 down_shift) {
 | 
				
			||||||
    ConvertDepthToColorPipeline(convert_d32_to_r32_pipeline, dst_framebuffer->RenderPass());
 | 
					    ConvertDepthToColorPipeline(convert_d32_to_r32_pipeline, dst_framebuffer->RenderPass());
 | 
				
			||||||
    Convert(*convert_d32_to_r32_pipeline, dst_framebuffer, src_image_view);
 | 
					    Convert(*convert_d32_to_r32_pipeline, dst_framebuffer, src_image_view, up_scale, down_shift);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void BlitImageHelper::ConvertR32ToD32(const Framebuffer* dst_framebuffer,
 | 
					void BlitImageHelper::ConvertR32ToD32(const Framebuffer* dst_framebuffer,
 | 
				
			||||||
                                      const ImageView& src_image_view) {
 | 
					                                      const ImageView& src_image_view, u32 up_scale,
 | 
				
			||||||
 | 
					                                      u32 down_shift) {
 | 
				
			||||||
    ConvertColorToDepthPipeline(convert_r32_to_d32_pipeline, dst_framebuffer->RenderPass());
 | 
					    ConvertColorToDepthPipeline(convert_r32_to_d32_pipeline, dst_framebuffer->RenderPass());
 | 
				
			||||||
    Convert(*convert_r32_to_d32_pipeline, dst_framebuffer, src_image_view);
 | 
					    Convert(*convert_r32_to_d32_pipeline, dst_framebuffer, src_image_view, up_scale, down_shift);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void BlitImageHelper::ConvertD16ToR16(const Framebuffer* dst_framebuffer,
 | 
					void BlitImageHelper::ConvertD16ToR16(const Framebuffer* dst_framebuffer,
 | 
				
			||||||
                                      const ImageView& src_image_view) {
 | 
					                                      const ImageView& src_image_view, u32 up_scale,
 | 
				
			||||||
 | 
					                                      u32 down_shift) {
 | 
				
			||||||
    ConvertDepthToColorPipeline(convert_d16_to_r16_pipeline, dst_framebuffer->RenderPass());
 | 
					    ConvertDepthToColorPipeline(convert_d16_to_r16_pipeline, dst_framebuffer->RenderPass());
 | 
				
			||||||
    Convert(*convert_d16_to_r16_pipeline, dst_framebuffer, src_image_view);
 | 
					    Convert(*convert_d16_to_r16_pipeline, dst_framebuffer, src_image_view, up_scale, down_shift);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void BlitImageHelper::ConvertR16ToD16(const Framebuffer* dst_framebuffer,
 | 
					void BlitImageHelper::ConvertR16ToD16(const Framebuffer* dst_framebuffer,
 | 
				
			||||||
                                      const ImageView& src_image_view) {
 | 
					                                      const ImageView& src_image_view, u32 up_scale,
 | 
				
			||||||
 | 
					                                      u32 down_shift) {
 | 
				
			||||||
    ConvertColorToDepthPipeline(convert_r16_to_d16_pipeline, dst_framebuffer->RenderPass());
 | 
					    ConvertColorToDepthPipeline(convert_r16_to_d16_pipeline, dst_framebuffer->RenderPass());
 | 
				
			||||||
    Convert(*convert_r16_to_d16_pipeline, dst_framebuffer, src_image_view);
 | 
					    Convert(*convert_r16_to_d16_pipeline, dst_framebuffer, src_image_view, up_scale, down_shift);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void BlitImageHelper::Convert(VkPipeline pipeline, const Framebuffer* dst_framebuffer,
 | 
					void BlitImageHelper::Convert(VkPipeline pipeline, const Framebuffer* dst_framebuffer,
 | 
				
			||||||
                              const ImageView& src_image_view) {
 | 
					                              const ImageView& src_image_view, u32 up_scale, u32 down_shift) {
 | 
				
			||||||
    const VkPipelineLayout layout = *one_texture_pipeline_layout;
 | 
					    const VkPipelineLayout layout = *one_texture_pipeline_layout;
 | 
				
			||||||
    const VkImageView src_view = src_image_view.Handle(Shader::TextureType::Color2D);
 | 
					    const VkImageView src_view = src_image_view.Handle(Shader::TextureType::Color2D);
 | 
				
			||||||
    const VkSampler sampler = *nearest_sampler;
 | 
					    const VkSampler sampler = *nearest_sampler;
 | 
				
			||||||
    const VkExtent2D extent{
 | 
					    const VkExtent2D extent{
 | 
				
			||||||
        .width = src_image_view.size.width,
 | 
					        .width = std::max((src_image_view.size.width * up_scale) >> down_shift, 1U),
 | 
				
			||||||
        .height = src_image_view.size.height,
 | 
					        .height = std::max((src_image_view.size.height * up_scale) >> down_shift, 1U),
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    scheduler.RequestRenderpass(dst_framebuffer);
 | 
					    scheduler.RequestRenderpass(dst_framebuffer);
 | 
				
			||||||
    scheduler.Record([pipeline, layout, sampler, src_view, extent, this](vk::CommandBuffer cmdbuf) {
 | 
					    scheduler.Record([pipeline, layout, sampler, src_view, extent, up_scale, down_shift,
 | 
				
			||||||
 | 
					                      this](vk::CommandBuffer cmdbuf) {
 | 
				
			||||||
        const VkOffset2D offset{
 | 
					        const VkOffset2D offset{
 | 
				
			||||||
            .x = 0,
 | 
					            .x = 0,
 | 
				
			||||||
            .y = 0,
 | 
					            .y = 0,
 | 
				
			||||||
 | 
				
			|||||||
@ -44,17 +44,21 @@ public:
 | 
				
			|||||||
                          const Region2D& src_region, Tegra::Engines::Fermi2D::Filter filter,
 | 
					                          const Region2D& src_region, Tegra::Engines::Fermi2D::Filter filter,
 | 
				
			||||||
                          Tegra::Engines::Fermi2D::Operation operation);
 | 
					                          Tegra::Engines::Fermi2D::Operation operation);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void ConvertD32ToR32(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
 | 
					    void ConvertD32ToR32(const Framebuffer* dst_framebuffer, const ImageView& src_image_view,
 | 
				
			||||||
 | 
					                         u32 up_scale, u32 down_shift);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void ConvertR32ToD32(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
 | 
					    void ConvertR32ToD32(const Framebuffer* dst_framebuffer, const ImageView& src_image_view,
 | 
				
			||||||
 | 
					                         u32 up_scale, u32 down_shift);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void ConvertD16ToR16(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
 | 
					    void ConvertD16ToR16(const Framebuffer* dst_framebuffer, const ImageView& src_image_view,
 | 
				
			||||||
 | 
					                         u32 up_scale, u32 down_shift);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void ConvertR16ToD16(const Framebuffer* dst_framebuffer, const ImageView& src_image_view);
 | 
					    void ConvertR16ToD16(const Framebuffer* dst_framebuffer, const ImageView& src_image_view,
 | 
				
			||||||
 | 
					                         u32 up_scale, u32 down_shift);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    void Convert(VkPipeline pipeline, const Framebuffer* dst_framebuffer,
 | 
					    void Convert(VkPipeline pipeline, const Framebuffer* dst_framebuffer,
 | 
				
			||||||
                 const ImageView& src_image_view);
 | 
					                 const ImageView& src_image_view, u32 up_scale, u32 down_shift);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [[nodiscard]] VkPipeline FindOrEmplacePipeline(const BlitImagePipelineKey& key);
 | 
					    [[nodiscard]] VkPipeline FindOrEmplacePipeline(const BlitImagePipelineKey& key);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -867,26 +867,29 @@ void TextureCacheRuntime::BlitImage(Framebuffer* dst_framebuffer, ImageView& dst
 | 
				
			|||||||
    });
 | 
					    });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void TextureCacheRuntime::ConvertImage(Framebuffer* dst, ImageView& dst_view, ImageView& src_view) {
 | 
					void TextureCacheRuntime::ConvertImage(Framebuffer* dst, ImageView& dst_view, ImageView& src_view,
 | 
				
			||||||
 | 
					                                       bool rescaled) {
 | 
				
			||||||
 | 
					    const u32 up_scale = rescaled ? resolution.up_scale : 1;
 | 
				
			||||||
 | 
					    const u32 down_shift = rescaled ? resolution.down_shift : 0;
 | 
				
			||||||
    switch (dst_view.format) {
 | 
					    switch (dst_view.format) {
 | 
				
			||||||
    case PixelFormat::R16_UNORM:
 | 
					    case PixelFormat::R16_UNORM:
 | 
				
			||||||
        if (src_view.format == PixelFormat::D16_UNORM) {
 | 
					        if (src_view.format == PixelFormat::D16_UNORM) {
 | 
				
			||||||
            return blit_image_helper.ConvertD16ToR16(dst, src_view);
 | 
					            return blit_image_helper.ConvertD16ToR16(dst, src_view, up_scale, down_shift);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
    case PixelFormat::R32_FLOAT:
 | 
					    case PixelFormat::R32_FLOAT:
 | 
				
			||||||
        if (src_view.format == PixelFormat::D32_FLOAT) {
 | 
					        if (src_view.format == PixelFormat::D32_FLOAT) {
 | 
				
			||||||
            return blit_image_helper.ConvertD32ToR32(dst, src_view);
 | 
					            return blit_image_helper.ConvertD32ToR32(dst, src_view, up_scale, down_shift);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
    case PixelFormat::D16_UNORM:
 | 
					    case PixelFormat::D16_UNORM:
 | 
				
			||||||
        if (src_view.format == PixelFormat::R16_UNORM) {
 | 
					        if (src_view.format == PixelFormat::R16_UNORM) {
 | 
				
			||||||
            return blit_image_helper.ConvertR16ToD16(dst, src_view);
 | 
					            return blit_image_helper.ConvertR16ToD16(dst, src_view, up_scale, down_shift);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
    case PixelFormat::D32_FLOAT:
 | 
					    case PixelFormat::D32_FLOAT:
 | 
				
			||||||
        if (src_view.format == PixelFormat::R32_FLOAT) {
 | 
					        if (src_view.format == PixelFormat::R32_FLOAT) {
 | 
				
			||||||
            return blit_image_helper.ConvertR32ToD32(dst, src_view);
 | 
					            return blit_image_helper.ConvertR32ToD32(dst, src_view, up_scale, down_shift);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
    default:
 | 
					    default:
 | 
				
			||||||
 | 
				
			|||||||
@ -61,7 +61,7 @@ public:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    void CopyImage(Image& dst, Image& src, std::span<const VideoCommon::ImageCopy> copies);
 | 
					    void CopyImage(Image& dst, Image& src, std::span<const VideoCommon::ImageCopy> copies);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void ConvertImage(Framebuffer* dst, ImageView& dst_view, ImageView& src_view);
 | 
					    void ConvertImage(Framebuffer* dst, ImageView& dst_view, ImageView& src_view, bool rescaled);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    bool CanAccelerateImageUpload(Image&) const noexcept {
 | 
					    bool CanAccelerateImageUpload(Image&) const noexcept {
 | 
				
			||||||
        return false;
 | 
					        return false;
 | 
				
			||||||
 | 
				
			|||||||
@ -1774,7 +1774,7 @@ void TextureCache<P>::CopyImage(ImageId dst_id, ImageId src_id, std::vector<Imag
 | 
				
			|||||||
        };
 | 
					        };
 | 
				
			||||||
        UNIMPLEMENTED_IF(copy.extent != expected_size);
 | 
					        UNIMPLEMENTED_IF(copy.extent != expected_size);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        runtime.ConvertImage(dst_framebuffer, dst_view, src_view);
 | 
					        runtime.ConvertImage(dst_framebuffer, dst_view, src_view, is_rescaled);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user