vulkan - Pipeline barriers across multiple shaders? -


judging vulkan barriers explained, seems each vkcmdpipelinebarrier introduces dependency between 2 subsequent pipeline “runs”. typical scenario of shader writes image , shader b samples same image, might this:

  1. dispatch shader writes image a
  2. vkcmdpipelinebarrier(cmd, vk_pipeline_stage_color_attachment_output_bit, vk_pipeline_stage_fragment_shader_bit, ...);
  3. dispatch shader reads image a

this defines dependency first shader execution's color attachment stage second shader execution's fragment stage. if want run independent commands in between? example

  1. dispatch shader writes image a
  2. dispatch unrelated shader doesn't touch image a
  3. vkcmdpipelinebarrier(cmd, vk_pipeline_stage_color_attachment_output_bit, vk_pipeline_stage_fragment_shader_bit, ...);
  4. dispatch shader reads image a

this still works, inefficient: because fragment shader stage has wait color attachment output stage of previous, unrelated shader. how specify dependency on shader before it?

you looking events. https://vulkan.lunarg.com/doc/view/1.0.57.0/windows/vkspec.html#synchronization-events

events synchronization primitive can used insert fine-grained dependency between commands submitted same queue, or between host , queue. events have 2 states - signaled , unsignaled. application can signal event, or unsignal it, on either host or device. device can wait event become signaled before executing further operations. no command exists wait event become signaled on host, current state of event can queried.

when recording command buffer, signal event via vkcmdsetevent after operation. thereafter vkcmdwaitevents can used define memory dependency between prior event signal operations , subsequent commands. see https://vulkan.lunarg.com/doc/view/1.0.57.0/windows/vkspec.html#vkcmdwaitevents.

make sure reset event before using again via vkcmdresetevent. , note:

applications should careful avoid race conditions when using events. there no direct ordering guarantee between vkcmdresetevent command , vkcmdwaitevents command submitted after it, other execution dependency must included between these commands (e.g. semaphore).


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -