Vulkan icon indicating copy to clipboard operation
Vulkan copied to clipboard

Misleading example base subpass dependencies?

Open krOoze opened this issue 5 years ago • 10 comments


	dependencies[0].srcSubpass = VK_SUBPASS_EXTERNAL;
	dependencies[0].dstSubpass = 0;
	dependencies[0].srcStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
	dependencies[0].dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
	dependencies[0].srcAccessMask = VK_ACCESS_MEMORY_READ_BIT;
	dependencies[0].dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
	dependencies[0].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;

Not entirelly sure why exacly it is VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT (blocking execution dependency), so it probably needs a comment. Probably it should be either ALL_COMMANDS and have WRITE too, or it should be TOP_OF_PIPE and the access mask should be 0.

Furthemore, the loadOp is set as CLEAR, so only VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT should be needed.

	dependencies[1].srcSubpass = 0;
	dependencies[1].dstSubpass = VK_SUBPASS_EXTERNAL;
	dependencies[1].srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
	dependencies[1].dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
	dependencies[1].srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
	dependencies[1].dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
	dependencies[1].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;

VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT has no memory access. The wildcard VK_ACCESS_MEMORY_READ_BIT is technically allowed, though the access mask should probably be 0

Furthermore the StoreOp is STORE, so only VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT should suffice.

krOoze avatar Feb 07 '20 16:02 krOoze

dependencies[0].srcSubpass = VK_SUBPASS_EXTERNAL; dependencies[0].dstSubpass = 0; dependencies[0].srcStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;

Probably it should be either ALL_COMMANDS, or it should be TOP_OF_PIPE and the access mask should be 0.

Shouldn't it most likely be VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT to match submitInfo.pWaitDstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT?

cforfang avatar Feb 07 '20 16:02 cforfang

Also, seems like:

	dependencies[3].srcSubpass = 0;
	dependencies[3].dstSubpass = VK_SUBPASS_EXTERNAL;

... should have srcSubpass = 3 -- i.e. external dependency after the last subpass, not the first? Possibly one could argue this entire dependency is unnecessary though. :)

cforfang avatar Feb 07 '20 16:02 cforfang

Shouldn't it most likely be VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT to match

For the triangle demo, yea. Though it is used for all the demos, so hard to be sure.

should have srcSubpass = 3

You are probably looking elsewhere. The renderPassInfo.subpassCount is only 1, so 0 is appropriate. I am talking about vulkanexamplebase.cpp.

krOoze avatar Feb 07 '20 17:02 krOoze

Ah, yes I was looking at the subpasses sample :)

cforfang avatar Feb 07 '20 17:02 cforfang

I modify it like the following: dependencies[0].srcSubpass = VK_SUBPASS_EXTERNAL; dependencies[0].dstSubpass = 0; dependencies[0].srcStageMask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; dependencies[0].srcAccessMask = 0; //LAYOUT TRANSITION dependencies[0].dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT; dependencies[0].dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT; dependencies[0].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;

And validation layer didn't give errors.

CretaceousConstructor avatar Apr 08 '21 12:04 CretaceousConstructor

What layers say is bit irrelevant. It is the low bar and necessary but not the only condition. That layers are silent does not imply it is good code. This is a learning resource, so should not resort to trial-and-error and bruteforcing layers until they allow something.

krOoze avatar Apr 08 '21 13:04 krOoze

What layers say is bit irrelevant. It is the low bar and necessary but not the only condition. That layers are silent does not imply it is good code. This is a learning resource, so should not resort to trial-and-error and bruteforcing layers until they allow something.

inputattachments example can't even pass validation layer's synchronization tests,I posted an issue on that.

CretaceousConstructor avatar Apr 08 '21 14:04 CretaceousConstructor

  • My samples run fine on a plethora of platforms
  • Base validation is clean, sync validation is relatively new and I haven't had the time to test this
  • I'm currently doing a larger rework of how my samples work and will take a look at the sync issues after that
  • I'm with @krOoze and I'd prefer having proper barriers that make sense and not just broad barriers that silence the (alpha) synchronization layer

So please give me some time, I'll tackle validation once other things are finished.

SaschaWillems avatar Apr 08 '21 15:04 SaschaWillems

  • My samples run fine on a plethora of platforms
  • Base validation is clean, sync validation is relatively new and I haven't had the time to test this
  • I'm currently doing a larger rework of how my samples work and will take a look at the sync issues after that
  • I'm with @krOoze and I'd prefer having proper barriers that make sense and not just broad barriers that silence the (alpha) synchronization layer

So please give me some time, I'll tackle validation once other things are finished.

I'm so sorry,Sascha Willems,I didn't mean it.It definitely takes a lot efforts to make those examples,and you'll need time to make them perfect.If my English is offensive(I'm not native),please forgive me,I shouldn't be such pushy.

CretaceousConstructor avatar Apr 08 '21 15:04 CretaceousConstructor

Don't worry. No offense taken :)

I'm aware that synchronization needs improvement, esp. as so many people refer to my samples.

SaschaWillems avatar Apr 08 '21 15:04 SaschaWillems

I fixed the base (and triangle) subpass dependencies as per discussion in #666.

Sync validation is now clean for a lot of the samples, unless they do something different by e.g. using their own attachments. That'll be fixed in the future.

SaschaWillems avatar Jan 01 '23 08:01 SaschaWillems