bambooagile / QuickVLC

Vlc and Qt (Qml) integration library
Other
8 stars 2 forks source link

d3d11 support #9

Closed chubinou closed 2 years ago

chubinou commented 2 years ago

Hi, here is a first implementation of D3D support.

You will notice that I had to do quite some changes in your architecture to be able to support 2 backends.

Notably, I remove the use of a custom shader to directly use QSGSimpleTexture along with QSG native texture wrapper provided in Qt6. I didn't really see the need of a custom shader but maybe I missed something.

there are still some rough edges to polish but this first version should work for most cases.

in order to test my patch I use the following modifications in QuickVLC-exemples

diff --git a/main.cpp b/main.cpp
index e992e23..4944adb 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,12 +1,29 @@
 #include <QApplication>
 #include <QQmlApplicationEngine>
 #include <QQmlEngine>
+#include <QQuickWindow>

 int main(int argc, char *argv[])
 {
     // this important so we can call makeCurrent from our rendering thread
     QCoreApplication::setAttribute(Qt::AA_DontCheckOpenGLContextThreadAffinity);

+    bool useGL = false;
+    if (argc > 1) {
+        for (int i = 1; i < argc; i++) {
+            if (QString(argv[i]) == "--gl") {
+                useGL = true;
+                break;
+            }
+        }
+    }
+
+    if (useGL) {
+        QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGLRhi);
+    } else {
+        QQuickWindow::setGraphicsApi(QSGRendererInterface::Direct3D11Rhi);
+    }
+
     QApplication app(argc, argv);

     QQmlApplicationEngine engine;
diff --git a/main.qml b/main.qml
index a696943..84cc487 100644
--- a/main.qml
+++ b/main.qml
@@ -58,7 +58,9 @@ ApplicationWindow {

         Rectangle {
             anchors.fill: parent
-            color: "#000000"
+            color: "red"
+
+            ColorAnimation on color { to: "yellow"; duration: 1000; loops: Animation.Infinite }
         }

         MediaPlayer

feedbacks are welcomed

fix #6

aa-bamboo commented 2 years ago

@chubinou Hello. How do you enable Direct3D in the test application. Application always uses OpenGL on my machine even if I try to enforce using Direct3D with QQuickWindow::setGraphicsApi(QSGRendererInterface::Direct3D11);

chubinou commented 2 years ago

just changing the QQuickWindow::setGraphicsApi works for me

I start QuickVLC-Example using this script (nothing fancy just fixing path)

set PATH=%PATH%;C:\Users\Intel-VCSE-9\Downloads\nighly\vlc-4.0.0-dev
set PATH=%PATH%;C:\Users\Intel-VCSE-9\Downloads\mediagun\install\bin
set QML2_IMPORT_PATH=C:\Users\Intel-VCSE-9\Downloads\mediagun\install\qml
QuickVlcExample.exe %*

in the console I can see

qt.scenegraph.general: Using QRhi with backend D3D11

when using D3D backend, and

qt.scenegraph.general: Using QRhi with backend OpenGL

when starting with OpenGL

I used Qt version 6.3.1, downloaded using Qt installer

aa-bamboo commented 2 years ago

Strange. I tried the code in our application:

#ifdef Q_OS_WIN
    QQuickWindow::setGraphicsApi(QSGRendererInterface::Direct3D11);
#else
    // this important so we can call makeCurrent from our rendering thread
    QCoreApplication::setAttribute(Qt::AA_DontCheckOpenGLContextThreadAffinity);
#endif

And it uses OpenGL anyway...

chubinou commented 2 years ago

By default Qt6 on windows uses the D3D11 backend, so I guess you are setting something that force the OpenGL. maybe the QSG_RHI_BACKEND environment variable

chubinou commented 2 years ago

Note: The call to the function must happen before constructing the first QQuickWindow in the application. The graphics API cannot be changed afterwards.

are you making the call early enough?

also are you using a QQuickWindow/QQuickView or are you rendering the scene using alternative methods (QQuickWidget, QQuickRenderControl)

aa-bamboo commented 2 years ago

Sure. We are using QQuickWindow. And QQuickWindow::setGraphicsApi(QSGRendererInterface::Direct3D11); is the first line in the main() function. Need to have some debugging session on Windows.

chubinou commented 2 years ago

hum, OK, how do you know it's not using D3D11. Do you have logs? what did you trace?

what version of Qt do you use?

I can't really guess more without more information.

aa-bamboo commented 1 year ago

Sorry. I was not working on project for a couple of time. Qt version 6.3.2 I'll have deeper debug session soon. After that I'll be back with some logs.

aa-bamboo commented 1 year ago

Little update. Will hard work after 11/21