Could it realized framebuffer fetch in vulkan?
My android phone isn't support dual source blend, so I want to bind current framebuffer as texture, and fetch color in shader.
But it don't work what I expected.
so anyone could help me to do this?
My android phone isn't support dual source blend, so I want to bind current framebuffer as texture, and fetch color in shader.
But it don't work what I expected.
so anyone could help me to do this?
Code:
void Renderer::BindFramebufferAsTexture(u32 index)
{
Texture2D* retex = FramebufferManager::GetInstance()->GetResolvedEFBColorTexture();
if (!retex)
{
Texture2D* tex = FramebufferManager::GetInstance()->GetEFBColorTexture();
VkRect2D region = { { 0, 0 },{ tex->GetWidth(), tex->GetHeight() } };
retex = FramebufferManager::GetInstance()->ResolveEFBColorTexture(region);
}
if (retex)
{
VkImageView view = retex->GetView();
if (view)
{
StateTracker::GetInstance()->SetTexture(index, view);
StateTracker::GetInstance()->SetSampler(index, g_object_cache->GetPointSampler());
}
}
}
Code:
void VertexManager::vFlush()
{
// bind shader blend texture
bool useDstAlpha = bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate && bpmem.zcontrol.pixel_format == PEControl::RGBA6_Z24;
if (useDstAlpha && !g_vulkan_context->SupportsDualSourceBlend())
{
Renderer::GetInstance()->BindFramebufferAsTexture(1);
}
}
Code:
ShaderCode GeneratePixelShaderCode(APIType ApiType, const ShaderHostConfig& host_config,
const pixel_shader_uid_data* uid_data)
{
if (use_shader_blend)
{
if (host_config.backend_shader_framebuffer_fetch)
{
// Store off a copy of the initial fb value for blending
out.Write("\tfloat4 initial_ocol0 = FB_FETCH_VALUE;\n");
}
else
{
out.Write("\tfloat4 initial_ocol0 = texelFetch(samp[1], ivec3(rawpos.xy, 0), 0);\n");
}
out.Write("\tfloat4 ocol0;\n");
out.Write("\tfloat4 ocol1;\n");
}
}