• Login
  • Register
  • Dolphin Forums
  • Home
  • FAQ
  • Download
  • Wiki
  • Code


Dolphin, the GameCube and Wii emulator - Forums › Dolphin Emulator Discussion and Support › Development Discussion v
« Previous 1 ... 16 17 18 19 20 ... 116 Next »

How to bind framebuffer as texture in vulkan?
View New Posts | View Today's Posts

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Thread Modes
How to bind framebuffer as texture in vulkan?
08-30-2018, 07:52 PM
#1
weihuoya Offline
Member
***
Posts: 73
Threads: 2
Joined: Aug 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");
   }
}
Find
Reply
08-31-2018, 02:06 AM
#2
DJBarry004 Offline
Don't even bother...
*******
Posts: 2,456
Threads: 33
Joined: Sep 2013
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
Rig 1: Windows 10 Home | AMD A6-1450 @ 600/1000/1400 MHz | AMD Radeon HD Graphics 8250 | 4GB RAM | HP Pavilion TouchSmart 11.

Rig 2: Windows 10 Pro | Intel Core i7-2640M @ 780/2800/3500 MHz | Intel HD 3000 Mobile | 8GB RAM | Dell Latitude 6320.
Find
Reply
08-31-2018, 02:21 AM (This post was last modified: 08-31-2018, 02:21 AM by Helios.)
#3
Helios Offline
Stellaaaaaaa
**********
Developers (Some Administrators and Super Moderators)
Posts: 4,397
Threads: 15
Joined: May 2012
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
Find
Reply
08-31-2018, 05:37 AM
#4
JonnyH Offline
Shameless AMD shill
**********
Developers (Some Administrators and Super Moderators)
Posts: 701
Threads: 0
Joined: May 2017
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.
Find
Reply
« Next Oldest | Next Newest »


  • View a Printable Version
  • Subscribe to this thread
Forum Jump:


Users browsing this thread: 1 Guest(s)



Powered By MyBB | Theme by Fragma

Linear Mode
Threaded Mode