From 49bd6ce56734a6e90b2f49182802ad7dd5717f5b Mon Sep 17 00:00:00 2001 From: goeiecool9999 <7033575+goeiecool9999@users.noreply.github.com> Date: Fri, 25 Oct 2024 02:38:46 +0200 Subject: [PATCH 01/16] Vulkan: Wire up bicubic and hermite scaling shaders --- src/Cafe/HW/Latte/Core/LatteRenderTarget.cpp | 7 -- .../HW/Latte/Renderer/RendererOuputShader.cpp | 70 ++++++++----------- .../Latte/Renderer/Vulkan/VulkanRenderer.cpp | 28 ++++++++ 3 files changed, 57 insertions(+), 48 deletions(-) diff --git a/src/Cafe/HW/Latte/Core/LatteRenderTarget.cpp b/src/Cafe/HW/Latte/Core/LatteRenderTarget.cpp index ca6a2a4d..0e5eff8a 100644 --- a/src/Cafe/HW/Latte/Core/LatteRenderTarget.cpp +++ b/src/Cafe/HW/Latte/Core/LatteRenderTarget.cpp @@ -933,13 +933,6 @@ void LatteRenderTarget_copyToBackbuffer(LatteTextureView* textureView, bool isPa if (shader == nullptr) { sint32 scaling_filter = downscaling ? GetConfig().downscale_filter : GetConfig().upscale_filter; - - if (g_renderer->GetType() == RendererAPI::Vulkan) - { - // force linear or nearest neighbor filter - if(scaling_filter != kLinearFilter && scaling_filter != kNearestNeighborFilter) - scaling_filter = kLinearFilter; - } if (scaling_filter == kLinearFilter) { diff --git a/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp b/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp index cdbeb3f3..4be4639b 100644 --- a/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp +++ b/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp @@ -6,13 +6,11 @@ R"(#version 420 #ifdef VULKAN layout(location = 0) in vec2 passUV; -layout(binding = 0) uniform sampler2D textureSrc; -layout(location = 0) out vec4 colorOut0; #else in vec2 passUV; -layout(binding=0) uniform sampler2D textureSrc; -layout(location = 0) out vec4 colorOut0; #endif +layout(binding = 0) uniform sampler2D textureSrc; +layout(location = 0) out vec4 colorOut0; void main() { @@ -26,15 +24,17 @@ R"( #ifdef VULKAN layout(location = 0) in vec2 passUV; -layout(binding = 0) uniform sampler2D textureSrc; -layout(binding = 1) uniform vec2 textureSrcResolution; -layout(location = 0) out vec4 colorOut0; +layout(push_constant) uniform pc { + vec2 textureSrcResolution; + vec2 inputResolution; + vec2 outputResolution; +}; #else in vec2 passUV; -layout(binding=0) uniform sampler2D textureSrc; uniform vec2 textureSrcResolution; -layout(location = 0) out vec4 colorOut0; #endif +layout(binding = 0) uniform sampler2D textureSrc; +layout(location = 0) out vec4 colorOut0; vec4 cubic(float x) { @@ -83,11 +83,21 @@ void main(){ const std::string RendererOutputShader::s_hermite_shader_source = R"(#version 420 -in vec4 gl_FragCoord; -in vec2 passUV; +in vec4 gl_FragCoord; layout(binding=0) uniform sampler2D textureSrc; +#ifdef VULKAN +layout(location = 0) in vec2 passUV; +layout(push_constant) uniform pc { + vec2 textureSrcResolution; + vec2 inputResolution; + vec2 outputResolution; +}; +#else +in vec2 passUV; uniform vec2 textureSrcResolution; uniform vec2 outputResolution; +#endif + layout(location = 0) out vec4 colorOut0; // https://www.shadertoy.com/view/MllSzX @@ -171,18 +181,6 @@ RendererOutputShader::RendererOutputShader(const std::string& vertex_source, con m_attributes[1].m_loc_input_resolution = m_fragment_shader->GetUniformLocation("inputResolution"); m_attributes[1].m_loc_output_resolution = m_fragment_shader->GetUniformLocation("outputResolution"); } - else - { - cemuLog_logDebug(LogType::Force, "RendererOutputShader() - todo for Vulkan"); - m_attributes[0].m_loc_texture_src_resolution = -1; - m_attributes[0].m_loc_input_resolution = -1; - m_attributes[0].m_loc_output_resolution = -1; - - m_attributes[1].m_loc_texture_src_resolution = -1; - m_attributes[1].m_loc_input_resolution = -1; - m_attributes[1].m_loc_output_resolution = -1; - } - } void RendererOutputShader::SetUniformParameters(const LatteTextureView& texture_view, const Vector2i& input_res, const Vector2i& output_res) const @@ -349,28 +347,18 @@ void RendererOutputShader::InitializeStatic() { vertex_source = GetOpenGlVertexSource(false); vertex_source_ud = GetOpenGlVertexSource(true); - - s_copy_shader = new RendererOutputShader(vertex_source, s_copy_shader_source); - s_copy_shader_ud = new RendererOutputShader(vertex_source_ud, s_copy_shader_source); - - s_bicubic_shader = new RendererOutputShader(vertex_source, s_bicubic_shader_source); - s_bicubic_shader_ud = new RendererOutputShader(vertex_source_ud, s_bicubic_shader_source); - - s_hermit_shader = new RendererOutputShader(vertex_source, s_hermite_shader_source); - s_hermit_shader_ud = new RendererOutputShader(vertex_source_ud, s_hermite_shader_source); } else { vertex_source = GetVulkanVertexSource(false); vertex_source_ud = GetVulkanVertexSource(true); - - s_copy_shader = new RendererOutputShader(vertex_source, s_copy_shader_source); - s_copy_shader_ud = new RendererOutputShader(vertex_source_ud, s_copy_shader_source); - - /* s_bicubic_shader = new RendererOutputShader(vertex_source, s_bicubic_shader_source); TODO - s_bicubic_shader_ud = new RendererOutputShader(vertex_source_ud, s_bicubic_shader_source); - - s_hermit_shader = new RendererOutputShader(vertex_source, s_hermite_shader_source); - s_hermit_shader_ud = new RendererOutputShader(vertex_source_ud, s_hermite_shader_source);*/ } + s_copy_shader = new RendererOutputShader(vertex_source, s_copy_shader_source); + s_copy_shader_ud = new RendererOutputShader(vertex_source_ud, s_copy_shader_source); + + s_bicubic_shader = new RendererOutputShader(vertex_source, s_bicubic_shader_source); + s_bicubic_shader_ud = new RendererOutputShader(vertex_source_ud, s_bicubic_shader_source); + + s_hermit_shader = new RendererOutputShader(vertex_source, s_hermite_shader_source); + s_hermit_shader_ud = new RendererOutputShader(vertex_source_ud, s_hermite_shader_source); } diff --git a/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp b/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp index 9ad2c5ca..9680f4f8 100644 --- a/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp +++ b/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp @@ -2581,10 +2581,18 @@ VkPipeline VulkanRenderer::backbufferBlit_createGraphicsPipeline(VkDescriptorSet colorBlending.blendConstants[2] = 0.0f; colorBlending.blendConstants[3] = 0.0f; + VkPushConstantRange pushConstantRange{ + .stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT, + .offset = 0, + .size = 3 * sizeof(float) * 2 // 3 vec2's + }; + VkPipelineLayoutCreateInfo pipelineLayoutInfo{}; pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; pipelineLayoutInfo.setLayoutCount = 1; pipelineLayoutInfo.pSetLayouts = &descriptorLayout; + pipelineLayoutInfo.pushConstantRangeCount = 1; + pipelineLayoutInfo.pPushConstantRanges = &pushConstantRange; VkResult result = vkCreatePipelineLayout(m_logicalDevice, &pipelineLayoutInfo, nullptr, &m_pipelineLayout); if (result != VK_SUCCESS) @@ -2956,6 +2964,26 @@ void VulkanRenderer::DrawBackbufferQuad(LatteTextureView* texView, RendererOutpu vkCmdBindDescriptorSets(m_state.currentCommandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipelineLayout, 0, 1, &descriptSet, 0, nullptr); + // update push constants + Vector2f pushData; + + // textureSrcResolution + pushData = { + (float)texViewVk->baseTexture->width, + (float)texViewVk->baseTexture->height, + }; + vkCmdPushConstants(m_state.currentCommandBuffer, m_pipelineLayout, VK_SHADER_STAGE_FRAGMENT_BIT, 0*sizeof(float)*2, sizeof(float)*2, &pushData); + + // inputResolution + sint32 effectiveWidth, effectiveHeight; + texView->baseTexture->GetEffectiveSize(effectiveWidth, effectiveHeight, 0); + pushData = {(float)effectiveWidth, (float)effectiveHeight}; + vkCmdPushConstants(m_state.currentCommandBuffer, m_pipelineLayout, VK_SHADER_STAGE_FRAGMENT_BIT, 1*sizeof(float)*2, sizeof(float)*2, &pushData); + + // outputResolution + pushData = {(float)imageWidth,(float)imageHeight}; + vkCmdPushConstants(m_state.currentCommandBuffer, m_pipelineLayout, VK_SHADER_STAGE_FRAGMENT_BIT, 2*sizeof(float)*2, sizeof(float)*2, &pushData); + vkCmdDraw(m_state.currentCommandBuffer, 6, 1, 0, 0); vkCmdEndRenderPass(m_state.currentCommandBuffer); From 0f3fbef6886d1d4a58f6e3a7b8d241bdd9366d34 Mon Sep 17 00:00:00 2001 From: goeiecool9999 <7033575+goeiecool9999@users.noreply.github.com> Date: Sat, 26 Oct 2024 20:17:07 +0200 Subject: [PATCH 02/16] GraphicPack: Fix key for downscale magnification filter --- src/Cafe/GraphicPack/GraphicPack2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cafe/GraphicPack/GraphicPack2.cpp b/src/Cafe/GraphicPack/GraphicPack2.cpp index c54c31cb..da6cb4e7 100644 --- a/src/Cafe/GraphicPack/GraphicPack2.cpp +++ b/src/Cafe/GraphicPack/GraphicPack2.cpp @@ -960,7 +960,7 @@ bool GraphicPack2::Activate() auto option_upscale = rules.FindOption("upscaleMagFilter"); if(option_upscale && boost::iequals(*option_upscale, "NearestNeighbor")) m_output_settings.upscale_filter = LatteTextureView::MagFilter::kNearestNeighbor; - auto option_downscale = rules.FindOption("NearestNeighbor"); + auto option_downscale = rules.FindOption("downscaleMagFilter"); if (option_downscale && boost::iequals(*option_downscale, "NearestNeighbor")) m_output_settings.downscale_filter = LatteTextureView::MagFilter::kNearestNeighbor; } From 2ae490b2e83d45f8cf823fa8e99a26c10a2c1f53 Mon Sep 17 00:00:00 2001 From: goeiecool9999 <7033575+goeiecool9999@users.noreply.github.com> Date: Sat, 26 Oct 2024 20:21:15 +0200 Subject: [PATCH 03/16] match OpenGL minification filtering and wrapping modes --- .../HW/Latte/Renderer/Vulkan/LatteTextureViewVk.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Cafe/HW/Latte/Renderer/Vulkan/LatteTextureViewVk.cpp b/src/Cafe/HW/Latte/Renderer/Vulkan/LatteTextureViewVk.cpp index f0e2295e..33ad92e4 100644 --- a/src/Cafe/HW/Latte/Renderer/Vulkan/LatteTextureViewVk.cpp +++ b/src/Cafe/HW/Latte/Renderer/Vulkan/LatteTextureViewVk.cpp @@ -202,16 +202,24 @@ VkSampler LatteTextureViewVk::GetDefaultTextureSampler(bool useLinearTexFilter) VkSamplerCreateInfo samplerInfo{}; samplerInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; + // emulate OpenGL linear minFilter + // see note under: https://docs.vulkan.org/spec/latest/chapters/samplers.html#VkSamplerCreateInfo + samplerInfo.minFilter = VK_FILTER_LINEAR; + samplerInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; + samplerInfo.minLod = 0.0f; + samplerInfo.maxLod = 0.25f; + if (useLinearTexFilter) { samplerInfo.magFilter = VK_FILTER_LINEAR; - samplerInfo.minFilter = VK_FILTER_LINEAR; } else { samplerInfo.magFilter = VK_FILTER_NEAREST; - samplerInfo.minFilter = VK_FILTER_NEAREST; } + samplerInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; + samplerInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; + samplerInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; if (vkCreateSampler(m_device, &samplerInfo, nullptr, &sampler) != VK_SUCCESS) { From 03074e743b7dd1dd5135eee4119b318e58a0ce38 Mon Sep 17 00:00:00 2001 From: goeiecool9999 <7033575+goeiecool9999@users.noreply.github.com> Date: Sun, 27 Oct 2024 21:08:11 +0100 Subject: [PATCH 04/16] use inputResolution --- src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp b/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp index 4be4639b..b71f6232 100644 --- a/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp +++ b/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp @@ -31,7 +31,7 @@ layout(push_constant) uniform pc { }; #else in vec2 passUV; -uniform vec2 textureSrcResolution; +uniform vec2 inputResolution; #endif layout(binding = 0) uniform sampler2D textureSrc; layout(location = 0) out vec4 colorOut0; @@ -76,7 +76,7 @@ vec4 bcFilter(vec2 texcoord, vec2 texscale) } void main(){ - colorOut0 = vec4(bcFilter(passUV*textureSrcResolution, vec2(1.0,1.0)/textureSrcResolution).rgb,1.0); + colorOut0 = vec4(bcFilter(passUV*inputResolution, vec2(1.0,1.0)/inputResolution).rgb,1.0); } )"; @@ -94,8 +94,7 @@ layout(push_constant) uniform pc { }; #else in vec2 passUV; -uniform vec2 textureSrcResolution; -uniform vec2 outputResolution; +uniform vec2 inputResolution; #endif layout(location = 0) out vec4 colorOut0; @@ -152,7 +151,7 @@ vec3 BicubicHermiteTexture(vec2 uv, vec4 texelSize) } void main(){ - vec4 texelSize = vec4( 1.0 / outputResolution.xy, outputResolution.xy); + vec4 texelSize = vec4( 1.0 / inputResolution.xy, inputResolution.xy); colorOut0 = vec4(BicubicHermiteTexture(passUV, texelSize), 1.0); } )"; From 49b6fb4924439f771b8d7784dc607c3ea78fa651 Mon Sep 17 00:00:00 2001 From: goeiecool9999 <7033575+goeiecool9999@users.noreply.github.com> Date: Sun, 27 Oct 2024 21:32:39 +0100 Subject: [PATCH 05/16] take bilinear changes from #879 this makes the shader consistent with hermite and fixes the wrong offset --- .../HW/Latte/Renderer/RendererOuputShader.cpp | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp b/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp index b71f6232..88ced3a0 100644 --- a/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp +++ b/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp @@ -48,24 +48,23 @@ vec4 cubic(float x) return w / 6.0; } -vec4 bcFilter(vec2 texcoord, vec2 texscale) +vec4 bcFilter(vec2 uv, vec4 texelSize) { - float fx = fract(texcoord.x); - float fy = fract(texcoord.y); - texcoord.x -= fx; - texcoord.y -= fy; + vec2 pixel = uv*texelSize.zw - 0.5; + vec2 pixelFrac = fract(pixel); + vec2 pixelInt = pixel - pixelFrac; - vec4 xcubic = cubic(fx); - vec4 ycubic = cubic(fy); + vec4 xcubic = cubic(pixelFrac.x); + vec4 ycubic = cubic(pixelFrac.y); - vec4 c = vec4(texcoord.x - 0.5, texcoord.x + 1.5, texcoord.y - 0.5, texcoord.y + 1.5); + vec4 c = vec4(pixelInt.x - 0.5, pixelInt.x + 1.5, pixelInt.y - 0.5, pixelInt.y + 1.5); vec4 s = vec4(xcubic.x + xcubic.y, xcubic.z + xcubic.w, ycubic.x + ycubic.y, ycubic.z + ycubic.w); vec4 offset = c + vec4(xcubic.y, xcubic.w, ycubic.y, ycubic.w) / s; - vec4 sample0 = texture(textureSrc, vec2(offset.x, offset.z) * texscale); - vec4 sample1 = texture(textureSrc, vec2(offset.y, offset.z) * texscale); - vec4 sample2 = texture(textureSrc, vec2(offset.x, offset.w) * texscale); - vec4 sample3 = texture(textureSrc, vec2(offset.y, offset.w) * texscale); + vec4 sample0 = texture(textureSrc, vec2(offset.x, offset.z) * texelSize.xy); + vec4 sample1 = texture(textureSrc, vec2(offset.y, offset.z) * texelSize.xy); + vec4 sample2 = texture(textureSrc, vec2(offset.x, offset.w) * texelSize.xy); + vec4 sample3 = texture(textureSrc, vec2(offset.y, offset.w) * texelSize.xy); float sx = s.x / (s.x + s.y); float sy = s.z / (s.z + s.w); @@ -76,7 +75,8 @@ vec4 bcFilter(vec2 texcoord, vec2 texscale) } void main(){ - colorOut0 = vec4(bcFilter(passUV*inputResolution, vec2(1.0,1.0)/inputResolution).rgb,1.0); + vec4 texelSize = vec4( 1.0 / inputResolution.xy, inputResolution.xy); + colorOut0 = vec4(bcFilter(passUV, texelSize).rgb,1.0); } )"; From 0ea358b95f02bbcaefbad5a85b6330f3bbb144a2 Mon Sep 17 00:00:00 2001 From: goeiecool9999 <7033575+goeiecool9999@users.noreply.github.com> Date: Sun, 27 Oct 2024 21:36:48 +0100 Subject: [PATCH 06/16] take hermite changes from #879 makes the shader look a lot better and less pixelated --- src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp b/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp index 88ced3a0..1cd23979 100644 --- a/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp +++ b/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp @@ -120,7 +120,7 @@ vec3 BicubicHermiteTexture(vec2 uv, vec4 texelSize) vec2 frac = fract(pixel); pixel = floor(pixel) / texelSize.zw - vec2(texelSize.xy/2.0); - vec4 doubleSize = texelSize*texelSize; + vec4 doubleSize = texelSize*2.0; vec3 C00 = texture(textureSrc, pixel + vec2(-texelSize.x ,-texelSize.y)).rgb; vec3 C10 = texture(textureSrc, pixel + vec2( 0.0 ,-texelSize.y)).rgb; From a0a86ccb5ab64caf28d0ad044f66c77972e08b8b Mon Sep 17 00:00:00 2001 From: goeiecool9999 <7033575+goeiecool9999@users.noreply.github.com> Date: Sun, 27 Oct 2024 23:31:49 +0100 Subject: [PATCH 07/16] fix bicubic by using linear mag filter --- src/Cafe/HW/Latte/Core/LatteRenderTarget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cafe/HW/Latte/Core/LatteRenderTarget.cpp b/src/Cafe/HW/Latte/Core/LatteRenderTarget.cpp index 0e5eff8a..3bb6c7e3 100644 --- a/src/Cafe/HW/Latte/Core/LatteRenderTarget.cpp +++ b/src/Cafe/HW/Latte/Core/LatteRenderTarget.cpp @@ -950,7 +950,7 @@ void LatteRenderTarget_copyToBackbuffer(LatteTextureView* textureView, bool isPa else shader = RendererOutputShader::s_bicubic_shader; - filter = LatteTextureView::MagFilter::kNearestNeighbor; + filter = LatteTextureView::MagFilter::kLinear; } else if (scaling_filter == kBicubicHermiteFilter) { From becdd55096107093c2031215b326a8a7ff03f56d Mon Sep 17 00:00:00 2001 From: goeiecool9999 <7033575+goeiecool9999@users.noreply.github.com> Date: Sun, 27 Oct 2024 23:48:12 +0100 Subject: [PATCH 08/16] cleanup ifdef --- src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp b/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp index 1cd23979..870087c8 100644 --- a/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp +++ b/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp @@ -4,11 +4,7 @@ const std::string RendererOutputShader::s_copy_shader_source = R"(#version 420 -#ifdef VULKAN layout(location = 0) in vec2 passUV; -#else -in vec2 passUV; -#endif layout(binding = 0) uniform sampler2D textureSrc; layout(location = 0) out vec4 colorOut0; @@ -23,16 +19,16 @@ R"( #version 420 #ifdef VULKAN -layout(location = 0) in vec2 passUV; layout(push_constant) uniform pc { vec2 textureSrcResolution; vec2 inputResolution; vec2 outputResolution; }; #else -in vec2 passUV; uniform vec2 inputResolution; #endif + +layout(location = 0) in vec2 passUV; layout(binding = 0) uniform sampler2D textureSrc; layout(location = 0) out vec4 colorOut0; @@ -83,20 +79,18 @@ void main(){ const std::string RendererOutputShader::s_hermite_shader_source = R"(#version 420 -in vec4 gl_FragCoord; -layout(binding=0) uniform sampler2D textureSrc; #ifdef VULKAN -layout(location = 0) in vec2 passUV; layout(push_constant) uniform pc { vec2 textureSrcResolution; vec2 inputResolution; vec2 outputResolution; }; #else -in vec2 passUV; uniform vec2 inputResolution; #endif +layout(location = 0) in vec2 passUV; +layout(binding=0) uniform sampler2D textureSrc; layout(location = 0) out vec4 colorOut0; // https://www.shadertoy.com/view/MllSzX From 21899d13abf19b0856bdce4fb2cd6f3f04129c7e Mon Sep 17 00:00:00 2001 From: goeiecool9999 <7033575+goeiecool9999@users.noreply.github.com> Date: Mon, 28 Oct 2024 02:15:50 +0100 Subject: [PATCH 09/16] Respect minification selection Undoes previous change where it would always use linear, like OpenGL does for DrawBackBuffer. This allows GetDefaultTextureSampler to remain somewhat generic, even though it's only used for DrawBackBufferQuad right now. --- src/Cafe/HW/Latte/Renderer/Vulkan/LatteTextureViewVk.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Cafe/HW/Latte/Renderer/Vulkan/LatteTextureViewVk.cpp b/src/Cafe/HW/Latte/Renderer/Vulkan/LatteTextureViewVk.cpp index 33ad92e4..de76f76d 100644 --- a/src/Cafe/HW/Latte/Renderer/Vulkan/LatteTextureViewVk.cpp +++ b/src/Cafe/HW/Latte/Renderer/Vulkan/LatteTextureViewVk.cpp @@ -202,9 +202,9 @@ VkSampler LatteTextureViewVk::GetDefaultTextureSampler(bool useLinearTexFilter) VkSamplerCreateInfo samplerInfo{}; samplerInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; - // emulate OpenGL linear minFilter + // emulate OpenGL minFilters // see note under: https://docs.vulkan.org/spec/latest/chapters/samplers.html#VkSamplerCreateInfo - samplerInfo.minFilter = VK_FILTER_LINEAR; + // if maxLod = 0 then magnification is always performed samplerInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST; samplerInfo.minLod = 0.0f; samplerInfo.maxLod = 0.25f; @@ -212,10 +212,12 @@ VkSampler LatteTextureViewVk::GetDefaultTextureSampler(bool useLinearTexFilter) if (useLinearTexFilter) { samplerInfo.magFilter = VK_FILTER_LINEAR; + samplerInfo.minFilter = VK_FILTER_LINEAR; } else { samplerInfo.magFilter = VK_FILTER_NEAREST; + samplerInfo.minFilter = VK_FILTER_NEAREST; } samplerInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; samplerInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; From c86e164ca12351a7916f8faf1002cb4cee2168c9 Mon Sep 17 00:00:00 2001 From: goeiecool9999 <7033575+goeiecool9999@users.noreply.github.com> Date: Mon, 28 Oct 2024 13:54:04 +0100 Subject: [PATCH 10/16] programmatically prepend shader preamble --- .../HW/Latte/Renderer/RendererOuputShader.cpp | 65 ++++++++----------- .../HW/Latte/Renderer/RendererOuputShader.h | 2 + 2 files changed, 28 insertions(+), 39 deletions(-) diff --git a/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp b/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp index 870087c8..9517a124 100644 --- a/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp +++ b/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp @@ -2,12 +2,7 @@ #include "Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.h" const std::string RendererOutputShader::s_copy_shader_source = -R"(#version 420 - -layout(location = 0) in vec2 passUV; -layout(binding = 0) uniform sampler2D textureSrc; -layout(location = 0) out vec4 colorOut0; - +R"( void main() { colorOut0 = vec4(texture(textureSrc, passUV).rgb,1.0); @@ -16,22 +11,6 @@ void main() const std::string RendererOutputShader::s_bicubic_shader_source = R"( -#version 420 - -#ifdef VULKAN -layout(push_constant) uniform pc { - vec2 textureSrcResolution; - vec2 inputResolution; - vec2 outputResolution; -}; -#else -uniform vec2 inputResolution; -#endif - -layout(location = 0) in vec2 passUV; -layout(binding = 0) uniform sampler2D textureSrc; -layout(location = 0) out vec4 colorOut0; - vec4 cubic(float x) { float x2 = x * x; @@ -77,22 +56,7 @@ void main(){ )"; const std::string RendererOutputShader::s_hermite_shader_source = -R"(#version 420 - -#ifdef VULKAN -layout(push_constant) uniform pc { - vec2 textureSrcResolution; - vec2 inputResolution; - vec2 outputResolution; -}; -#else -uniform vec2 inputResolution; -#endif - -layout(location = 0) in vec2 passUV; -layout(binding=0) uniform sampler2D textureSrc; -layout(location = 0) out vec4 colorOut0; - +R"( // https://www.shadertoy.com/view/MllSzX vec3 CubicHermite (vec3 A, vec3 B, vec3 C, vec3 D, float t) @@ -152,8 +116,10 @@ void main(){ RendererOutputShader::RendererOutputShader(const std::string& vertex_source, const std::string& fragment_source) { + auto finalFragmentSrc = PrependFragmentPreamble(fragment_source); + m_vertex_shader = g_renderer->shader_create(RendererShader::ShaderType::kVertex, 0, 0, vertex_source, false, false); - m_fragment_shader = g_renderer->shader_create(RendererShader::ShaderType::kFragment, 0, 0, fragment_source, false, false); + m_fragment_shader = g_renderer->shader_create(RendererShader::ShaderType::kFragment, 0, 0, finalFragmentSrc, false, false); m_vertex_shader->PreponeCompilation(true); m_fragment_shader->PreponeCompilation(true); @@ -332,6 +298,27 @@ void main(){ )"; return vertex_source.str(); } + +std::string RendererOutputShader::PrependFragmentPreamble(const std::string& shaderSrc) +{ + return R"(#version 420 +#ifdef VULKAN +layout(push_constant) uniform pc { + vec2 textureSrcResolution; + vec2 inputResolution; + vec2 outputResolution; +}; +#else +uniform vec2 textureSrcResolution; +uniform vec2 inputResolution; +uniform vec2 outputResolution; +#endif + +layout(location = 0) in vec2 passUV; +layout(binding=0) uniform sampler2D textureSrc; +layout(location = 0) out vec4 colorOut0; +)" + shaderSrc; +} void RendererOutputShader::InitializeStatic() { std::string vertex_source, vertex_source_ud; diff --git a/src/Cafe/HW/Latte/Renderer/RendererOuputShader.h b/src/Cafe/HW/Latte/Renderer/RendererOuputShader.h index 398ac663..fca0c6ba 100644 --- a/src/Cafe/HW/Latte/Renderer/RendererOuputShader.h +++ b/src/Cafe/HW/Latte/Renderer/RendererOuputShader.h @@ -43,6 +43,8 @@ public: static std::string GetVulkanVertexSource(bool render_upside_down); static std::string GetOpenGlVertexSource(bool render_upside_down); + static std::string PrependFragmentPreamble(const std::string& shaderSrc); + protected: RendererShader* m_vertex_shader; RendererShader* m_fragment_shader; From cd4284ab63b581053fb3dc21f86e25c3b9bee154 Mon Sep 17 00:00:00 2001 From: goeiecool9999 <7033575+goeiecool9999@users.noreply.github.com> Date: Mon, 28 Oct 2024 16:25:47 +0100 Subject: [PATCH 11/16] specify wrap mode and min filter for OpenGL to be consistent with Vulkan --- src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp b/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp index cf134a5d..6eff1033 100644 --- a/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp +++ b/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp @@ -584,6 +584,12 @@ void OpenGLRenderer::DrawBackbufferQuad(LatteTextureView* texView, RendererOutpu LatteTextureViewGL* texViewGL = (LatteTextureViewGL*)texView; texture_bindAndActivate(texView, 0); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + texViewGL->samplerState.clampS = texViewGL->samplerState.clampT = 0xFF; + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, useLinearTexFilter ? GL_LINEAR : GL_NEAREST); + texViewGL->samplerState.filterMin = 0xFFFFFFFF; glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, useLinearTexFilter ? GL_LINEAR : GL_NEAREST); texViewGL->samplerState.filterMag = 0xFFFFFFFF; From c98a0c3ae561290975972b51a23ea3a6969413f8 Mon Sep 17 00:00:00 2001 From: goeiecool9999 <7033575+goeiecool9999@users.noreply.github.com> Date: Tue, 29 Oct 2024 20:58:28 +0100 Subject: [PATCH 12/16] Change uniforms and cleanup code - Make textureSrcResolution the actual resolution of the textureSrc sampler image This reflects the expectations of graphic pack creators - Rename inputResolution to nativeResolution which is the non-overriden size Not sure if this is useful, but it's there already so let's not remove it. - Change SetUniformParameters to use lambda expression --- .../HW/Latte/Renderer/RendererOuputShader.cpp | 85 +++++++------------ .../HW/Latte/Renderer/RendererOuputShader.h | 10 +-- .../Latte/Renderer/Vulkan/VulkanRenderer.cpp | 12 +-- 3 files changed, 44 insertions(+), 63 deletions(-) diff --git a/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp b/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp index 9517a124..2c5d746a 100644 --- a/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp +++ b/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp @@ -50,7 +50,7 @@ vec4 bcFilter(vec2 uv, vec4 texelSize) } void main(){ - vec4 texelSize = vec4( 1.0 / inputResolution.xy, inputResolution.xy); + vec4 texelSize = vec4( 1.0 / textureSrcResolution.xy, textureSrcResolution.xy); colorOut0 = vec4(bcFilter(passUV, texelSize).rgb,1.0); } )"; @@ -109,7 +109,7 @@ vec3 BicubicHermiteTexture(vec2 uv, vec4 texelSize) } void main(){ - vec4 texelSize = vec4( 1.0 / inputResolution.xy, inputResolution.xy); + vec4 texelSize = vec4( 1.0 / textureSrcResolution.xy, textureSrcResolution.xy); colorOut0 = vec4(BicubicHermiteTexture(passUV, texelSize), 1.0); } )"; @@ -132,62 +132,43 @@ RendererOutputShader::RendererOutputShader(const std::string& vertex_source, con if (g_renderer->GetType() == RendererAPI::OpenGL) { - m_attributes[0].m_loc_texture_src_resolution = m_vertex_shader->GetUniformLocation("textureSrcResolution"); - m_attributes[0].m_loc_input_resolution = m_vertex_shader->GetUniformLocation("inputResolution"); - m_attributes[0].m_loc_output_resolution = m_vertex_shader->GetUniformLocation("outputResolution"); + m_uniformLocations[0].m_loc_textureSrcResolution = m_vertex_shader->GetUniformLocation("textureSrcResolution"); + m_uniformLocations[0].m_loc_nativeResolution = m_vertex_shader->GetUniformLocation("nativeResolution"); + m_uniformLocations[0].m_loc_outputResolution = m_vertex_shader->GetUniformLocation("outputResolution"); - m_attributes[1].m_loc_texture_src_resolution = m_fragment_shader->GetUniformLocation("textureSrcResolution"); - m_attributes[1].m_loc_input_resolution = m_fragment_shader->GetUniformLocation("inputResolution"); - m_attributes[1].m_loc_output_resolution = m_fragment_shader->GetUniformLocation("outputResolution"); + m_uniformLocations[1].m_loc_textureSrcResolution = m_fragment_shader->GetUniformLocation("textureSrcResolution"); + m_uniformLocations[1].m_loc_nativeResolution = m_fragment_shader->GetUniformLocation("nativeResolution"); + m_uniformLocations[1].m_loc_outputResolution = m_fragment_shader->GetUniformLocation("outputResolution"); } } void RendererOutputShader::SetUniformParameters(const LatteTextureView& texture_view, const Vector2i& input_res, const Vector2i& output_res) const { - float res[2]; - // vertex shader - if (m_attributes[0].m_loc_texture_src_resolution != -1) - { - res[0] = (float)texture_view.baseTexture->width; - res[1] = (float)texture_view.baseTexture->height; - m_vertex_shader->SetUniform2fv(m_attributes[0].m_loc_texture_src_resolution, res, 1); - } + auto setUniforms = [&](RendererShader* shader, const UniformLocations& attributes){ + float res[2]; + if (attributes.m_loc_textureSrcResolution != -1) + { + res[0] = (float)input_res.x; + res[1] = (float)input_res.y; + shader->SetUniform2fv(attributes.m_loc_textureSrcResolution, res, 1); + } - if (m_attributes[0].m_loc_input_resolution != -1) - { - res[0] = (float)input_res.x; - res[1] = (float)input_res.y; - m_vertex_shader->SetUniform2fv(m_attributes[0].m_loc_input_resolution, res, 1); - } + if (attributes.m_loc_nativeResolution != -1) + { + res[0] = (float)texture_view.baseTexture->width; + res[1] = (float)texture_view.baseTexture->height; + shader->SetUniform2fv(attributes.m_loc_nativeResolution, res, 1); + } - if (m_attributes[0].m_loc_output_resolution != -1) - { - res[0] = (float)output_res.x; - res[1] = (float)output_res.y; - m_vertex_shader->SetUniform2fv(m_attributes[0].m_loc_output_resolution, res, 1); - } - - // fragment shader - if (m_attributes[1].m_loc_texture_src_resolution != -1) - { - res[0] = (float)texture_view.baseTexture->width; - res[1] = (float)texture_view.baseTexture->height; - m_fragment_shader->SetUniform2fv(m_attributes[1].m_loc_texture_src_resolution, res, 1); - } - - if (m_attributes[1].m_loc_input_resolution != -1) - { - res[0] = (float)input_res.x; - res[1] = (float)input_res.y; - m_fragment_shader->SetUniform2fv(m_attributes[1].m_loc_input_resolution, res, 1); - } - - if (m_attributes[1].m_loc_output_resolution != -1) - { - res[0] = (float)output_res.x; - res[1] = (float)output_res.y; - m_fragment_shader->SetUniform2fv(m_attributes[1].m_loc_output_resolution, res, 1); - } + if (attributes.m_loc_outputResolution != -1) + { + res[0] = (float)output_res.x; + res[1] = (float)output_res.y; + shader->SetUniform2fv(attributes.m_loc_outputResolution, res, 1); + } + }; + setUniforms(m_vertex_shader, m_uniformLocations[0]); + setUniforms(m_fragment_shader, m_uniformLocations[1]); } RendererOutputShader* RendererOutputShader::s_copy_shader; @@ -305,12 +286,12 @@ std::string RendererOutputShader::PrependFragmentPreamble(const std::string& sha #ifdef VULKAN layout(push_constant) uniform pc { vec2 textureSrcResolution; - vec2 inputResolution; + vec2 nativeResolution; vec2 outputResolution; }; #else uniform vec2 textureSrcResolution; -uniform vec2 inputResolution; +uniform vec2 nativeResolution; uniform vec2 outputResolution; #endif diff --git a/src/Cafe/HW/Latte/Renderer/RendererOuputShader.h b/src/Cafe/HW/Latte/Renderer/RendererOuputShader.h index fca0c6ba..d89e2597 100644 --- a/src/Cafe/HW/Latte/Renderer/RendererOuputShader.h +++ b/src/Cafe/HW/Latte/Renderer/RendererOuputShader.h @@ -49,12 +49,12 @@ protected: RendererShader* m_vertex_shader; RendererShader* m_fragment_shader; - struct + struct UniformLocations { - sint32 m_loc_texture_src_resolution = -1; - sint32 m_loc_input_resolution = -1; - sint32 m_loc_output_resolution = -1; - } m_attributes[2]{}; + sint32 m_loc_textureSrcResolution = -1; + sint32 m_loc_nativeResolution = -1; + sint32 m_loc_outputResolution = -1; + } m_uniformLocations[2]{}; private: static const std::string s_copy_shader_source; diff --git a/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp b/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp index 9680f4f8..c2ff6a6a 100644 --- a/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp +++ b/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp @@ -2968,16 +2968,16 @@ void VulkanRenderer::DrawBackbufferQuad(LatteTextureView* texView, RendererOutpu Vector2f pushData; // textureSrcResolution + sint32 effectiveWidth, effectiveHeight; + texView->baseTexture->GetEffectiveSize(effectiveWidth, effectiveHeight, 0); + pushData = {(float)effectiveWidth, (float)effectiveHeight}; + vkCmdPushConstants(m_state.currentCommandBuffer, m_pipelineLayout, VK_SHADER_STAGE_FRAGMENT_BIT, 0*sizeof(float)*2, sizeof(float)*2, &pushData); + + // nativeResolution pushData = { (float)texViewVk->baseTexture->width, (float)texViewVk->baseTexture->height, }; - vkCmdPushConstants(m_state.currentCommandBuffer, m_pipelineLayout, VK_SHADER_STAGE_FRAGMENT_BIT, 0*sizeof(float)*2, sizeof(float)*2, &pushData); - - // inputResolution - sint32 effectiveWidth, effectiveHeight; - texView->baseTexture->GetEffectiveSize(effectiveWidth, effectiveHeight, 0); - pushData = {(float)effectiveWidth, (float)effectiveHeight}; vkCmdPushConstants(m_state.currentCommandBuffer, m_pipelineLayout, VK_SHADER_STAGE_FRAGMENT_BIT, 1*sizeof(float)*2, sizeof(float)*2, &pushData); // outputResolution From 6074e9049772bf726731544797390b407c74c3db Mon Sep 17 00:00:00 2001 From: goeiecool9999 <7033575+goeiecool9999@users.noreply.github.com> Date: Tue, 29 Oct 2024 21:10:00 +0100 Subject: [PATCH 13/16] Move getting the effective res into SetUniformParameters --- src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp | 5 +---- src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp | 8 +++++--- src/Cafe/HW/Latte/Renderer/RendererOuputShader.h | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp b/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp index 6eff1033..bbf988bc 100644 --- a/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp +++ b/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp @@ -570,13 +570,10 @@ void OpenGLRenderer::DrawBackbufferQuad(LatteTextureView* texView, RendererOutpu g_renderer->ClearColorbuffer(padView); } - sint32 effectiveWidth, effectiveHeight; - texView->baseTexture->GetEffectiveSize(effectiveWidth, effectiveHeight, 0); - shader_unbind(RendererShader::ShaderType::kGeometry); shader_bind(shader->GetVertexShader()); shader_bind(shader->GetFragmentShader()); - shader->SetUniformParameters(*texView, { effectiveWidth, effectiveHeight }, { imageWidth, imageHeight }); + shader->SetUniformParameters(*texView, {imageWidth, imageHeight}); // set viewport glViewportIndexedf(0, imageX, imageY, imageWidth, imageHeight); diff --git a/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp b/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp index 2c5d746a..4162f9d7 100644 --- a/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp +++ b/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp @@ -142,14 +142,16 @@ RendererOutputShader::RendererOutputShader(const std::string& vertex_source, con } } -void RendererOutputShader::SetUniformParameters(const LatteTextureView& texture_view, const Vector2i& input_res, const Vector2i& output_res) const +void RendererOutputShader::SetUniformParameters(const LatteTextureView& texture_view, const Vector2i& output_res) const { + sint32 effectiveWidth, effectiveHeight; + texture_view.baseTexture->GetEffectiveSize(effectiveWidth, effectiveHeight, 0); auto setUniforms = [&](RendererShader* shader, const UniformLocations& attributes){ float res[2]; if (attributes.m_loc_textureSrcResolution != -1) { - res[0] = (float)input_res.x; - res[1] = (float)input_res.y; + res[0] = (float)effectiveWidth; + res[1] = (float)effectiveHeight; shader->SetUniform2fv(attributes.m_loc_textureSrcResolution, res, 1); } diff --git a/src/Cafe/HW/Latte/Renderer/RendererOuputShader.h b/src/Cafe/HW/Latte/Renderer/RendererOuputShader.h index d89e2597..61b24c20 100644 --- a/src/Cafe/HW/Latte/Renderer/RendererOuputShader.h +++ b/src/Cafe/HW/Latte/Renderer/RendererOuputShader.h @@ -17,7 +17,7 @@ public: RendererOutputShader(const std::string& vertex_source, const std::string& fragment_source); virtual ~RendererOutputShader() = default; - void SetUniformParameters(const LatteTextureView& texture_view, const Vector2i& input_res, const Vector2i& output_res) const; + void SetUniformParameters(const LatteTextureView& texture_view, const Vector2i& output_res) const; RendererShader* GetVertexShader() const { From 826bb92d569aa12215475faabb2a922cc45da14f Mon Sep 17 00:00:00 2001 From: goeiecool9999 <7033575+goeiecool9999@users.noreply.github.com> Date: Wed, 30 Oct 2024 00:32:03 +0100 Subject: [PATCH 14/16] use a single PushConstants command --- .../HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp b/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp index c2ff6a6a..37432eeb 100644 --- a/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp +++ b/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp @@ -2965,24 +2965,23 @@ void VulkanRenderer::DrawBackbufferQuad(LatteTextureView* texView, RendererOutpu vkCmdBindDescriptorSets(m_state.currentCommandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipelineLayout, 0, 1, &descriptSet, 0, nullptr); // update push constants - Vector2f pushData; + Vector2f pushData[3]; // textureSrcResolution sint32 effectiveWidth, effectiveHeight; texView->baseTexture->GetEffectiveSize(effectiveWidth, effectiveHeight, 0); - pushData = {(float)effectiveWidth, (float)effectiveHeight}; - vkCmdPushConstants(m_state.currentCommandBuffer, m_pipelineLayout, VK_SHADER_STAGE_FRAGMENT_BIT, 0*sizeof(float)*2, sizeof(float)*2, &pushData); + pushData[0] = {(float)effectiveWidth, (float)effectiveHeight}; // nativeResolution - pushData = { + pushData[1] = { (float)texViewVk->baseTexture->width, (float)texViewVk->baseTexture->height, }; - vkCmdPushConstants(m_state.currentCommandBuffer, m_pipelineLayout, VK_SHADER_STAGE_FRAGMENT_BIT, 1*sizeof(float)*2, sizeof(float)*2, &pushData); // outputResolution - pushData = {(float)imageWidth,(float)imageHeight}; - vkCmdPushConstants(m_state.currentCommandBuffer, m_pipelineLayout, VK_SHADER_STAGE_FRAGMENT_BIT, 2*sizeof(float)*2, sizeof(float)*2, &pushData); + pushData[2] = {(float)imageWidth,(float)imageHeight}; + + vkCmdPushConstants(m_state.currentCommandBuffer, m_pipelineLayout, VK_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(float) * 2 * 3, &pushData); vkCmdDraw(m_state.currentCommandBuffer, 6, 1, 0, 0); From e2e9e81c3eaa626b401a9a61f10daf7335f95d7f Mon Sep 17 00:00:00 2001 From: goeiecool9999 <7033575+goeiecool9999@users.noreply.github.com> Date: Wed, 30 Oct 2024 00:59:21 +0100 Subject: [PATCH 15/16] Bump GLSL version to 430 (and formatting --- src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp b/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp index 4162f9d7..8fc50fa2 100644 --- a/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp +++ b/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp @@ -284,7 +284,7 @@ void main(){ std::string RendererOutputShader::PrependFragmentPreamble(const std::string& shaderSrc) { - return R"(#version 420 + return R"(#version 430 #ifdef VULKAN layout(push_constant) uniform pc { vec2 textureSrcResolution; @@ -298,7 +298,7 @@ uniform vec2 outputResolution; #endif layout(location = 0) in vec2 passUV; -layout(binding=0) uniform sampler2D textureSrc; +layout(binding = 0) uniform sampler2D textureSrc; layout(location = 0) out vec4 colorOut0; )" + shaderSrc; } From 49e08404427d9733d6611840af1d18dc7617b7ce Mon Sep 17 00:00:00 2001 From: goeiecool9999 <7033575+goeiecool9999@users.noreply.github.com> Date: Thu, 31 Oct 2024 00:24:19 +0100 Subject: [PATCH 16/16] rename parameter --- src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp b/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp index 8fc50fa2..409dc24f 100644 --- a/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp +++ b/src/Cafe/HW/Latte/Renderer/RendererOuputShader.cpp @@ -146,27 +146,27 @@ void RendererOutputShader::SetUniformParameters(const LatteTextureView& texture_ { sint32 effectiveWidth, effectiveHeight; texture_view.baseTexture->GetEffectiveSize(effectiveWidth, effectiveHeight, 0); - auto setUniforms = [&](RendererShader* shader, const UniformLocations& attributes){ + auto setUniforms = [&](RendererShader* shader, const UniformLocations& locations){ float res[2]; - if (attributes.m_loc_textureSrcResolution != -1) + if (locations.m_loc_textureSrcResolution != -1) { res[0] = (float)effectiveWidth; res[1] = (float)effectiveHeight; - shader->SetUniform2fv(attributes.m_loc_textureSrcResolution, res, 1); + shader->SetUniform2fv(locations.m_loc_textureSrcResolution, res, 1); } - if (attributes.m_loc_nativeResolution != -1) + if (locations.m_loc_nativeResolution != -1) { res[0] = (float)texture_view.baseTexture->width; res[1] = (float)texture_view.baseTexture->height; - shader->SetUniform2fv(attributes.m_loc_nativeResolution, res, 1); + shader->SetUniform2fv(locations.m_loc_nativeResolution, res, 1); } - if (attributes.m_loc_outputResolution != -1) + if (locations.m_loc_outputResolution != -1) { res[0] = (float)output_res.x; res[1] = (float)output_res.y; - shader->SetUniform2fv(attributes.m_loc_outputResolution, res, 1); + shader->SetUniform2fv(locations.m_loc_outputResolution, res, 1); } }; setUniforms(m_vertex_shader, m_uniformLocations[0]);