Vulkan: Wire up bicubic and hermite scaling shaders

This commit is contained in:
goeiecool9999 2024-10-25 02:38:46 +02:00
parent f9a4b2dbb1
commit 49bd6ce567
3 changed files with 57 additions and 48 deletions

View File

@ -934,13 +934,6 @@ void LatteRenderTarget_copyToBackbuffer(LatteTextureView* textureView, bool isPa
{ {
sint32 scaling_filter = downscaling ? GetConfig().downscale_filter : GetConfig().upscale_filter; 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) if (scaling_filter == kLinearFilter)
{ {
if(renderUpsideDown) if(renderUpsideDown)

View File

@ -6,13 +6,11 @@ R"(#version 420
#ifdef VULKAN #ifdef VULKAN
layout(location = 0) in vec2 passUV; layout(location = 0) in vec2 passUV;
layout(binding = 0) uniform sampler2D textureSrc;
layout(location = 0) out vec4 colorOut0;
#else #else
in vec2 passUV; in vec2 passUV;
layout(binding=0) uniform sampler2D textureSrc;
layout(location = 0) out vec4 colorOut0;
#endif #endif
layout(binding = 0) uniform sampler2D textureSrc;
layout(location = 0) out vec4 colorOut0;
void main() void main()
{ {
@ -26,15 +24,17 @@ R"(
#ifdef VULKAN #ifdef VULKAN
layout(location = 0) in vec2 passUV; layout(location = 0) in vec2 passUV;
layout(binding = 0) uniform sampler2D textureSrc; layout(push_constant) uniform pc {
layout(binding = 1) uniform vec2 textureSrcResolution; vec2 textureSrcResolution;
layout(location = 0) out vec4 colorOut0; vec2 inputResolution;
vec2 outputResolution;
};
#else #else
in vec2 passUV; in vec2 passUV;
layout(binding=0) uniform sampler2D textureSrc;
uniform vec2 textureSrcResolution; uniform vec2 textureSrcResolution;
layout(location = 0) out vec4 colorOut0;
#endif #endif
layout(binding = 0) uniform sampler2D textureSrc;
layout(location = 0) out vec4 colorOut0;
vec4 cubic(float x) vec4 cubic(float x)
{ {
@ -84,10 +84,20 @@ const std::string RendererOutputShader::s_hermite_shader_source =
R"(#version 420 R"(#version 420
in vec4 gl_FragCoord; in vec4 gl_FragCoord;
in vec2 passUV;
layout(binding=0) uniform sampler2D textureSrc; 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 textureSrcResolution;
uniform vec2 outputResolution; uniform vec2 outputResolution;
#endif
layout(location = 0) out vec4 colorOut0; layout(location = 0) out vec4 colorOut0;
// https://www.shadertoy.com/view/MllSzX // 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_input_resolution = m_fragment_shader->GetUniformLocation("inputResolution");
m_attributes[1].m_loc_output_resolution = m_fragment_shader->GetUniformLocation("outputResolution"); 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 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 = GetOpenGlVertexSource(false);
vertex_source_ud = GetOpenGlVertexSource(true); 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 else
{ {
vertex_source = GetVulkanVertexSource(false); vertex_source = GetVulkanVertexSource(false);
vertex_source_ud = GetVulkanVertexSource(true); 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);
} }

View File

@ -2581,10 +2581,18 @@ VkPipeline VulkanRenderer::backbufferBlit_createGraphicsPipeline(VkDescriptorSet
colorBlending.blendConstants[2] = 0.0f; colorBlending.blendConstants[2] = 0.0f;
colorBlending.blendConstants[3] = 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{}; VkPipelineLayoutCreateInfo pipelineLayoutInfo{};
pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
pipelineLayoutInfo.setLayoutCount = 1; pipelineLayoutInfo.setLayoutCount = 1;
pipelineLayoutInfo.pSetLayouts = &descriptorLayout; pipelineLayoutInfo.pSetLayouts = &descriptorLayout;
pipelineLayoutInfo.pushConstantRangeCount = 1;
pipelineLayoutInfo.pPushConstantRanges = &pushConstantRange;
VkResult result = vkCreatePipelineLayout(m_logicalDevice, &pipelineLayoutInfo, nullptr, &m_pipelineLayout); VkResult result = vkCreatePipelineLayout(m_logicalDevice, &pipelineLayoutInfo, nullptr, &m_pipelineLayout);
if (result != VK_SUCCESS) 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); 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); vkCmdDraw(m_state.currentCommandBuffer, 6, 1, 0, 0);
vkCmdEndRenderPass(m_state.currentCommandBuffer); vkCmdEndRenderPass(m_state.currentCommandBuffer);