diff options
author | Laszlo Agocs <laszlo.agocs@theqtcompany.com> | 2016-04-20 12:36:15 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@theqtcompany.com> | 2016-04-29 09:36:33 +0000 |
commit | e88e2940598086b57e6c844afa2eca4153d0f528 (patch) | |
tree | 54dc790adf9b8b384cb7067cce848c32dd58057f /src/quick/items/qquickgenericshadereffect_p.h | |
parent | e4d56b01b30ad6c8482dab3dab6600676a9d6632 (diff) |
Adaptable shader effect enablers
The D3D12 node implementation is mostly missing. The rest of the enablers
should be in place now however.
Importing QtQuick 2.8 provides new properties for ShaderEffect:
- shaderType can be used to decide which language should be used
- shaderCompilationType tells if compilation is runtime or offline
- shaderSourceType tells if the vertex/fragmentShader properties refer
to source strings or source files or pre-compiled bytecode files
The last two are bitmasks. In practice however we will support only
one approach per backend for now (runtime + source string for OpenGL,
offline + bytecode for D3D12).
In addition to QSGShaderEffectNode, introduce the QSGGuiThreadShaderEffectManager
interface. This provides the gui thread bits for the above and performs shader
reflection. Backends that use the new ShaderEffect system must provide both.
For each ShaderEffect item there will be a manager (on the gui thread) and
a node (on the render thread).
Reflection is expected to be done via standard helper libs (d3d12shader
+ D3DReflect from d3dcompiler for the D3D12 backend), or via manually inspecting
SPIR-V, or parsing the source (like the GL path does now), or by using some
3rd party library (not recommended). In any case we require that reflection is
doable on the gui thread without dependencies to the actual graphics API.
The ShaderEffect documentation is greatly extended, covering HLSL and the new
properties.
The test app uses manually compiled shaders on its HLSL path for now. This
is because there is no story yet for build system integration for public
use (the internal HLSL -> bytecode in C header rule is only suitable for
the d3d12 plugin itself, apps need something different).
Change-Id: Id112104906fbcb26b9902a35f19d8d509b340d1b
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Diffstat (limited to 'src/quick/items/qquickgenericshadereffect_p.h')
-rw-r--r-- | src/quick/items/qquickgenericshadereffect_p.h | 57 |
1 files changed, 45 insertions, 12 deletions
diff --git a/src/quick/items/qquickgenericshadereffect_p.h b/src/quick/items/qquickgenericshadereffect_p.h index 6a31276a61..bc90b493ca 100644 --- a/src/quick/items/qquickgenericshadereffect_p.h +++ b/src/quick/items/qquickgenericshadereffect_p.h @@ -53,11 +53,14 @@ #include <QtQuick/qquickitem.h> #include <private/qtquickglobal_p.h> +#include <private/qsgadaptationlayer_p.h> #include "qquickshadereffect_p.h" #include "qquickshadereffectmesh_p.h" QT_BEGIN_NAMESPACE +class QSignalMapper; + class Q_QUICK_PRIVATE_EXPORT QQuickGenericShaderEffect : public QObject { Q_OBJECT @@ -66,11 +69,11 @@ public: QQuickGenericShaderEffect(QQuickShaderEffect *item, QObject *parent = 0); ~QQuickGenericShaderEffect(); - QByteArray fragmentShader() const { return QByteArray(); } - void setFragmentShader(const QByteArray &code); + QByteArray fragmentShader() const { return m_fragShader; } + void setFragmentShader(const QByteArray &src); - QByteArray vertexShader() const { return QByteArray(); } - void setVertexShader(const QByteArray &code); + QByteArray vertexShader() const { return m_vertShader; } + void setVertexShader(const QByteArray &src); bool blending() const { return m_blending; } void setBlending(bool enable); @@ -81,31 +84,61 @@ public: QQuickShaderEffect::CullMode cullMode() const { return m_cullMode; } void setCullMode(QQuickShaderEffect::CullMode face); - QString log() const { return m_log; } - QQuickShaderEffect::Status status() const { return m_status; } + QString log() const; + QQuickShaderEffect::Status status() const; bool supportsAtlasTextures() const { return m_supportsAtlasTextures; } void setSupportsAtlasTextures(bool supports); + QQuickShaderEffect::ShaderType shaderType() const; + QQuickShaderEffect::ShaderCompilationType shaderCompilationType() const; + QQuickShaderEffect::ShaderSourceType shaderSourceType() const; + void handleEvent(QEvent *); void handleGeometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); QSGNode *handleUpdatePaintNode(QSGNode *, QQuickItem::UpdatePaintNodeData *); void handleComponentComplete(); void handleItemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &value); - QString parseLog() { return QString(); } +private slots: + void propertyChanged(int mappedId); + void sourceDestroyed(QObject *object); + void markGeometryDirtyAndUpdate(); + void markGeometryDirtyAndUpdateIfSupportsAtlas(); private: + QSGGuiThreadShaderEffectManager *shaderEffectManager() const; + + enum Shader { + Vertex, + Fragment, + + NShader + }; + void updateShader(Shader which, const QByteArray &src); + void disconnectSignals(Shader which); + bool sourceIsUnique(QQuickItem *source, Shader typeToSkip, int indexToSkip) const; + QQuickShaderEffect *m_item; QSize m_meshResolution; QQuickShaderEffectMesh *m_mesh; QQuickGridMesh m_defaultMesh; QQuickShaderEffect::CullMode m_cullMode; - QString m_log; - QQuickShaderEffect::Status m_status; - - uint m_blending : 1; - uint m_supportsAtlasTextures : 1; + bool m_blending; + bool m_supportsAtlasTextures; + mutable QSGGuiThreadShaderEffectManager *m_mgr; + QByteArray m_fragShader; + QByteArray m_vertShader; + + QSGShaderEffectNode::ShaderData m_shaders[NShader]; + QSGShaderEffectNode::DirtyShaderFlags m_dirty; + + struct SignalMapper { + SignalMapper() : mapper(nullptr), active(false) { } + QSignalMapper *mapper; + bool active; + }; + QVector<SignalMapper> m_signalMappers[NShader]; }; QT_END_NAMESPACE |