summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Fernando Sahmkow2021-11-19 23:22:44 +0100
committerGravatar Fernando Sahmkow2021-11-19 23:22:44 +0100
commit1d5e6a51d7f66cf089d541a009c84c373fd5c6ab (patch)
tree246d901c6f831a7e6050a26043385b907660d343 /src
parentTextureCache: Further fixes on resolve algorithm. (diff)
downloadyuzu-1d5e6a51d7f66cf089d541a009c84c373fd5c6ab.tar.gz
yuzu-1d5e6a51d7f66cf089d541a009c84c373fd5c6ab.tar.xz
yuzu-1d5e6a51d7f66cf089d541a009c84c373fd5c6ab.zip
TextureCache: Add B10G11R11 to D24S8 converter.
Diffstat (limited to 'src')
-rw-r--r--src/video_core/host_shaders/CMakeLists.txt1
-rw-r--r--src/video_core/host_shaders/convert_b10g11r11_to_d24s8.frag19
-rw-r--r--src/video_core/renderer_vulkan/blit_image.cpp62
-rw-r--r--src/video_core/renderer_vulkan/blit_image.h12
-rw-r--r--src/video_core/renderer_vulkan/vk_texture_cache.cpp3
5 files changed, 84 insertions, 13 deletions
diff --git a/src/video_core/host_shaders/CMakeLists.txt b/src/video_core/host_shaders/CMakeLists.txt
index 87042195a..a2e046f12 100644
--- a/src/video_core/host_shaders/CMakeLists.txt
+++ b/src/video_core/host_shaders/CMakeLists.txt
@@ -11,6 +11,7 @@ set(SHADER_FILES
11 block_linear_unswizzle_2d.comp 11 block_linear_unswizzle_2d.comp
12 block_linear_unswizzle_3d.comp 12 block_linear_unswizzle_3d.comp
13 convert_abgr8_to_d24s8.frag 13 convert_abgr8_to_d24s8.frag
14 convert_b10g11r11_to_d24s8.frag
14 convert_d24s8_to_abgr8.frag 15 convert_d24s8_to_abgr8.frag
15 convert_d24s8_to_b10g11r11.frag 16 convert_d24s8_to_b10g11r11.frag
16 convert_d24s8_to_r16g16.frag 17 convert_d24s8_to_r16g16.frag
diff --git a/src/video_core/host_shaders/convert_b10g11r11_to_d24s8.frag b/src/video_core/host_shaders/convert_b10g11r11_to_d24s8.frag
new file mode 100644
index 000000000..b7358c15c
--- /dev/null
+++ b/src/video_core/host_shaders/convert_b10g11r11_to_d24s8.frag
@@ -0,0 +1,19 @@
1// Copyright 2021 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#version 450
6// #extension GL_ARB_shader_stencil_export : require
7
8layout(binding = 0) uniform sampler2D color_texture;
9
10void main() {
11 ivec2 coord = ivec2(gl_FragCoord.xy);
12 vec4 color = texelFetch(color_texture, coord, 0).rgba;
13 uint depth_stencil_unorm = (uint(color.b * (exp2(10) - 1.0f)) << 22)
14 | (uint(color.g * (exp2(11) - 1.0f)) << 11)
15 | (uint(color.r * (exp2(11) - 1.0f)));
16
17 gl_FragDepth = float(depth_stencil_unorm >> 8) / (exp2(24.0) - 1.0f);
18 // gl_FragStencilRefARB = int(depth_stencil_unorm & 0x00FF);
19}
diff --git a/src/video_core/renderer_vulkan/blit_image.cpp b/src/video_core/renderer_vulkan/blit_image.cpp
index 12b28aadd..e70459de5 100644
--- a/src/video_core/renderer_vulkan/blit_image.cpp
+++ b/src/video_core/renderer_vulkan/blit_image.cpp
@@ -5,6 +5,7 @@
5#include <algorithm> 5#include <algorithm>
6 6
7#include "video_core/host_shaders/convert_abgr8_to_d24s8_frag_spv.h" 7#include "video_core/host_shaders/convert_abgr8_to_d24s8_frag_spv.h"
8#include "video_core/host_shaders/convert_b10g11r11_to_d24s8_frag_spv.h"
8#include "video_core/host_shaders/convert_d24s8_to_abgr8_frag_spv.h" 9#include "video_core/host_shaders/convert_d24s8_to_abgr8_frag_spv.h"
9#include "video_core/host_shaders/convert_d24s8_to_b10g11r11_frag_spv.h" 10#include "video_core/host_shaders/convert_d24s8_to_b10g11r11_frag_spv.h"
10#include "video_core/host_shaders/convert_d24s8_to_r16g16_frag_spv.h" 11#include "video_core/host_shaders/convert_d24s8_to_r16g16_frag_spv.h"
@@ -359,6 +360,7 @@ BlitImageHelper::BlitImageHelper(const Device& device_, VKScheduler& scheduler_,
359 convert_depth_to_float_frag(BuildShader(device, CONVERT_DEPTH_TO_FLOAT_FRAG_SPV)), 360 convert_depth_to_float_frag(BuildShader(device, CONVERT_DEPTH_TO_FLOAT_FRAG_SPV)),
360 convert_float_to_depth_frag(BuildShader(device, CONVERT_FLOAT_TO_DEPTH_FRAG_SPV)), 361 convert_float_to_depth_frag(BuildShader(device, CONVERT_FLOAT_TO_DEPTH_FRAG_SPV)),
361 convert_abgr8_to_d24s8_frag(BuildShader(device, CONVERT_ABGR8_TO_D24S8_FRAG_SPV)), 362 convert_abgr8_to_d24s8_frag(BuildShader(device, CONVERT_ABGR8_TO_D24S8_FRAG_SPV)),
363 convert_b10g11r11_to_d24s8_frag(BuildShader(device, CONVERT_B10G11R11_TO_D24S8_FRAG_SPV)),
362 convert_d24s8_to_abgr8_frag(BuildShader(device, CONVERT_D24S8_TO_ABGR8_FRAG_SPV)), 364 convert_d24s8_to_abgr8_frag(BuildShader(device, CONVERT_D24S8_TO_ABGR8_FRAG_SPV)),
363 convert_d24s8_to_b10g11r11_frag(BuildShader(device, CONVERT_D24S8_TO_B10G11R11_FRAG_SPV)), 365 convert_d24s8_to_b10g11r11_frag(BuildShader(device, CONVERT_D24S8_TO_B10G11R11_FRAG_SPV)),
364 convert_d24s8_to_r16g16_frag(BuildShader(device, CONVERT_D24S8_TO_R16G16_FRAG_SPV)), 366 convert_d24s8_to_r16g16_frag(BuildShader(device, CONVERT_D24S8_TO_R16G16_FRAG_SPV)),
@@ -459,16 +461,25 @@ void BlitImageHelper::ConvertR16ToD16(const Framebuffer* dst_framebuffer,
459void BlitImageHelper::ConvertABGR8ToD24S8(const Framebuffer* dst_framebuffer, 461void BlitImageHelper::ConvertABGR8ToD24S8(const Framebuffer* dst_framebuffer,
460 const ImageView& src_image_view, u32 up_scale, 462 const ImageView& src_image_view, u32 up_scale,
461 u32 down_shift) { 463 u32 down_shift) {
462 ConvertPipelineEx(convert_abgr8_to_d24s8_pipeline, dst_framebuffer->RenderPass(), 464 ConvertPipelineDepthTargetEx(convert_abgr8_to_d24s8_pipeline, dst_framebuffer->RenderPass(),
463 convert_abgr8_to_d24s8_frag, true); 465 convert_abgr8_to_d24s8_frag, true);
464 Convert(*convert_abgr8_to_d24s8_pipeline, dst_framebuffer, src_image_view, up_scale, 466 Convert(*convert_abgr8_to_d24s8_pipeline, dst_framebuffer, src_image_view, up_scale,
465 down_shift); 467 down_shift);
466} 468}
467 469
470void BlitImageHelper::ConvertB10G11R11ToD24S8(const Framebuffer* dst_framebuffer,
471 const ImageView& src_image_view, u32 up_scale,
472 u32 down_shift) {
473 ConvertPipelineDepthTargetEx(convert_b10g11r11_to_d24s8_pipeline, dst_framebuffer->RenderPass(),
474 convert_b10g11r11_to_d24s8_frag, true);
475 Convert(*convert_b10g11r11_to_d24s8_pipeline, dst_framebuffer, src_image_view, up_scale,
476 down_shift);
477}
478
468void BlitImageHelper::ConvertD24S8ToABGR8(const Framebuffer* dst_framebuffer, 479void BlitImageHelper::ConvertD24S8ToABGR8(const Framebuffer* dst_framebuffer,
469 ImageView& src_image_view, u32 up_scale, u32 down_shift) { 480 ImageView& src_image_view, u32 up_scale, u32 down_shift) {
470 ConvertPipelineEx(convert_d24s8_to_abgr8_pipeline, dst_framebuffer->RenderPass(), 481 ConvertPipelineColorTargetEx(convert_d24s8_to_abgr8_pipeline, dst_framebuffer->RenderPass(),
471 convert_d24s8_to_abgr8_frag, false); 482 convert_d24s8_to_abgr8_frag, false);
472 ConvertDepthStencil(*convert_d24s8_to_abgr8_pipeline, dst_framebuffer, src_image_view, up_scale, 483 ConvertDepthStencil(*convert_d24s8_to_abgr8_pipeline, dst_framebuffer, src_image_view, up_scale,
473 down_shift); 484 down_shift);
474} 485}
@@ -476,8 +487,8 @@ void BlitImageHelper::ConvertD24S8ToABGR8(const Framebuffer* dst_framebuffer,
476void BlitImageHelper::ConvertD24S8ToB10G11R11(const Framebuffer* dst_framebuffer, 487void BlitImageHelper::ConvertD24S8ToB10G11R11(const Framebuffer* dst_framebuffer,
477 ImageView& src_image_view, u32 up_scale, 488 ImageView& src_image_view, u32 up_scale,
478 u32 down_shift) { 489 u32 down_shift) {
479 ConvertPipelineEx(convert_d24s8_to_b10g11r11_pipeline, dst_framebuffer->RenderPass(), 490 ConvertPipelineColorTargetEx(convert_d24s8_to_b10g11r11_pipeline, dst_framebuffer->RenderPass(),
480 convert_d24s8_to_b10g11r11_frag, false); 491 convert_d24s8_to_b10g11r11_frag, false);
481 ConvertDepthStencil(*convert_d24s8_to_b10g11r11_pipeline, dst_framebuffer, src_image_view, 492 ConvertDepthStencil(*convert_d24s8_to_b10g11r11_pipeline, dst_framebuffer, src_image_view,
482 up_scale, down_shift); 493 up_scale, down_shift);
483} 494}
@@ -485,8 +496,8 @@ void BlitImageHelper::ConvertD24S8ToB10G11R11(const Framebuffer* dst_framebuffer
485void BlitImageHelper::ConvertD24S8ToR16G16(const Framebuffer* dst_framebuffer, 496void BlitImageHelper::ConvertD24S8ToR16G16(const Framebuffer* dst_framebuffer,
486 ImageView& src_image_view, u32 up_scale, 497 ImageView& src_image_view, u32 up_scale,
487 u32 down_shift) { 498 u32 down_shift) {
488 ConvertPipelineEx(convert_d24s8_to_r16g16_pipeline, dst_framebuffer->RenderPass(), 499 ConvertPipelineColorTargetEx(convert_d24s8_to_r16g16_pipeline, dst_framebuffer->RenderPass(),
489 convert_d24s8_to_r16g16_frag, false); 500 convert_d24s8_to_r16g16_frag, false);
490 ConvertDepthStencil(*convert_d24s8_to_r16g16_pipeline, dst_framebuffer, src_image_view, 501 ConvertDepthStencil(*convert_d24s8_to_r16g16_pipeline, dst_framebuffer, src_image_view,
491 up_scale, down_shift); 502 up_scale, down_shift);
492} 503}
@@ -540,7 +551,7 @@ void BlitImageHelper::Convert(VkPipeline pipeline, const Framebuffer* dst_frameb
540 551
541void BlitImageHelper::ConvertDepthStencil(VkPipeline pipeline, const Framebuffer* dst_framebuffer, 552void BlitImageHelper::ConvertDepthStencil(VkPipeline pipeline, const Framebuffer* dst_framebuffer,
542 ImageView& src_image_view, u32 up_scale, u32 down_shift) { 553 ImageView& src_image_view, u32 up_scale, u32 down_shift) {
543 const VkPipelineLayout layout = *one_texture_pipeline_layout; 554 const VkPipelineLayout layout = *two_textures_pipeline_layout;
544 const VkImageView src_depth_view = src_image_view.DepthView(); 555 const VkImageView src_depth_view = src_image_view.DepthView();
545 const VkImageView src_stencil_view = src_image_view.StencilView(); 556 const VkImageView src_stencil_view = src_image_view.StencilView();
546 const VkSampler sampler = *nearest_sampler; 557 const VkSampler sampler = *nearest_sampler;
@@ -727,8 +738,37 @@ void BlitImageHelper::ConvertColorToDepthPipeline(vk::Pipeline& pipeline, VkRend
727 }); 738 });
728} 739}
729 740
730void BlitImageHelper::ConvertPipelineEx(vk::Pipeline& pipeline, VkRenderPass renderpass, 741void BlitImageHelper::ConvertPipelineColorTargetEx(vk::Pipeline& pipeline, VkRenderPass renderpass,
731 vk::ShaderModule& module, bool single_texture) { 742 vk::ShaderModule& module, bool single_texture) {
743 if (pipeline) {
744 return;
745 }
746 const std::array stages = MakeStages(*full_screen_vert, *module);
747 pipeline = device.GetLogical().CreateGraphicsPipeline({
748 .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
749 .pNext = nullptr,
750 .flags = 0,
751 .stageCount = static_cast<u32>(stages.size()),
752 .pStages = stages.data(),
753 .pVertexInputState = &PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
754 .pInputAssemblyState = &PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
755 .pTessellationState = nullptr,
756 .pViewportState = &PIPELINE_VIEWPORT_STATE_CREATE_INFO,
757 .pRasterizationState = &PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
758 .pMultisampleState = &PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
759 .pDepthStencilState = nullptr,
760 .pColorBlendState = &PIPELINE_COLOR_BLEND_STATE_GENERIC_CREATE_INFO,
761 .pDynamicState = &PIPELINE_DYNAMIC_STATE_CREATE_INFO,
762 .layout = single_texture ? *one_texture_pipeline_layout : *two_textures_pipeline_layout,
763 .renderPass = renderpass,
764 .subpass = 0,
765 .basePipelineHandle = VK_NULL_HANDLE,
766 .basePipelineIndex = 0,
767 });
768}
769
770void BlitImageHelper::ConvertPipelineDepthTargetEx(vk::Pipeline& pipeline, VkRenderPass renderpass,
771 vk::ShaderModule& module, bool single_texture) {
732 if (pipeline) { 772 if (pipeline) {
733 return; 773 return;
734 } 774 }
diff --git a/src/video_core/renderer_vulkan/blit_image.h b/src/video_core/renderer_vulkan/blit_image.h
index 10d24c4b7..607964b5e 100644
--- a/src/video_core/renderer_vulkan/blit_image.h
+++ b/src/video_core/renderer_vulkan/blit_image.h
@@ -59,6 +59,9 @@ public:
59 void ConvertABGR8ToD24S8(const Framebuffer* dst_framebuffer, const ImageView& src_image_view, 59 void ConvertABGR8ToD24S8(const Framebuffer* dst_framebuffer, const ImageView& src_image_view,
60 u32 up_scale, u32 down_shift); 60 u32 up_scale, u32 down_shift);
61 61
62 void ConvertB10G11R11ToD24S8(const Framebuffer* dst_framebuffer,
63 const ImageView& src_image_view, u32 up_scale, u32 down_shift);
64
62 void ConvertD24S8ToABGR8(const Framebuffer* dst_framebuffer, ImageView& src_image_view, 65 void ConvertD24S8ToABGR8(const Framebuffer* dst_framebuffer, ImageView& src_image_view,
63 u32 up_scale, u32 down_shift); 66 u32 up_scale, u32 down_shift);
64 67
@@ -83,8 +86,11 @@ private:
83 86
84 void ConvertColorToDepthPipeline(vk::Pipeline& pipeline, VkRenderPass renderpass); 87 void ConvertColorToDepthPipeline(vk::Pipeline& pipeline, VkRenderPass renderpass);
85 88
86 void ConvertPipelineEx(vk::Pipeline& pipeline, VkRenderPass renderpass, 89 void ConvertPipelineColorTargetEx(vk::Pipeline& pipeline, VkRenderPass renderpass,
87 vk::ShaderModule& module, bool single_texture); 90 vk::ShaderModule& module, bool single_texture);
91
92 void ConvertPipelineDepthTargetEx(vk::Pipeline& pipeline, VkRenderPass renderpass,
93 vk::ShaderModule& module, bool single_texture);
88 94
89 const Device& device; 95 const Device& device;
90 VKScheduler& scheduler; 96 VKScheduler& scheduler;
@@ -102,6 +108,7 @@ private:
102 vk::ShaderModule convert_depth_to_float_frag; 108 vk::ShaderModule convert_depth_to_float_frag;
103 vk::ShaderModule convert_float_to_depth_frag; 109 vk::ShaderModule convert_float_to_depth_frag;
104 vk::ShaderModule convert_abgr8_to_d24s8_frag; 110 vk::ShaderModule convert_abgr8_to_d24s8_frag;
111 vk::ShaderModule convert_b10g11r11_to_d24s8_frag;
105 vk::ShaderModule convert_d24s8_to_abgr8_frag; 112 vk::ShaderModule convert_d24s8_to_abgr8_frag;
106 vk::ShaderModule convert_d24s8_to_b10g11r11_frag; 113 vk::ShaderModule convert_d24s8_to_b10g11r11_frag;
107 vk::ShaderModule convert_d24s8_to_r16g16_frag; 114 vk::ShaderModule convert_d24s8_to_r16g16_frag;
@@ -117,6 +124,7 @@ private:
117 vk::Pipeline convert_d16_to_r16_pipeline; 124 vk::Pipeline convert_d16_to_r16_pipeline;
118 vk::Pipeline convert_r16_to_d16_pipeline; 125 vk::Pipeline convert_r16_to_d16_pipeline;
119 vk::Pipeline convert_abgr8_to_d24s8_pipeline; 126 vk::Pipeline convert_abgr8_to_d24s8_pipeline;
127 vk::Pipeline convert_b10g11r11_to_d24s8_pipeline;
120 vk::Pipeline convert_d24s8_to_abgr8_pipeline; 128 vk::Pipeline convert_d24s8_to_abgr8_pipeline;
121 vk::Pipeline convert_d24s8_to_b10g11r11_pipeline; 129 vk::Pipeline convert_d24s8_to_b10g11r11_pipeline;
122 vk::Pipeline convert_d24s8_to_r16g16_pipeline; 130 vk::Pipeline convert_d24s8_to_r16g16_pipeline;
diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.cpp b/src/video_core/renderer_vulkan/vk_texture_cache.cpp
index fd6064271..28a659c0e 100644
--- a/src/video_core/renderer_vulkan/vk_texture_cache.cpp
+++ b/src/video_core/renderer_vulkan/vk_texture_cache.cpp
@@ -912,6 +912,9 @@ void TextureCacheRuntime::ConvertImage(Framebuffer* dst, ImageView& dst_view, Im
912 src_view.format == PixelFormat::B8G8R8A8_UNORM) { 912 src_view.format == PixelFormat::B8G8R8A8_UNORM) {
913 return blit_image_helper.ConvertABGR8ToD24S8(dst, src_view, up_scale, down_shift); 913 return blit_image_helper.ConvertABGR8ToD24S8(dst, src_view, up_scale, down_shift);
914 } 914 }
915 if (src_view.format == PixelFormat::B10G11R11_FLOAT) {
916 return blit_image_helper.ConvertB10G11R11ToD24S8(dst, src_view, up_scale, down_shift);
917 }
915 break; 918 break;
916 case PixelFormat::D32_FLOAT: 919 case PixelFormat::D32_FLOAT:
917 if (src_view.format == PixelFormat::R32_FLOAT) { 920 if (src_view.format == PixelFormat::R32_FLOAT) {