Dolphin, the GameCube and Wii emulator - Forums
How to bind framebuffer as texture in vulkan? - Printable Version

+- Dolphin, the GameCube and Wii emulator - Forums (https://forums.dolphin-emu.org)
+-- Forum: Dolphin Emulator Discussion and Support (https://forums.dolphin-emu.org/Forum-dolphin-emulator-discussion-and-support)
+--- Forum: Development Discussion (https://forums.dolphin-emu.org/Forum-development-discussion)
+--- Thread: How to bind framebuffer as texture in vulkan? (/Thread-how-to-bind-framebuffer-as-texture-in-vulkan)



How to bind framebuffer as texture in vulkan? - weihuoya - 08-30-2018

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? Tongue
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");
   }
}



RE: How to bind framebuffer as texture in vulkan? - DJBarry004 - 08-31-2018

After a quick search, it seems to be doable only in GL. https://stackoverflow.com/.../bind-screen-framebuffer-to-texture


Nonetheless, I think this tutorial could help.

https://vulkan-tutorial.com/Drawing_a_triangle/Drawing/Framebuffers


RE: How to bind framebuffer as texture in vulkan? - Helios - 08-31-2018

Since they already wrote some code trying to do it, I'm going to assume that they already googled.

Anyways, from one of the graphics peeps.

< Stenzek> pretty sure it's not going to work well
< Stenzek> especially if their GPU is a tiler


RE: How to bind framebuffer as texture in vulkan? - JonnyH - 08-31-2018

No, this won't work as is - you need some magic to ensure the texture read is consistent with the last framebuffer write, and not some stale cached value. I don't think this is yet exposed in vulkan.

A workaround may be to schedule a copy blit for the current framebuffer to a new texture and read that, but that has obvious performance implications.