diff options
| author | 2024-01-22 12:40:50 -0500 | |
|---|---|---|
| committer | 2024-02-09 09:20:53 -0500 | |
| commit | 962c82540c304f909957776908aabcd261f2a7ba (patch) | |
| tree | 707ab34565e8309b5ede21acebf36975da7718e7 /src/video_core | |
| parent | nvservices: unmap only on last container free (diff) | |
| download | yuzu-962c82540c304f909957776908aabcd261f2a7ba.tar.gz yuzu-962c82540c304f909957776908aabcd261f2a7ba.tar.xz yuzu-962c82540c304f909957776908aabcd261f2a7ba.zip | |
nvnflinger/gpu: implement blending
Diffstat (limited to 'src/video_core')
21 files changed, 166 insertions, 75 deletions
diff --git a/src/video_core/framebuffer_config.h b/src/video_core/framebuffer_config.h index 6a18b76fb..8b2a49de5 100644 --- a/src/video_core/framebuffer_config.h +++ b/src/video_core/framebuffer_config.h | |||
| @@ -11,6 +11,12 @@ | |||
| 11 | 11 | ||
| 12 | namespace Tegra { | 12 | namespace Tegra { |
| 13 | 13 | ||
| 14 | enum class BlendMode { | ||
| 15 | Opaque, | ||
| 16 | Premultiplied, | ||
| 17 | Coverage, | ||
| 18 | }; | ||
| 19 | |||
| 14 | /** | 20 | /** |
| 15 | * Struct describing framebuffer configuration | 21 | * Struct describing framebuffer configuration |
| 16 | */ | 22 | */ |
| @@ -23,6 +29,7 @@ struct FramebufferConfig { | |||
| 23 | Service::android::PixelFormat pixel_format{}; | 29 | Service::android::PixelFormat pixel_format{}; |
| 24 | Service::android::BufferTransformFlags transform_flags{}; | 30 | Service::android::BufferTransformFlags transform_flags{}; |
| 25 | Common::Rectangle<int> crop_rect{}; | 31 | Common::Rectangle<int> crop_rect{}; |
| 32 | BlendMode blending{}; | ||
| 26 | }; | 33 | }; |
| 27 | 34 | ||
| 28 | Common::Rectangle<f32> NormalizeCrop(const FramebufferConfig& framebuffer, u32 texture_width, | 35 | Common::Rectangle<f32> NormalizeCrop(const FramebufferConfig& framebuffer, u32 texture_width, |
diff --git a/src/video_core/host_shaders/fidelityfx_fsr.frag b/src/video_core/host_shaders/fidelityfx_fsr.frag index a266e1c4e..54eedb450 100644 --- a/src/video_core/host_shaders/fidelityfx_fsr.frag +++ b/src/video_core/host_shaders/fidelityfx_fsr.frag | |||
| @@ -37,6 +37,7 @@ layout(set=0,binding=0) uniform sampler2D InputTexture; | |||
| 37 | 37 | ||
| 38 | #define A_GPU 1 | 38 | #define A_GPU 1 |
| 39 | #define A_GLSL 1 | 39 | #define A_GLSL 1 |
| 40 | #define FSR_RCAS_PASSTHROUGH_ALPHA 1 | ||
| 40 | 41 | ||
| 41 | #ifndef YUZU_USE_FP16 | 42 | #ifndef YUZU_USE_FP16 |
| 42 | #include "ffx_a.h" | 43 | #include "ffx_a.h" |
| @@ -71,9 +72,7 @@ layout(set=0,binding=0) uniform sampler2D InputTexture; | |||
| 71 | 72 | ||
| 72 | #include "ffx_fsr1.h" | 73 | #include "ffx_fsr1.h" |
| 73 | 74 | ||
| 74 | #if USE_RCAS | 75 | layout (location = 0) in vec2 frag_texcoord; |
| 75 | layout(location = 0) in vec2 frag_texcoord; | ||
| 76 | #endif | ||
| 77 | layout (location = 0) out vec4 frag_color; | 76 | layout (location = 0) out vec4 frag_color; |
| 78 | 77 | ||
| 79 | void CurrFilter(AU2 pos) { | 78 | void CurrFilter(AU2 pos) { |
| @@ -81,22 +80,22 @@ void CurrFilter(AU2 pos) { | |||
| 81 | #ifndef YUZU_USE_FP16 | 80 | #ifndef YUZU_USE_FP16 |
| 82 | AF3 c; | 81 | AF3 c; |
| 83 | FsrEasuF(c, pos, Const0, Const1, Const2, Const3); | 82 | FsrEasuF(c, pos, Const0, Const1, Const2, Const3); |
| 84 | frag_color = AF4(c, 1.0); | 83 | frag_color = AF4(c, texture(InputTexture, frag_texcoord).a); |
| 85 | #else | 84 | #else |
| 86 | AH3 c; | 85 | AH3 c; |
| 87 | FsrEasuH(c, pos, Const0, Const1, Const2, Const3); | 86 | FsrEasuH(c, pos, Const0, Const1, Const2, Const3); |
| 88 | frag_color = AH4(c, 1.0); | 87 | frag_color = AH4(c, texture(InputTexture, frag_texcoord).a); |
| 89 | #endif | 88 | #endif |
| 90 | #endif | 89 | #endif |
| 91 | #if USE_RCAS | 90 | #if USE_RCAS |
| 92 | #ifndef YUZU_USE_FP16 | 91 | #ifndef YUZU_USE_FP16 |
| 93 | AF3 c; | 92 | AF4 c; |
| 94 | FsrRcasF(c.r, c.g, c.b, pos, Const0); | 93 | FsrRcasF(c.r, c.g, c.b, c.a, pos, Const0); |
| 95 | frag_color = AF4(c, 1.0); | 94 | frag_color = c; |
| 96 | #else | 95 | #else |
| 97 | AH3 c; | 96 | AH4 c; |
| 98 | FsrRcasH(c.r, c.g, c.b, pos, Const0); | 97 | FsrRcasH(c.r, c.g, c.b, c.a, pos, Const0); |
| 99 | frag_color = AH4(c, 1.0); | 98 | frag_color = c; |
| 100 | #endif | 99 | #endif |
| 101 | #endif | 100 | #endif |
| 102 | } | 101 | } |
diff --git a/src/video_core/host_shaders/fxaa.frag b/src/video_core/host_shaders/fxaa.frag index 9bffc20d5..192a602c1 100644 --- a/src/video_core/host_shaders/fxaa.frag +++ b/src/video_core/host_shaders/fxaa.frag | |||
| @@ -71,5 +71,5 @@ vec3 FxaaPixelShader(vec4 posPos, sampler2D tex) { | |||
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | void main() { | 73 | void main() { |
| 74 | frag_color = vec4(FxaaPixelShader(posPos, input_texture), 1.0); | 74 | frag_color = vec4(FxaaPixelShader(posPos, input_texture), texture(input_texture, posPos.xy).a); |
| 75 | } | 75 | } |
diff --git a/src/video_core/host_shaders/opengl_fidelityfx_fsr.frag b/src/video_core/host_shaders/opengl_fidelityfx_fsr.frag index 16d22f58e..fc47d3810 100644 --- a/src/video_core/host_shaders/opengl_fidelityfx_fsr.frag +++ b/src/video_core/host_shaders/opengl_fidelityfx_fsr.frag | |||
| @@ -31,6 +31,7 @@ layout (location = 0) uniform uvec4 constants[4]; | |||
| 31 | 31 | ||
| 32 | #define A_GPU 1 | 32 | #define A_GPU 1 |
| 33 | #define A_GLSL 1 | 33 | #define A_GLSL 1 |
| 34 | #define FSR_RCAS_PASSTHROUGH_ALPHA 1 | ||
| 34 | 35 | ||
| 35 | #ifdef YUZU_USE_FP16 | 36 | #ifdef YUZU_USE_FP16 |
| 36 | #define A_HALF | 37 | #define A_HALF |
| @@ -67,9 +68,7 @@ layout (location = 0) uniform uvec4 constants[4]; | |||
| 67 | 68 | ||
| 68 | #include "ffx_fsr1.h" | 69 | #include "ffx_fsr1.h" |
| 69 | 70 | ||
| 70 | #if USE_RCAS | 71 | layout (location = 0) in vec2 frag_texcoord; |
| 71 | layout(location = 0) in vec2 frag_texcoord; | ||
| 72 | #endif | ||
| 73 | layout (location = 0) out vec4 frag_color; | 72 | layout (location = 0) out vec4 frag_color; |
| 74 | 73 | ||
| 75 | void CurrFilter(AU2 pos) | 74 | void CurrFilter(AU2 pos) |
| @@ -78,22 +77,22 @@ void CurrFilter(AU2 pos) | |||
| 78 | #ifndef YUZU_USE_FP16 | 77 | #ifndef YUZU_USE_FP16 |
| 79 | AF3 c; | 78 | AF3 c; |
| 80 | FsrEasuF(c, pos, constants[0], constants[1], constants[2], constants[3]); | 79 | FsrEasuF(c, pos, constants[0], constants[1], constants[2], constants[3]); |
| 81 | frag_color = AF4(c, 1.0); | 80 | frag_color = AF4(c, texture(InputTexture, frag_texcoord).a); |
| 82 | #else | 81 | #else |
| 83 | AH3 c; | 82 | AH3 c; |
| 84 | FsrEasuH(c, pos, constants[0], constants[1], constants[2], constants[3]); | 83 | FsrEasuH(c, pos, constants[0], constants[1], constants[2], constants[3]); |
| 85 | frag_color = AH4(c, 1.0); | 84 | frag_color = AH4(c, texture(InputTexture, frag_texcoord).a); |
| 86 | #endif | 85 | #endif |
| 87 | #endif | 86 | #endif |
| 88 | #if USE_RCAS | 87 | #if USE_RCAS |
| 89 | #ifndef YUZU_USE_FP16 | 88 | #ifndef YUZU_USE_FP16 |
| 90 | AF3 c; | 89 | AF4 c; |
| 91 | FsrRcasF(c.r, c.g, c.b, pos, constants[0]); | 90 | FsrRcasF(c.r, c.g, c.b, c.a, pos, constants[0]); |
| 92 | frag_color = AF4(c, 1.0); | 91 | frag_color = c; |
| 93 | #else | 92 | #else |
| 94 | AH3 c; | 93 | AH3 c; |
| 95 | FsrRcasH(c.r, c.g, c.b, pos, constants[0]); | 94 | FsrRcasH(c.r, c.g, c.b, c.a, pos, constants[0]); |
| 96 | frag_color = AH4(c, 1.0); | 95 | frag_color = c; |
| 97 | #endif | 96 | #endif |
| 98 | #endif | 97 | #endif |
| 99 | } | 98 | } |
diff --git a/src/video_core/host_shaders/opengl_present.frag b/src/video_core/host_shaders/opengl_present.frag index 5fd7ad297..096b4e4db 100644 --- a/src/video_core/host_shaders/opengl_present.frag +++ b/src/video_core/host_shaders/opengl_present.frag | |||
| @@ -9,5 +9,5 @@ layout (location = 0) out vec4 color; | |||
| 9 | layout (binding = 0) uniform sampler2D color_texture; | 9 | layout (binding = 0) uniform sampler2D color_texture; |
| 10 | 10 | ||
| 11 | void main() { | 11 | void main() { |
| 12 | color = vec4(texture(color_texture, frag_tex_coord).rgb, 1.0f); | 12 | color = vec4(texture(color_texture, frag_tex_coord)); |
| 13 | } | 13 | } |
diff --git a/src/video_core/host_shaders/present_bicubic.frag b/src/video_core/host_shaders/present_bicubic.frag index c814629cf..a9d9d40a3 100644 --- a/src/video_core/host_shaders/present_bicubic.frag +++ b/src/video_core/host_shaders/present_bicubic.frag | |||
| @@ -52,5 +52,5 @@ vec4 textureBicubic( sampler2D textureSampler, vec2 texCoords ) { | |||
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | void main() { | 54 | void main() { |
| 55 | color = vec4(textureBicubic(color_texture, frag_tex_coord).rgb, 1.0f); | 55 | color = textureBicubic(color_texture, frag_tex_coord); |
| 56 | } | 56 | } |
diff --git a/src/video_core/host_shaders/present_gaussian.frag b/src/video_core/host_shaders/present_gaussian.frag index ad9bb76a4..78edeb9b4 100644 --- a/src/video_core/host_shaders/present_gaussian.frag +++ b/src/video_core/host_shaders/present_gaussian.frag | |||
| @@ -46,14 +46,14 @@ vec4 blurDiagonal(sampler2D textureSampler, vec2 coord, vec2 norm) { | |||
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | void main() { | 48 | void main() { |
| 49 | vec3 base = texture(color_texture, vec2(frag_tex_coord)).rgb * weight[0]; | 49 | vec4 base = texture(color_texture, vec2(frag_tex_coord)) * weight[0]; |
| 50 | vec2 tex_offset = 1.0f / textureSize(color_texture, 0); | 50 | vec2 tex_offset = 1.0f / textureSize(color_texture, 0); |
| 51 | 51 | ||
| 52 | // TODO(Blinkhawk): This code can be optimized through shader group instructions. | 52 | // TODO(Blinkhawk): This code can be optimized through shader group instructions. |
| 53 | vec3 horizontal = blurHorizontal(color_texture, frag_tex_coord, tex_offset).rgb; | 53 | vec4 horizontal = blurHorizontal(color_texture, frag_tex_coord, tex_offset); |
| 54 | vec3 vertical = blurVertical(color_texture, frag_tex_coord, tex_offset).rgb; | 54 | vec4 vertical = blurVertical(color_texture, frag_tex_coord, tex_offset); |
| 55 | vec3 diagonalA = blurDiagonal(color_texture, frag_tex_coord, tex_offset).rgb; | 55 | vec4 diagonalA = blurDiagonal(color_texture, frag_tex_coord, tex_offset); |
| 56 | vec3 diagonalB = blurDiagonal(color_texture, frag_tex_coord, tex_offset * vec2(1.0, -1.0)).rgb; | 56 | vec4 diagonalB = blurDiagonal(color_texture, frag_tex_coord, tex_offset * vec2(1.0, -1.0)); |
| 57 | vec3 combination = mix(mix(horizontal, vertical, 0.5f), mix(diagonalA, diagonalB, 0.5f), 0.5f); | 57 | vec4 combination = mix(mix(horizontal, vertical, 0.5f), mix(diagonalA, diagonalB, 0.5f), 0.5f); |
| 58 | color = vec4(combination + base, 1.0f); | 58 | color = combination + base; |
| 59 | } | 59 | } |
diff --git a/src/video_core/host_shaders/vulkan_fidelityfx_fsr_easu_fp16.frag b/src/video_core/host_shaders/vulkan_fidelityfx_fsr_easu_fp16.frag index d369bef06..05d033310 100644 --- a/src/video_core/host_shaders/vulkan_fidelityfx_fsr_easu_fp16.frag +++ b/src/video_core/host_shaders/vulkan_fidelityfx_fsr_easu_fp16.frag | |||
| @@ -6,5 +6,6 @@ | |||
| 6 | 6 | ||
| 7 | #define YUZU_USE_FP16 | 7 | #define YUZU_USE_FP16 |
| 8 | #define USE_EASU 1 | 8 | #define USE_EASU 1 |
| 9 | #define VERSION 1 | ||
| 9 | 10 | ||
| 10 | #include "fidelityfx_fsr.frag" | 11 | #include "fidelityfx_fsr.frag" |
diff --git a/src/video_core/host_shaders/vulkan_fidelityfx_fsr_easu_fp32.frag b/src/video_core/host_shaders/vulkan_fidelityfx_fsr_easu_fp32.frag index 6f25ef00f..7ae11dd66 100644 --- a/src/video_core/host_shaders/vulkan_fidelityfx_fsr_easu_fp32.frag +++ b/src/video_core/host_shaders/vulkan_fidelityfx_fsr_easu_fp32.frag | |||
| @@ -5,5 +5,6 @@ | |||
| 5 | #extension GL_GOOGLE_include_directive : enable | 5 | #extension GL_GOOGLE_include_directive : enable |
| 6 | 6 | ||
| 7 | #define USE_EASU 1 | 7 | #define USE_EASU 1 |
| 8 | #define VERSION 1 | ||
| 8 | 9 | ||
| 9 | #include "fidelityfx_fsr.frag" | 10 | #include "fidelityfx_fsr.frag" |
diff --git a/src/video_core/host_shaders/vulkan_fidelityfx_fsr_rcas_fp16.frag b/src/video_core/host_shaders/vulkan_fidelityfx_fsr_rcas_fp16.frag index 0c953a900..c017214a5 100644 --- a/src/video_core/host_shaders/vulkan_fidelityfx_fsr_rcas_fp16.frag +++ b/src/video_core/host_shaders/vulkan_fidelityfx_fsr_rcas_fp16.frag | |||
| @@ -6,5 +6,6 @@ | |||
| 6 | 6 | ||
| 7 | #define YUZU_USE_FP16 | 7 | #define YUZU_USE_FP16 |
| 8 | #define USE_RCAS 1 | 8 | #define USE_RCAS 1 |
| 9 | #define VERSION 1 | ||
| 9 | 10 | ||
| 10 | #include "fidelityfx_fsr.frag" | 11 | #include "fidelityfx_fsr.frag" |
diff --git a/src/video_core/host_shaders/vulkan_fidelityfx_fsr_rcas_fp32.frag b/src/video_core/host_shaders/vulkan_fidelityfx_fsr_rcas_fp32.frag index 02e9a27c6..976825f4b 100644 --- a/src/video_core/host_shaders/vulkan_fidelityfx_fsr_rcas_fp32.frag +++ b/src/video_core/host_shaders/vulkan_fidelityfx_fsr_rcas_fp32.frag | |||
| @@ -5,5 +5,6 @@ | |||
| 5 | #extension GL_GOOGLE_include_directive : enable | 5 | #extension GL_GOOGLE_include_directive : enable |
| 6 | 6 | ||
| 7 | #define USE_RCAS 1 | 7 | #define USE_RCAS 1 |
| 8 | #define VERSION 1 | ||
| 8 | 9 | ||
| 9 | #include "fidelityfx_fsr.frag" | 10 | #include "fidelityfx_fsr.frag" |
diff --git a/src/video_core/host_shaders/vulkan_present_scaleforce_fp16.frag b/src/video_core/host_shaders/vulkan_present_scaleforce_fp16.frag index 79ea817c2..cea5dac9d 100644 --- a/src/video_core/host_shaders/vulkan_present_scaleforce_fp16.frag +++ b/src/video_core/host_shaders/vulkan_present_scaleforce_fp16.frag | |||
| @@ -5,7 +5,7 @@ | |||
| 5 | 5 | ||
| 6 | #extension GL_GOOGLE_include_directive : enable | 6 | #extension GL_GOOGLE_include_directive : enable |
| 7 | 7 | ||
| 8 | #define VERSION 1 | 8 | #define VERSION 2 |
| 9 | #define YUZU_USE_FP16 | 9 | #define YUZU_USE_FP16 |
| 10 | 10 | ||
| 11 | #include "opengl_present_scaleforce.frag" | 11 | #include "opengl_present_scaleforce.frag" |
diff --git a/src/video_core/host_shaders/vulkan_present_scaleforce_fp32.frag b/src/video_core/host_shaders/vulkan_present_scaleforce_fp32.frag index 9605bb58b..10ddf0401 100644 --- a/src/video_core/host_shaders/vulkan_present_scaleforce_fp32.frag +++ b/src/video_core/host_shaders/vulkan_present_scaleforce_fp32.frag | |||
| @@ -5,6 +5,6 @@ | |||
| 5 | 5 | ||
| 6 | #extension GL_GOOGLE_include_directive : enable | 6 | #extension GL_GOOGLE_include_directive : enable |
| 7 | 7 | ||
| 8 | #define VERSION 1 | 8 | #define VERSION 2 |
| 9 | 9 | ||
| 10 | #include "opengl_present_scaleforce.frag" | 10 | #include "opengl_present_scaleforce.frag" |
diff --git a/src/video_core/renderer_opengl/present/window_adapt_pass.cpp b/src/video_core/renderer_opengl/present/window_adapt_pass.cpp index 4d681606b..0328abd70 100644 --- a/src/video_core/renderer_opengl/present/window_adapt_pass.cpp +++ b/src/video_core/renderer_opengl/present/window_adapt_pass.cpp | |||
| @@ -92,6 +92,21 @@ void WindowAdaptPass::DrawToFramebuffer(ProgramManager& program_manager, std::li | |||
| 92 | glClear(GL_COLOR_BUFFER_BIT); | 92 | glClear(GL_COLOR_BUFFER_BIT); |
| 93 | 93 | ||
| 94 | for (size_t i = 0; i < layer_count; i++) { | 94 | for (size_t i = 0; i < layer_count; i++) { |
| 95 | switch (framebuffers[i].blending) { | ||
| 96 | case Tegra::BlendMode::Opaque: | ||
| 97 | default: | ||
| 98 | glDisablei(GL_BLEND, 0); | ||
| 99 | break; | ||
| 100 | case Tegra::BlendMode::Premultiplied: | ||
| 101 | glEnablei(GL_BLEND, 0); | ||
| 102 | glBlendFuncSeparatei(0, GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO); | ||
| 103 | break; | ||
| 104 | case Tegra::BlendMode::Coverage: | ||
| 105 | glEnablei(GL_BLEND, 0); | ||
| 106 | glBlendFuncSeparatei(0, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO); | ||
| 107 | break; | ||
| 108 | } | ||
| 109 | |||
| 95 | glBindTextureUnit(0, textures[i]); | 110 | glBindTextureUnit(0, textures[i]); |
| 96 | glProgramUniformMatrix3x2fv(vert.handle, ModelViewMatrixLocation, 1, GL_FALSE, | 111 | glProgramUniformMatrix3x2fv(vert.handle, ModelViewMatrixLocation, 1, GL_FALSE, |
| 97 | matrices[i].data()); | 112 | matrices[i].data()); |
diff --git a/src/video_core/renderer_vulkan/present/util.cpp b/src/video_core/renderer_vulkan/present/util.cpp index 6ee16595d..7f27c7c1b 100644 --- a/src/video_core/renderer_vulkan/present/util.cpp +++ b/src/video_core/renderer_vulkan/present/util.cpp | |||
| @@ -362,10 +362,10 @@ vk::PipelineLayout CreateWrappedPipelineLayout(const Device& device, | |||
| 362 | }); | 362 | }); |
| 363 | } | 363 | } |
| 364 | 364 | ||
| 365 | vk::Pipeline CreateWrappedPipeline(const Device& device, vk::RenderPass& renderpass, | 365 | static vk::Pipeline CreateWrappedPipelineImpl( |
| 366 | vk::PipelineLayout& layout, | 366 | const Device& device, vk::RenderPass& renderpass, vk::PipelineLayout& layout, |
| 367 | std::tuple<vk::ShaderModule&, vk::ShaderModule&> shaders, | 367 | std::tuple<vk::ShaderModule&, vk::ShaderModule&> shaders, |
| 368 | bool enable_blending) { | 368 | VkPipelineColorBlendAttachmentState blending) { |
| 369 | const std::array<VkPipelineShaderStageCreateInfo, 2> shader_stages{{ | 369 | const std::array<VkPipelineShaderStageCreateInfo, 2> shader_stages{{ |
| 370 | { | 370 | { |
| 371 | .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, | 371 | .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, |
| @@ -443,30 +443,6 @@ vk::Pipeline CreateWrappedPipeline(const Device& device, vk::RenderPass& renderp | |||
| 443 | .alphaToOneEnable = VK_FALSE, | 443 | .alphaToOneEnable = VK_FALSE, |
| 444 | }; | 444 | }; |
| 445 | 445 | ||
| 446 | constexpr VkPipelineColorBlendAttachmentState color_blend_attachment_disabled{ | ||
| 447 | .blendEnable = VK_FALSE, | ||
| 448 | .srcColorBlendFactor = VK_BLEND_FACTOR_ZERO, | ||
| 449 | .dstColorBlendFactor = VK_BLEND_FACTOR_ZERO, | ||
| 450 | .colorBlendOp = VK_BLEND_OP_ADD, | ||
| 451 | .srcAlphaBlendFactor = VK_BLEND_FACTOR_ZERO, | ||
| 452 | .dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO, | ||
| 453 | .alphaBlendOp = VK_BLEND_OP_ADD, | ||
| 454 | .colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | | ||
| 455 | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT, | ||
| 456 | }; | ||
| 457 | |||
| 458 | constexpr VkPipelineColorBlendAttachmentState color_blend_attachment_enabled{ | ||
| 459 | .blendEnable = VK_TRUE, | ||
| 460 | .srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA, | ||
| 461 | .dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, | ||
| 462 | .colorBlendOp = VK_BLEND_OP_ADD, | ||
| 463 | .srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE, | ||
| 464 | .dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO, | ||
| 465 | .alphaBlendOp = VK_BLEND_OP_ADD, | ||
| 466 | .colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | | ||
| 467 | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT, | ||
| 468 | }; | ||
| 469 | |||
| 470 | const VkPipelineColorBlendStateCreateInfo color_blend_ci{ | 446 | const VkPipelineColorBlendStateCreateInfo color_blend_ci{ |
| 471 | .sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, | 447 | .sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, |
| 472 | .pNext = nullptr, | 448 | .pNext = nullptr, |
| @@ -474,8 +450,7 @@ vk::Pipeline CreateWrappedPipeline(const Device& device, vk::RenderPass& renderp | |||
| 474 | .logicOpEnable = VK_FALSE, | 450 | .logicOpEnable = VK_FALSE, |
| 475 | .logicOp = VK_LOGIC_OP_COPY, | 451 | .logicOp = VK_LOGIC_OP_COPY, |
| 476 | .attachmentCount = 1, | 452 | .attachmentCount = 1, |
| 477 | .pAttachments = | 453 | .pAttachments = &blending, |
| 478 | enable_blending ? &color_blend_attachment_enabled : &color_blend_attachment_disabled, | ||
| 479 | .blendConstants = {0.0f, 0.0f, 0.0f, 0.0f}, | 454 | .blendConstants = {0.0f, 0.0f, 0.0f, 0.0f}, |
| 480 | }; | 455 | }; |
| 481 | 456 | ||
| @@ -515,6 +490,63 @@ vk::Pipeline CreateWrappedPipeline(const Device& device, vk::RenderPass& renderp | |||
| 515 | }); | 490 | }); |
| 516 | } | 491 | } |
| 517 | 492 | ||
| 493 | vk::Pipeline CreateWrappedPipeline(const Device& device, vk::RenderPass& renderpass, | ||
| 494 | vk::PipelineLayout& layout, | ||
| 495 | std::tuple<vk::ShaderModule&, vk::ShaderModule&> shaders) { | ||
| 496 | constexpr VkPipelineColorBlendAttachmentState color_blend_attachment_disabled{ | ||
| 497 | .blendEnable = VK_FALSE, | ||
| 498 | .srcColorBlendFactor = VK_BLEND_FACTOR_ZERO, | ||
| 499 | .dstColorBlendFactor = VK_BLEND_FACTOR_ZERO, | ||
| 500 | .colorBlendOp = VK_BLEND_OP_ADD, | ||
| 501 | .srcAlphaBlendFactor = VK_BLEND_FACTOR_ZERO, | ||
| 502 | .dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO, | ||
| 503 | .alphaBlendOp = VK_BLEND_OP_ADD, | ||
| 504 | .colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | | ||
| 505 | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT, | ||
| 506 | }; | ||
| 507 | |||
| 508 | return CreateWrappedPipelineImpl(device, renderpass, layout, shaders, | ||
| 509 | color_blend_attachment_disabled); | ||
| 510 | } | ||
| 511 | |||
| 512 | vk::Pipeline CreateWrappedPremultipliedBlendingPipeline( | ||
| 513 | const Device& device, vk::RenderPass& renderpass, vk::PipelineLayout& layout, | ||
| 514 | std::tuple<vk::ShaderModule&, vk::ShaderModule&> shaders) { | ||
| 515 | constexpr VkPipelineColorBlendAttachmentState color_blend_attachment_premultiplied{ | ||
| 516 | .blendEnable = VK_TRUE, | ||
| 517 | .srcColorBlendFactor = VK_BLEND_FACTOR_ONE, | ||
| 518 | .dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, | ||
| 519 | .colorBlendOp = VK_BLEND_OP_ADD, | ||
| 520 | .srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE, | ||
| 521 | .dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO, | ||
| 522 | .alphaBlendOp = VK_BLEND_OP_ADD, | ||
| 523 | .colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | | ||
| 524 | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT, | ||
| 525 | }; | ||
| 526 | |||
| 527 | return CreateWrappedPipelineImpl(device, renderpass, layout, shaders, | ||
| 528 | color_blend_attachment_premultiplied); | ||
| 529 | } | ||
| 530 | |||
| 531 | vk::Pipeline CreateWrappedCoverageBlendingPipeline( | ||
| 532 | const Device& device, vk::RenderPass& renderpass, vk::PipelineLayout& layout, | ||
| 533 | std::tuple<vk::ShaderModule&, vk::ShaderModule&> shaders) { | ||
| 534 | constexpr VkPipelineColorBlendAttachmentState color_blend_attachment_coverage{ | ||
| 535 | .blendEnable = VK_TRUE, | ||
| 536 | .srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA, | ||
| 537 | .dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, | ||
| 538 | .colorBlendOp = VK_BLEND_OP_ADD, | ||
| 539 | .srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE, | ||
| 540 | .dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO, | ||
| 541 | .alphaBlendOp = VK_BLEND_OP_ADD, | ||
| 542 | .colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | | ||
| 543 | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT, | ||
| 544 | }; | ||
| 545 | |||
| 546 | return CreateWrappedPipelineImpl(device, renderpass, layout, shaders, | ||
| 547 | color_blend_attachment_coverage); | ||
| 548 | } | ||
| 549 | |||
| 518 | VkWriteDescriptorSet CreateWriteDescriptorSet(std::vector<VkDescriptorImageInfo>& images, | 550 | VkWriteDescriptorSet CreateWriteDescriptorSet(std::vector<VkDescriptorImageInfo>& images, |
| 519 | VkSampler sampler, VkImageView view, | 551 | VkSampler sampler, VkImageView view, |
| 520 | VkDescriptorSet set, u32 binding) { | 552 | VkDescriptorSet set, u32 binding) { |
diff --git a/src/video_core/renderer_vulkan/present/util.h b/src/video_core/renderer_vulkan/present/util.h index 1104aaa15..5b22f0fa8 100644 --- a/src/video_core/renderer_vulkan/present/util.h +++ b/src/video_core/renderer_vulkan/present/util.h | |||
| @@ -42,8 +42,13 @@ vk::PipelineLayout CreateWrappedPipelineLayout(const Device& device, | |||
| 42 | vk::DescriptorSetLayout& layout); | 42 | vk::DescriptorSetLayout& layout); |
| 43 | vk::Pipeline CreateWrappedPipeline(const Device& device, vk::RenderPass& renderpass, | 43 | vk::Pipeline CreateWrappedPipeline(const Device& device, vk::RenderPass& renderpass, |
| 44 | vk::PipelineLayout& layout, | 44 | vk::PipelineLayout& layout, |
| 45 | std::tuple<vk::ShaderModule&, vk::ShaderModule&> shaders, | 45 | std::tuple<vk::ShaderModule&, vk::ShaderModule&> shaders); |
| 46 | bool enable_blending = false); | 46 | vk::Pipeline CreateWrappedPremultipliedBlendingPipeline( |
| 47 | const Device& device, vk::RenderPass& renderpass, vk::PipelineLayout& layout, | ||
| 48 | std::tuple<vk::ShaderModule&, vk::ShaderModule&> shaders); | ||
| 49 | vk::Pipeline CreateWrappedCoverageBlendingPipeline( | ||
| 50 | const Device& device, vk::RenderPass& renderpass, vk::PipelineLayout& layout, | ||
| 51 | std::tuple<vk::ShaderModule&, vk::ShaderModule&> shaders); | ||
| 47 | VkWriteDescriptorSet CreateWriteDescriptorSet(std::vector<VkDescriptorImageInfo>& images, | 52 | VkWriteDescriptorSet CreateWriteDescriptorSet(std::vector<VkDescriptorImageInfo>& images, |
| 48 | VkSampler sampler, VkImageView view, | 53 | VkSampler sampler, VkImageView view, |
| 49 | VkDescriptorSet set, u32 binding); | 54 | VkDescriptorSet set, u32 binding); |
diff --git a/src/video_core/renderer_vulkan/present/window_adapt_pass.cpp b/src/video_core/renderer_vulkan/present/window_adapt_pass.cpp index c5db0230d..22ffacf11 100644 --- a/src/video_core/renderer_vulkan/present/window_adapt_pass.cpp +++ b/src/video_core/renderer_vulkan/present/window_adapt_pass.cpp | |||
| @@ -22,7 +22,7 @@ WindowAdaptPass::WindowAdaptPass(const Device& device_, VkFormat frame_format, | |||
| 22 | CreatePipelineLayout(); | 22 | CreatePipelineLayout(); |
| 23 | CreateVertexShader(); | 23 | CreateVertexShader(); |
| 24 | CreateRenderPass(frame_format); | 24 | CreateRenderPass(frame_format); |
| 25 | CreatePipeline(); | 25 | CreatePipelines(); |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | WindowAdaptPass::~WindowAdaptPass() = default; | 28 | WindowAdaptPass::~WindowAdaptPass() = default; |
| @@ -34,7 +34,6 @@ void WindowAdaptPass::Draw(RasterizerVulkan& rasterizer, Scheduler& scheduler, s | |||
| 34 | 34 | ||
| 35 | const VkFramebuffer host_framebuffer{*dst->framebuffer}; | 35 | const VkFramebuffer host_framebuffer{*dst->framebuffer}; |
| 36 | const VkRenderPass renderpass{*render_pass}; | 36 | const VkRenderPass renderpass{*render_pass}; |
| 37 | const VkPipeline graphics_pipeline{*pipeline}; | ||
| 38 | const VkPipelineLayout graphics_pipeline_layout{*pipeline_layout}; | 37 | const VkPipelineLayout graphics_pipeline_layout{*pipeline_layout}; |
| 39 | const VkExtent2D render_area{ | 38 | const VkExtent2D render_area{ |
| 40 | .width = dst->width, | 39 | .width = dst->width, |
| @@ -44,9 +43,23 @@ void WindowAdaptPass::Draw(RasterizerVulkan& rasterizer, Scheduler& scheduler, s | |||
| 44 | const size_t layer_count = configs.size(); | 43 | const size_t layer_count = configs.size(); |
| 45 | std::vector<PresentPushConstants> push_constants(layer_count); | 44 | std::vector<PresentPushConstants> push_constants(layer_count); |
| 46 | std::vector<VkDescriptorSet> descriptor_sets(layer_count); | 45 | std::vector<VkDescriptorSet> descriptor_sets(layer_count); |
| 46 | std::vector<VkPipeline> graphics_pipelines(layer_count); | ||
| 47 | 47 | ||
| 48 | auto layer_it = layers.begin(); | 48 | auto layer_it = layers.begin(); |
| 49 | for (size_t i = 0; i < layer_count; i++) { | 49 | for (size_t i = 0; i < layer_count; i++) { |
| 50 | switch (configs[i].blending) { | ||
| 51 | case Tegra::BlendMode::Opaque: | ||
| 52 | default: | ||
| 53 | graphics_pipelines[i] = *opaque_pipeline; | ||
| 54 | break; | ||
| 55 | case Tegra::BlendMode::Premultiplied: | ||
| 56 | graphics_pipelines[i] = *premultiplied_pipeline; | ||
| 57 | break; | ||
| 58 | case Tegra::BlendMode::Coverage: | ||
| 59 | graphics_pipelines[i] = *coverage_pipeline; | ||
| 60 | break; | ||
| 61 | } | ||
| 62 | |||
| 50 | layer_it->ConfigureDraw(&push_constants[i], &descriptor_sets[i], rasterizer, *sampler, | 63 | layer_it->ConfigureDraw(&push_constants[i], &descriptor_sets[i], rasterizer, *sampler, |
| 51 | image_index, configs[i], layout); | 64 | image_index, configs[i], layout); |
| 52 | layer_it++; | 65 | layer_it++; |
| @@ -77,8 +90,8 @@ void WindowAdaptPass::Draw(RasterizerVulkan& rasterizer, Scheduler& scheduler, s | |||
| 77 | BeginRenderPass(cmdbuf, renderpass, host_framebuffer, render_area); | 90 | BeginRenderPass(cmdbuf, renderpass, host_framebuffer, render_area); |
| 78 | cmdbuf.ClearAttachments({clear_attachment}, {clear_rect}); | 91 | cmdbuf.ClearAttachments({clear_attachment}, {clear_rect}); |
| 79 | 92 | ||
| 80 | cmdbuf.BindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, graphics_pipeline); | ||
| 81 | for (size_t i = 0; i < layer_count; i++) { | 93 | for (size_t i = 0; i < layer_count; i++) { |
| 94 | cmdbuf.BindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, graphics_pipelines[i]); | ||
| 82 | cmdbuf.PushConstants(graphics_pipeline_layout, VK_SHADER_STAGE_VERTEX_BIT, | 95 | cmdbuf.PushConstants(graphics_pipeline_layout, VK_SHADER_STAGE_VERTEX_BIT, |
| 83 | push_constants[i]); | 96 | push_constants[i]); |
| 84 | cmdbuf.BindDescriptorSets(VK_PIPELINE_BIND_POINT_GRAPHICS, graphics_pipeline_layout, 0, | 97 | cmdbuf.BindDescriptorSets(VK_PIPELINE_BIND_POINT_GRAPHICS, graphics_pipeline_layout, 0, |
| @@ -129,9 +142,13 @@ void WindowAdaptPass::CreateRenderPass(VkFormat frame_format) { | |||
| 129 | render_pass = CreateWrappedRenderPass(device, frame_format, VK_IMAGE_LAYOUT_UNDEFINED); | 142 | render_pass = CreateWrappedRenderPass(device, frame_format, VK_IMAGE_LAYOUT_UNDEFINED); |
| 130 | } | 143 | } |
| 131 | 144 | ||
| 132 | void WindowAdaptPass::CreatePipeline() { | 145 | void WindowAdaptPass::CreatePipelines() { |
| 133 | pipeline = CreateWrappedPipeline(device, render_pass, pipeline_layout, | 146 | opaque_pipeline = CreateWrappedPipeline(device, render_pass, pipeline_layout, |
| 134 | std::tie(vertex_shader, fragment_shader), false); | 147 | std::tie(vertex_shader, fragment_shader)); |
| 148 | premultiplied_pipeline = CreateWrappedPremultipliedBlendingPipeline( | ||
| 149 | device, render_pass, pipeline_layout, std::tie(vertex_shader, fragment_shader)); | ||
| 150 | coverage_pipeline = CreateWrappedCoverageBlendingPipeline( | ||
| 151 | device, render_pass, pipeline_layout, std::tie(vertex_shader, fragment_shader)); | ||
| 135 | } | 152 | } |
| 136 | 153 | ||
| 137 | } // namespace Vulkan | 154 | } // namespace Vulkan |
diff --git a/src/video_core/renderer_vulkan/present/window_adapt_pass.h b/src/video_core/renderer_vulkan/present/window_adapt_pass.h index 0e2edfc31..cf667a4fc 100644 --- a/src/video_core/renderer_vulkan/present/window_adapt_pass.h +++ b/src/video_core/renderer_vulkan/present/window_adapt_pass.h | |||
| @@ -42,7 +42,7 @@ private: | |||
| 42 | void CreatePipelineLayout(); | 42 | void CreatePipelineLayout(); |
| 43 | void CreateVertexShader(); | 43 | void CreateVertexShader(); |
| 44 | void CreateRenderPass(VkFormat frame_format); | 44 | void CreateRenderPass(VkFormat frame_format); |
| 45 | void CreatePipeline(); | 45 | void CreatePipelines(); |
| 46 | 46 | ||
| 47 | private: | 47 | private: |
| 48 | const Device& device; | 48 | const Device& device; |
| @@ -52,7 +52,9 @@ private: | |||
| 52 | vk::ShaderModule vertex_shader; | 52 | vk::ShaderModule vertex_shader; |
| 53 | vk::ShaderModule fragment_shader; | 53 | vk::ShaderModule fragment_shader; |
| 54 | vk::RenderPass render_pass; | 54 | vk::RenderPass render_pass; |
| 55 | vk::Pipeline pipeline; | 55 | vk::Pipeline opaque_pipeline; |
| 56 | vk::Pipeline premultiplied_pipeline; | ||
| 57 | vk::Pipeline coverage_pipeline; | ||
| 56 | }; | 58 | }; |
| 57 | 59 | ||
| 58 | } // namespace Vulkan | 60 | } // namespace Vulkan |
diff --git a/src/video_core/renderer_vulkan/renderer_vulkan.cpp b/src/video_core/renderer_vulkan/renderer_vulkan.cpp index 48a105327..c7c234fd8 100644 --- a/src/video_core/renderer_vulkan/renderer_vulkan.cpp +++ b/src/video_core/renderer_vulkan/renderer_vulkan.cpp | |||
| @@ -101,8 +101,10 @@ RendererVulkan::RendererVulkan(Core::TelemetrySession& telemetry_session_, | |||
| 101 | surface), | 101 | surface), |
| 102 | blit_swapchain(device_memory, device, memory_allocator, present_manager, scheduler), | 102 | blit_swapchain(device_memory, device, memory_allocator, present_manager, scheduler), |
| 103 | blit_screenshot(device_memory, device, memory_allocator, present_manager, scheduler), | 103 | blit_screenshot(device_memory, device, memory_allocator, present_manager, scheduler), |
| 104 | blit_application_layer(device_memory, device, memory_allocator, present_manager, scheduler), | ||
| 104 | rasterizer(render_window, gpu, device_memory, device, memory_allocator, state_tracker, | 105 | rasterizer(render_window, gpu, device_memory, device, memory_allocator, state_tracker, |
| 105 | scheduler) { | 106 | scheduler), |
| 107 | application_frame() { | ||
| 106 | if (Settings::values.renderer_force_max_clock.GetValue() && device.ShouldBoostClocks()) { | 108 | if (Settings::values.renderer_force_max_clock.GetValue() && device.ShouldBoostClocks()) { |
| 107 | turbo_mode.emplace(instance, dld); | 109 | turbo_mode.emplace(instance, dld); |
| 108 | scheduler.RegisterOnSubmit([this] { turbo_mode->QueueSubmitted(); }); | 110 | scheduler.RegisterOnSubmit([this] { turbo_mode->QueueSubmitted(); }); |
diff --git a/src/video_core/renderer_vulkan/renderer_vulkan.h b/src/video_core/renderer_vulkan/renderer_vulkan.h index c6d8a0f21..ed9c7af7f 100644 --- a/src/video_core/renderer_vulkan/renderer_vulkan.h +++ b/src/video_core/renderer_vulkan/renderer_vulkan.h | |||
| @@ -80,8 +80,11 @@ private: | |||
| 80 | PresentManager present_manager; | 80 | PresentManager present_manager; |
| 81 | BlitScreen blit_swapchain; | 81 | BlitScreen blit_swapchain; |
| 82 | BlitScreen blit_screenshot; | 82 | BlitScreen blit_screenshot; |
| 83 | BlitScreen blit_application_layer; | ||
| 83 | RasterizerVulkan rasterizer; | 84 | RasterizerVulkan rasterizer; |
| 84 | std::optional<TurboMode> turbo_mode; | 85 | std::optional<TurboMode> turbo_mode; |
| 86 | |||
| 87 | Frame application_frame; | ||
| 85 | }; | 88 | }; |
| 86 | 89 | ||
| 87 | } // namespace Vulkan | 90 | } // namespace Vulkan |
diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h index a20c956ff..3a1cc060e 100644 --- a/src/video_core/texture_cache/texture_cache.h +++ b/src/video_core/texture_cache/texture_cache.h | |||
| @@ -746,7 +746,13 @@ std::pair<typename P::ImageView*, bool> TextureCache<P>::TryFindFramebufferImage | |||
| 746 | }(); | 746 | }(); |
| 747 | 747 | ||
| 748 | const auto GetImageViewForFramebuffer = [&](ImageId image_id) { | 748 | const auto GetImageViewForFramebuffer = [&](ImageId image_id) { |
| 749 | const ImageViewInfo info{ImageViewType::e2D, view_format}; | 749 | ImageViewInfo info{ImageViewType::e2D, view_format}; |
| 750 | if (config.blending == Tegra::BlendMode::Opaque) { | ||
| 751 | info.x_source = static_cast<u8>(SwizzleSource::R); | ||
| 752 | info.y_source = static_cast<u8>(SwizzleSource::G); | ||
| 753 | info.z_source = static_cast<u8>(SwizzleSource::B); | ||
| 754 | info.w_source = static_cast<u8>(SwizzleSource::OneFloat); | ||
| 755 | } | ||
| 750 | return std::make_pair(&slot_image_views[FindOrEmplaceImageView(image_id, info)], | 756 | return std::make_pair(&slot_image_views[FindOrEmplaceImageView(image_id, info)], |
| 751 | slot_images[image_id].IsRescaled()); | 757 | slot_images[image_id].IsRescaled()); |
| 752 | }; | 758 | }; |