barrier.lua 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. return {
  2. tag = 'compute',
  3. summary = 'Synchronize compute work.',
  4. description = [[
  5. Synchronizes compute work.
  6. By default, within a single Pass, multiple calls to `Pass:compute` can run on the GPU in any
  7. order, or all at the same time. This is great because it lets the GPU process the work as
  8. efficiently as possible, but sometimes multiple compute dispatches need to be sequenced.
  9. Calling this function will insert a barrier. All compute operations on the Pass after the
  10. barrier will only start once all of the previous compute operations on the Pass are finished.
  11. ]],
  12. arguments = {},
  13. returns = {},
  14. variants = {
  15. {
  16. arguments = {},
  17. returns = {}
  18. }
  19. },
  20. notes = [[
  21. It's only necessary to use a barrier if a compute shader is reading/writing the same bytes of
  22. memory that a previous compute operation in the same Pass read/wrote.
  23. Barriers will slow things down because they reduce parallelism by causing the GPU to wait.
  24. Strategic reordering of non-dependent :compute calls around the barrier can help.
  25. Calling this function before recording any :computes will do nothing, and calling it after the
  26. last :compute will do nothing.
  27. ]],
  28. example = [[
  29. pass = lovr.graphics.newPass()
  30. pass:setShader(computeShader)
  31. pass:compute(x, y, z)
  32. pass:compute(x, y, z)
  33. pass:barrier()
  34. pass:compute(x, y, z) --> waits for the previous 2 :computes to complete
  35. ]],
  36. related = {
  37. 'Pass:compute'
  38. }
  39. }