Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QVulkanWindow vs. QRHI /QRHI Widget?
QtWS25 Last Chance

QVulkanWindow vs. QRHI /QRHI Widget?

Scheduled Pinned Locked Moved Solved General and Desktop
vulkanqvulkanwindowqrhiqrhiwidgetc++qt
8 Posts 4 Posters 425 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    StudentScripter
    wrote on last edited by
    #1

    Both can be used to draw things with vulkan but what exactly is the advantage/difference or better what should i by using for rendering custom 2d scenes with shaders with vulkan.

    From what i've read in the documentation QRHI is more flexible especially cause it can be integrated as painting backend for widgets. It also supports other graphics api's but my main focus is vulkan.

    1 Reply Last reply
    0
    • S StudentScripter

      @SGaist Yes but in this case wouldn't it be possible to force vulkan usage on end users system using QRHI too?

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #8

      @StudentScripter

      From QRHI :

      Each QRhi instance is backed by a backend for a specific graphics API. The selection of the backend is a run time choice and is up to the application or library that creates the QRhi instance.

      See also the example:

      #if QT_CONFIG(vulkan)
          QVulkanInstance inst;
      #endif
      // ...
      // ...
      // ...
      // ...
      #elif QT_CONFIG(vulkan)
          inst.setExtensions(QRhiVulkanInitParams::preferredInstanceExtensions());
          if (inst.create()) {
              QRhiVulkanInitParams params;
              params.inst = &inst;
              rhi.reset(QRhi::create(QRhi::Vulkan, &params));
          } else {
              qFatal("Failed to create Vulkan instance");
          }
      #endif
          if (rhi)
              qDebug() << rhi->backendName() << rhi->driverInfo();
          else
              qFatal("Failed to initialize RHI");
      

      So it's up to YOU (the developer) to chose a backend (or leave it dynamic)...
      If you force the use of Vulkan and further only use the Vulkan API, you program/code only works with Vulkan

      and like @SGaist said above... if no Vulkan SDK or libs are found or the system is incompatible with Vulkan at all, your program won't work (you need to handle that also... for example like shown in my example via defines and error handling)


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      3
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        QRhi is an abstraction layer that can make use of different backends depending on the OS you are running your application on.

        QVulkanWindow is dedicated for Vulkan as the name suggests.

        If you are only interested in implementing Vulkan code then go with QVulkanWindow.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        S 1 Reply Last reply
        1
        • SGaistS SGaist

          Hi,

          QRhi is an abstraction layer that can make use of different backends depending on the OS you are running your application on.

          QVulkanWindow is dedicated for Vulkan as the name suggests.

          If you are only interested in implementing Vulkan code then go with QVulkanWindow.

          S Offline
          S Offline
          StudentScripter
          wrote on last edited by
          #3

          @SGaist Yes but QRHI can be used with Widgets such as QRHIWidget right? would that bring any advantages over embedding alot of QVulkanWindows? I my want some custom widgets such as an keyframe editor.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SimonSchroeder
            wrote on last edited by
            #4

            If you write code against QRHI you don't know which backend you get. If you then try to write shaders you basically have the smallest common subset that is supported by all backends. Or you only write against a single backend and others will run into problems you have a hard time to understand and debug. If you want to use Vulkan you should definitely use a QVulkanWidget.

            It might be a little complicated to overlay widgets on top the QVulkanWidget. With the QOpenGLWidget this was allowed. There is a thread on StackOverflow that explains that QML on top of QVulkanWidget (through sharing OpenGL with Vulkan) can be used: https://stackoverflow.com/questions/52691818/qt-qvulkanwindow-overlay-widgets. Maybe something similar works with regular widgets (as those can be drawn on a QOpenGLWidget and that might be able to be used by Vulkan...

            S 1 Reply Last reply
            0
            • S SimonSchroeder

              If you write code against QRHI you don't know which backend you get. If you then try to write shaders you basically have the smallest common subset that is supported by all backends. Or you only write against a single backend and others will run into problems you have a hard time to understand and debug. If you want to use Vulkan you should definitely use a QVulkanWidget.

              It might be a little complicated to overlay widgets on top the QVulkanWidget. With the QOpenGLWidget this was allowed. There is a thread on StackOverflow that explains that QML on top of QVulkanWidget (through sharing OpenGL with Vulkan) can be used: https://stackoverflow.com/questions/52691818/qt-qvulkanwindow-overlay-widgets. Maybe something similar works with regular widgets (as those can be drawn on a QOpenGLWidget and that might be able to be used by Vulkan...

              S Offline
              S Offline
              StudentScripter
              wrote on last edited by
              #5

              @SimonSchroeder Alright that definitely helps. But one last question to this topic: isn't there a way to force using vulkan with QRHI? Cause obviously QVulkanWindow is probably doing something similar otherwise it would be broken on many systems that don't have vulcan.

              SGaistS 1 Reply Last reply
              0
              • S StudentScripter

                @SimonSchroeder Alright that definitely helps. But one last question to this topic: isn't there a way to force using vulkan with QRHI? Cause obviously QVulkanWindow is probably doing something similar otherwise it would be broken on many systems that don't have vulcan.

                SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #6

                @StudentScripter QVulkanWindow won't work on system that don't support Vulkan.

                It's your responsibility to provide the required libraries along with your application.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                S 1 Reply Last reply
                0
                • SGaistS SGaist

                  @StudentScripter QVulkanWindow won't work on system that don't support Vulkan.

                  It's your responsibility to provide the required libraries along with your application.

                  S Offline
                  S Offline
                  StudentScripter
                  wrote on last edited by
                  #7

                  @SGaist Yes but in this case wouldn't it be possible to force vulkan usage on end users system using QRHI too?

                  Pl45m4P 1 Reply Last reply
                  0
                  • S StudentScripter

                    @SGaist Yes but in this case wouldn't it be possible to force vulkan usage on end users system using QRHI too?

                    Pl45m4P Offline
                    Pl45m4P Offline
                    Pl45m4
                    wrote on last edited by Pl45m4
                    #8

                    @StudentScripter

                    From QRHI :

                    Each QRhi instance is backed by a backend for a specific graphics API. The selection of the backend is a run time choice and is up to the application or library that creates the QRhi instance.

                    See also the example:

                    #if QT_CONFIG(vulkan)
                        QVulkanInstance inst;
                    #endif
                    // ...
                    // ...
                    // ...
                    // ...
                    #elif QT_CONFIG(vulkan)
                        inst.setExtensions(QRhiVulkanInitParams::preferredInstanceExtensions());
                        if (inst.create()) {
                            QRhiVulkanInitParams params;
                            params.inst = &inst;
                            rhi.reset(QRhi::create(QRhi::Vulkan, &params));
                        } else {
                            qFatal("Failed to create Vulkan instance");
                        }
                    #endif
                        if (rhi)
                            qDebug() << rhi->backendName() << rhi->driverInfo();
                        else
                            qFatal("Failed to initialize RHI");
                    

                    So it's up to YOU (the developer) to chose a backend (or leave it dynamic)...
                    If you force the use of Vulkan and further only use the Vulkan API, you program/code only works with Vulkan

                    and like @SGaist said above... if no Vulkan SDK or libs are found or the system is incompatible with Vulkan at all, your program won't work (you need to handle that also... for example like shown in my example via defines and error handling)


                    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                    ~E. W. Dijkstra

                    1 Reply Last reply
                    3
                    • S StudentScripter has marked this topic as solved on
                    • S StudentScripter has marked this topic as solved on

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved