Creating multiple command pools per thread in Vulkan





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I am trying to set up a multi-threaded renderer with Vulkan and I have a question about command pools.



Here https://on-demand.gputechconf.com/siggraph/2016/video/sig1625-tristan-lorach-vulkan-nvidia-essentials.mp4 at 13 minutes, they talk about how you should make 1 command pool per FRAME and cycle them in a ring buffer.
enter image description here



Why allocate 3 command pools per thread(one for each frame in a 3-frame ring buffer) instead of having just one command pool per thread and having 3 command buffers from it?










share|improve this question





























    1















    I am trying to set up a multi-threaded renderer with Vulkan and I have a question about command pools.



    Here https://on-demand.gputechconf.com/siggraph/2016/video/sig1625-tristan-lorach-vulkan-nvidia-essentials.mp4 at 13 minutes, they talk about how you should make 1 command pool per FRAME and cycle them in a ring buffer.
    enter image description here



    Why allocate 3 command pools per thread(one for each frame in a 3-frame ring buffer) instead of having just one command pool per thread and having 3 command buffers from it?










    share|improve this question

























      1












      1








      1








      I am trying to set up a multi-threaded renderer with Vulkan and I have a question about command pools.



      Here https://on-demand.gputechconf.com/siggraph/2016/video/sig1625-tristan-lorach-vulkan-nvidia-essentials.mp4 at 13 minutes, they talk about how you should make 1 command pool per FRAME and cycle them in a ring buffer.
      enter image description here



      Why allocate 3 command pools per thread(one for each frame in a 3-frame ring buffer) instead of having just one command pool per thread and having 3 command buffers from it?










      share|improve this question














      I am trying to set up a multi-threaded renderer with Vulkan and I have a question about command pools.



      Here https://on-demand.gputechconf.com/siggraph/2016/video/sig1625-tristan-lorach-vulkan-nvidia-essentials.mp4 at 13 minutes, they talk about how you should make 1 command pool per FRAME and cycle them in a ring buffer.
      enter image description here



      Why allocate 3 command pools per thread(one for each frame in a 3-frame ring buffer) instead of having just one command pool per thread and having 3 command buffers from it?







      c++ multithreading vulkan






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 22 '18 at 22:32









      ulak bladeulak blade

      61021648




      61021648
























          2 Answers
          2






          active

          oldest

          votes


















          1














          It's basically about limiting how much synchronization and state tracking you have to do. If you have one Command pool per frame per thread then you just need to track a single event for completion and then reset the entire Command pool, no matter how many Command buffers you created in it for that frame.



          From an engine point of view this can be quite nice for command buffers you don't intend to reuse multiple times - they become stateless fire and forget entities and you just need to persistently track the pool.



          Exact trade offs are going to vary here from application to application, and driver to driver, so YMMV in terms of what works best.






          share|improve this answer
























          • I see, and I suppose '3' is an arbitrary number - if frames take more to complete, I may need a bigger ring buffer

            – ulak blade
            Nov 22 '18 at 23:01






          • 1





            You don't want to have a frame queue that is too deep in your swapchain - latency from user input to something showing on screen becomes too high. Usually 2 or 3 is fine. 2 can cause issues with vsync locking, which 3 avoids, but there is not really any performance benefit to going above triple buffering and it just causes latency issues.

            – solidpixel
            Nov 22 '18 at 23:04













          • Oh I see, so the number of command pools in the ring buffer should match the buffer count in the swap chain?

            – ulak blade
            Nov 22 '18 at 23:09











          • I don't think so. Number of images in a swapchain may vary on different hardware vendors or even driver versions - even with the same creation parameters. You specify the minimal required number of images, but driver may give You more. So matching the size of the ring buffer with the number of swapchain images is not the best idea. Have a look here: software.intel.com/en-us/articles/…

            – Ekzuzy
            Nov 23 '18 at 14:39



















          2














          I think the premise here is that vkResetCommandPool is better than resetting individual command buffers. Which also requires VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT flag, whose existence is a little hint by the Specification itself that the ability to reset individual cmdbuffers may not be for free.



          Actually the speaker says so if you do not just read slides but get the full presentation.






          share|improve this answer


























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438692%2fcreating-multiple-command-pools-per-thread-in-vulkan%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            It's basically about limiting how much synchronization and state tracking you have to do. If you have one Command pool per frame per thread then you just need to track a single event for completion and then reset the entire Command pool, no matter how many Command buffers you created in it for that frame.



            From an engine point of view this can be quite nice for command buffers you don't intend to reuse multiple times - they become stateless fire and forget entities and you just need to persistently track the pool.



            Exact trade offs are going to vary here from application to application, and driver to driver, so YMMV in terms of what works best.






            share|improve this answer
























            • I see, and I suppose '3' is an arbitrary number - if frames take more to complete, I may need a bigger ring buffer

              – ulak blade
              Nov 22 '18 at 23:01






            • 1





              You don't want to have a frame queue that is too deep in your swapchain - latency from user input to something showing on screen becomes too high. Usually 2 or 3 is fine. 2 can cause issues with vsync locking, which 3 avoids, but there is not really any performance benefit to going above triple buffering and it just causes latency issues.

              – solidpixel
              Nov 22 '18 at 23:04













            • Oh I see, so the number of command pools in the ring buffer should match the buffer count in the swap chain?

              – ulak blade
              Nov 22 '18 at 23:09











            • I don't think so. Number of images in a swapchain may vary on different hardware vendors or even driver versions - even with the same creation parameters. You specify the minimal required number of images, but driver may give You more. So matching the size of the ring buffer with the number of swapchain images is not the best idea. Have a look here: software.intel.com/en-us/articles/…

              – Ekzuzy
              Nov 23 '18 at 14:39
















            1














            It's basically about limiting how much synchronization and state tracking you have to do. If you have one Command pool per frame per thread then you just need to track a single event for completion and then reset the entire Command pool, no matter how many Command buffers you created in it for that frame.



            From an engine point of view this can be quite nice for command buffers you don't intend to reuse multiple times - they become stateless fire and forget entities and you just need to persistently track the pool.



            Exact trade offs are going to vary here from application to application, and driver to driver, so YMMV in terms of what works best.






            share|improve this answer
























            • I see, and I suppose '3' is an arbitrary number - if frames take more to complete, I may need a bigger ring buffer

              – ulak blade
              Nov 22 '18 at 23:01






            • 1





              You don't want to have a frame queue that is too deep in your swapchain - latency from user input to something showing on screen becomes too high. Usually 2 or 3 is fine. 2 can cause issues with vsync locking, which 3 avoids, but there is not really any performance benefit to going above triple buffering and it just causes latency issues.

              – solidpixel
              Nov 22 '18 at 23:04













            • Oh I see, so the number of command pools in the ring buffer should match the buffer count in the swap chain?

              – ulak blade
              Nov 22 '18 at 23:09











            • I don't think so. Number of images in a swapchain may vary on different hardware vendors or even driver versions - even with the same creation parameters. You specify the minimal required number of images, but driver may give You more. So matching the size of the ring buffer with the number of swapchain images is not the best idea. Have a look here: software.intel.com/en-us/articles/…

              – Ekzuzy
              Nov 23 '18 at 14:39














            1












            1








            1







            It's basically about limiting how much synchronization and state tracking you have to do. If you have one Command pool per frame per thread then you just need to track a single event for completion and then reset the entire Command pool, no matter how many Command buffers you created in it for that frame.



            From an engine point of view this can be quite nice for command buffers you don't intend to reuse multiple times - they become stateless fire and forget entities and you just need to persistently track the pool.



            Exact trade offs are going to vary here from application to application, and driver to driver, so YMMV in terms of what works best.






            share|improve this answer













            It's basically about limiting how much synchronization and state tracking you have to do. If you have one Command pool per frame per thread then you just need to track a single event for completion and then reset the entire Command pool, no matter how many Command buffers you created in it for that frame.



            From an engine point of view this can be quite nice for command buffers you don't intend to reuse multiple times - they become stateless fire and forget entities and you just need to persistently track the pool.



            Exact trade offs are going to vary here from application to application, and driver to driver, so YMMV in terms of what works best.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 22 '18 at 22:56









            solidpixelsolidpixel

            5,30711223




            5,30711223













            • I see, and I suppose '3' is an arbitrary number - if frames take more to complete, I may need a bigger ring buffer

              – ulak blade
              Nov 22 '18 at 23:01






            • 1





              You don't want to have a frame queue that is too deep in your swapchain - latency from user input to something showing on screen becomes too high. Usually 2 or 3 is fine. 2 can cause issues with vsync locking, which 3 avoids, but there is not really any performance benefit to going above triple buffering and it just causes latency issues.

              – solidpixel
              Nov 22 '18 at 23:04













            • Oh I see, so the number of command pools in the ring buffer should match the buffer count in the swap chain?

              – ulak blade
              Nov 22 '18 at 23:09











            • I don't think so. Number of images in a swapchain may vary on different hardware vendors or even driver versions - even with the same creation parameters. You specify the minimal required number of images, but driver may give You more. So matching the size of the ring buffer with the number of swapchain images is not the best idea. Have a look here: software.intel.com/en-us/articles/…

              – Ekzuzy
              Nov 23 '18 at 14:39



















            • I see, and I suppose '3' is an arbitrary number - if frames take more to complete, I may need a bigger ring buffer

              – ulak blade
              Nov 22 '18 at 23:01






            • 1





              You don't want to have a frame queue that is too deep in your swapchain - latency from user input to something showing on screen becomes too high. Usually 2 or 3 is fine. 2 can cause issues with vsync locking, which 3 avoids, but there is not really any performance benefit to going above triple buffering and it just causes latency issues.

              – solidpixel
              Nov 22 '18 at 23:04













            • Oh I see, so the number of command pools in the ring buffer should match the buffer count in the swap chain?

              – ulak blade
              Nov 22 '18 at 23:09











            • I don't think so. Number of images in a swapchain may vary on different hardware vendors or even driver versions - even with the same creation parameters. You specify the minimal required number of images, but driver may give You more. So matching the size of the ring buffer with the number of swapchain images is not the best idea. Have a look here: software.intel.com/en-us/articles/…

              – Ekzuzy
              Nov 23 '18 at 14:39

















            I see, and I suppose '3' is an arbitrary number - if frames take more to complete, I may need a bigger ring buffer

            – ulak blade
            Nov 22 '18 at 23:01





            I see, and I suppose '3' is an arbitrary number - if frames take more to complete, I may need a bigger ring buffer

            – ulak blade
            Nov 22 '18 at 23:01




            1




            1





            You don't want to have a frame queue that is too deep in your swapchain - latency from user input to something showing on screen becomes too high. Usually 2 or 3 is fine. 2 can cause issues with vsync locking, which 3 avoids, but there is not really any performance benefit to going above triple buffering and it just causes latency issues.

            – solidpixel
            Nov 22 '18 at 23:04







            You don't want to have a frame queue that is too deep in your swapchain - latency from user input to something showing on screen becomes too high. Usually 2 or 3 is fine. 2 can cause issues with vsync locking, which 3 avoids, but there is not really any performance benefit to going above triple buffering and it just causes latency issues.

            – solidpixel
            Nov 22 '18 at 23:04















            Oh I see, so the number of command pools in the ring buffer should match the buffer count in the swap chain?

            – ulak blade
            Nov 22 '18 at 23:09





            Oh I see, so the number of command pools in the ring buffer should match the buffer count in the swap chain?

            – ulak blade
            Nov 22 '18 at 23:09













            I don't think so. Number of images in a swapchain may vary on different hardware vendors or even driver versions - even with the same creation parameters. You specify the minimal required number of images, but driver may give You more. So matching the size of the ring buffer with the number of swapchain images is not the best idea. Have a look here: software.intel.com/en-us/articles/…

            – Ekzuzy
            Nov 23 '18 at 14:39





            I don't think so. Number of images in a swapchain may vary on different hardware vendors or even driver versions - even with the same creation parameters. You specify the minimal required number of images, but driver may give You more. So matching the size of the ring buffer with the number of swapchain images is not the best idea. Have a look here: software.intel.com/en-us/articles/…

            – Ekzuzy
            Nov 23 '18 at 14:39













            2














            I think the premise here is that vkResetCommandPool is better than resetting individual command buffers. Which also requires VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT flag, whose existence is a little hint by the Specification itself that the ability to reset individual cmdbuffers may not be for free.



            Actually the speaker says so if you do not just read slides but get the full presentation.






            share|improve this answer






























              2














              I think the premise here is that vkResetCommandPool is better than resetting individual command buffers. Which also requires VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT flag, whose existence is a little hint by the Specification itself that the ability to reset individual cmdbuffers may not be for free.



              Actually the speaker says so if you do not just read slides but get the full presentation.






              share|improve this answer




























                2












                2








                2







                I think the premise here is that vkResetCommandPool is better than resetting individual command buffers. Which also requires VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT flag, whose existence is a little hint by the Specification itself that the ability to reset individual cmdbuffers may not be for free.



                Actually the speaker says so if you do not just read slides but get the full presentation.






                share|improve this answer















                I think the premise here is that vkResetCommandPool is better than resetting individual command buffers. Which also requires VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT flag, whose existence is a little hint by the Specification itself that the ability to reset individual cmdbuffers may not be for free.



                Actually the speaker says so if you do not just read slides but get the full presentation.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 23 '18 at 17:48

























                answered Nov 23 '18 at 13:06









                krOozekrOoze

                4,3301921




                4,3301921






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438692%2fcreating-multiple-command-pools-per-thread-in-vulkan%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    How to change which sound is reproduced for terminal bell?

                    Can I use Tabulator js library in my java Spring + Thymeleaf project?

                    Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents