Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. Integration Direct3D 12 in Qt
QtWS25 Last Chance

Integration Direct3D 12 in Qt

Scheduled Pinned Locked Moved Unsolved 3rd Party Software
msvcdirectxqt 5.12.3exceptiondebug
7 Posts 3 Posters 1.6k 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.
  • R Offline
    R Offline
    range36rus
    wrote on 3 Aug 2019, 16:32 last edited by range36rus 8 Apr 2019, 09:57
    #1

    Hello. I use Qt 5.12.3 and Qt Creator 4.9.1 to create an application using Direct3D 12. I wrote the following testing code:

        using uint = unsigned int;
        ComPtr<IDXGIFactory4> dx_dxgiFactory(nullptr);
        std::vector<ComPtr<IDXGIAdapter1>> adapters;
        ComPtr<IDXGIAdapter1> adapter(nullptr);
        ComPtr<ID3D12Device1> dx_Device(nullptr);
        D3D_FEATURE_LEVEL dx_featureLevels [] =
        {
            D3D_FEATURE_LEVEL_12_1,
            D3D_FEATURE_LEVEL_12_0,
            D3D_FEATURE_LEVEL_11_1,
            D3D_FEATURE_LEVEL_11_0,
            D3D_FEATURE_LEVEL_10_1,
            D3D_FEATURE_LEVEL_10_0,
            D3D_FEATURE_LEVEL_9_3,
            D3D_FEATURE_LEVEL_9_2,
            D3D_FEATURE_LEVEL_9_1
        };
    
        if(FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&dx_dxgiFactory))))
            return -1;
    
        for(uint i(0); dx_dxgiFactory->EnumAdapters1(i, adapter.GetAddressOf()) != DXGI_ERROR_NOT_FOUND;i++)
            adapters.push_back(adapter);
    
        for(auto&& a: adapters)
        {
    //        DXGI_ADAPTER_DESC1 desc;
    //        a->GetDesc1(&desc);
    //        qDebug() << QString::fromStdWString(std::wstring(desc.Description));
            for(auto&& l: dx_featureLevels)
                if(SUCCEEDED(D3D12CreateDevice(a.Get(), l, IID_PPV_ARGS(dx_Device.GetAddressOf()))))
                {
                    qDebug() << "OK";
                    return 1;
                }
        }
        return -1;
    

    This code works fine in release, if you debug at each step, but then, when i call the D3D12CreateDevice, I have error :
    Screenshot
    However, the method returns S_OK. Why is this happening?
    PS : I have two graphic adapter - Intel HD Graphics 620 & nVidia GeForce 950M. I use a low-performance adapter Intel by default. I import the following variable, for using high-performance nVidia adapter :

    extern "C"
    {
        __declspec(dllexport) unsigned int NvOptimusEnablement = 1;
    }
    

    This gives me the ability to get the first nVidia graphics card when listing all adapters. But this doesnt solve the problem, the error still remains.
    I tried also inserting the code in a try - catch block, but it doesn't stop the exception :

        try
        {
            for(auto&& a: adapters)
            {
                //        DXGI_ADAPTER_DESC1 desc;
                //        a->GetDesc1(&desc);
                //        qDebug() << QString::fromStdWString(std::wstring(desc.Description));
                for(auto&& l: dx_featureLevels)
                    if(SUCCEEDED(D3D12CreateDevice(a.Get(), l, IID_PPV_ARGS(dx_Device.GetAddressOf()))))
                    {
                        qDebug() << "OK";
                        return 1;
                    }
            }
        }
        catch(...)
        {
            qDebug() << "error create dx12 device"; // unreachable code !
        }
    

    Please, help me :)
    PS : I'm using the 64 bit MSVC compiler 2017

    J 1 Reply Last reply 5 Aug 2019, 04:57
    0
    • R range36rus
      3 Aug 2019, 16:32

      Hello. I use Qt 5.12.3 and Qt Creator 4.9.1 to create an application using Direct3D 12. I wrote the following testing code:

          using uint = unsigned int;
          ComPtr<IDXGIFactory4> dx_dxgiFactory(nullptr);
          std::vector<ComPtr<IDXGIAdapter1>> adapters;
          ComPtr<IDXGIAdapter1> adapter(nullptr);
          ComPtr<ID3D12Device1> dx_Device(nullptr);
          D3D_FEATURE_LEVEL dx_featureLevels [] =
          {
              D3D_FEATURE_LEVEL_12_1,
              D3D_FEATURE_LEVEL_12_0,
              D3D_FEATURE_LEVEL_11_1,
              D3D_FEATURE_LEVEL_11_0,
              D3D_FEATURE_LEVEL_10_1,
              D3D_FEATURE_LEVEL_10_0,
              D3D_FEATURE_LEVEL_9_3,
              D3D_FEATURE_LEVEL_9_2,
              D3D_FEATURE_LEVEL_9_1
          };
      
          if(FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&dx_dxgiFactory))))
              return -1;
      
          for(uint i(0); dx_dxgiFactory->EnumAdapters1(i, adapter.GetAddressOf()) != DXGI_ERROR_NOT_FOUND;i++)
              adapters.push_back(adapter);
      
          for(auto&& a: adapters)
          {
      //        DXGI_ADAPTER_DESC1 desc;
      //        a->GetDesc1(&desc);
      //        qDebug() << QString::fromStdWString(std::wstring(desc.Description));
              for(auto&& l: dx_featureLevels)
                  if(SUCCEEDED(D3D12CreateDevice(a.Get(), l, IID_PPV_ARGS(dx_Device.GetAddressOf()))))
                  {
                      qDebug() << "OK";
                      return 1;
                  }
          }
          return -1;
      

      This code works fine in release, if you debug at each step, but then, when i call the D3D12CreateDevice, I have error :
      Screenshot
      However, the method returns S_OK. Why is this happening?
      PS : I have two graphic adapter - Intel HD Graphics 620 & nVidia GeForce 950M. I use a low-performance adapter Intel by default. I import the following variable, for using high-performance nVidia adapter :

      extern "C"
      {
          __declspec(dllexport) unsigned int NvOptimusEnablement = 1;
      }
      

      This gives me the ability to get the first nVidia graphics card when listing all adapters. But this doesnt solve the problem, the error still remains.
      I tried also inserting the code in a try - catch block, but it doesn't stop the exception :

          try
          {
              for(auto&& a: adapters)
              {
                  //        DXGI_ADAPTER_DESC1 desc;
                  //        a->GetDesc1(&desc);
                  //        qDebug() << QString::fromStdWString(std::wstring(desc.Description));
                  for(auto&& l: dx_featureLevels)
                      if(SUCCEEDED(D3D12CreateDevice(a.Get(), l, IID_PPV_ARGS(dx_Device.GetAddressOf()))))
                      {
                          qDebug() << "OK";
                          return 1;
                      }
              }
          }
          catch(...)
          {
              qDebug() << "error create dx12 device"; // unreachable code !
          }
      

      Please, help me :)
      PS : I'm using the 64 bit MSVC compiler 2017

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 5 Aug 2019, 04:57 last edited by
      #2

      @range36rus Did you try to ask in a Direct3D related forum as this isn't related to Qt?
      Chances to get an answer are higher then asking people who have experience with Direct3D.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • R Offline
        R Offline
        range36rus
        wrote on 5 Aug 2019, 09:48 last edited by
        #3

        @jsulm I ran the same code in Visual Studio and didn't have any problems

        J 1 Reply Last reply 5 Aug 2019, 23:53
        0
        • R range36rus
          5 Aug 2019, 09:48

          @jsulm I ran the same code in Visual Studio and didn't have any problems

          J Offline
          J Offline
          JKSH
          Moderators
          wrote on 5 Aug 2019, 23:53 last edited by
          #4

          @range36rus said in Integration Direct3D 12 in Qt:

          I ran the same code in Visual Studio and didn't have any problems

          Did you use the same compiler and run the debugger?

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          1
          • R Offline
            R Offline
            range36rus
            wrote on 6 Aug 2019, 09:51 last edited by
            #5

            @JKSH Yes of course

            J 1 Reply Last reply 7 Aug 2019, 00:57
            0
            • R range36rus
              6 Aug 2019, 09:51

              @JKSH Yes of course

              J Offline
              J Offline
              JKSH
              Moderators
              wrote on 7 Aug 2019, 00:57 last edited by
              #6

              @range36rus said in Integration Direct3D 12 in Qt:

              Yes of course

              And just to double-check: You're compiling exactly the same source code in both IDEs? In other words, you're also linking to the Qt libraries in Visual Studio?

              If that's the case, you'll need to identify what's different in the 2 builds (compiler options, defined flags, etc). Your Makefile might contain a clue.

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              1 Reply Last reply
              0
              • R Offline
                R Offline
                range36rus
                wrote on 7 Aug 2019, 20:53 last edited by
                #7

                @JKSH Yes, I created two simple console applications and added required libraries to them. Compiler keys are identical. I checked carefully. A one project have a mistake, and another doesn't have For example, a project with subprojects have this error, but QT Widgets does not have (but not always). Heisenbug?

                1 Reply Last reply
                0

                4/7

                5 Aug 2019, 23:53

                • Login

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