| 1 | // Copyright (C) 2021 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QSPIRVSHADER_P_H |
| 5 | #define QSPIRVSHADER_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists for the convenience |
| 12 | // of a number of Qt sources files. This header file may change from |
| 13 | // version to version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtShaderTools/private/qtshadertoolsglobal_p.h> |
| 19 | #include <rhi/qshader.h> |
| 20 | |
| 21 | QT_BEGIN_NAMESPACE |
| 22 | |
| 23 | struct QSpirvShaderPrivate; |
| 24 | |
| 25 | class Q_SHADERTOOLS_EXPORT QSpirvShader |
| 26 | { |
| 27 | public: |
| 28 | enum class GlslFlag { |
| 29 | GlslEs = 0x01, |
| 30 | FixClipSpace = 0x02, |
| 31 | FragDefaultMediump = 0x04 |
| 32 | }; |
| 33 | Q_DECLARE_FLAGS(GlslFlags, GlslFlag) |
| 34 | |
| 35 | enum class MslFlag { |
| 36 | VertexAsCompute = 0x01, |
| 37 | WithUInt16Index = 0x02, |
| 38 | WithUInt32Index = 0x04 |
| 39 | }; |
| 40 | Q_DECLARE_FLAGS(MslFlags, MslFlag) |
| 41 | |
| 42 | enum class RemapFlag { |
| 43 | StripOnly = 0x01 |
| 44 | }; |
| 45 | Q_DECLARE_FLAGS(RemapFlags, RemapFlag) |
| 46 | |
| 47 | QSpirvShader(); |
| 48 | ~QSpirvShader(); |
| 49 | |
| 50 | void setSpirvBinary(const QByteArray &spirv, QShader::Stage stage); |
| 51 | |
| 52 | QShaderDescription shaderDescription() const; |
| 53 | |
| 54 | QByteArray spirvBinary() const; |
| 55 | QByteArray remappedSpirvBinary(RemapFlags flags = RemapFlags(), QString *errorMessage = nullptr) const; |
| 56 | |
| 57 | struct SeparateToCombinedImageSamplerMapping { |
| 58 | QByteArray textureName; |
| 59 | QByteArray samplerName; |
| 60 | QByteArray combinedSamplerName; |
| 61 | }; |
| 62 | |
| 63 | struct TessellationInfo { |
| 64 | // The tess.evaluation shader will likely declaer something like layout(triangles, fractional_odd_spacing, ccw) in; |
| 65 | // For Metal we need to know the tessellation mode (triangles) when generating the translated tess.control shader. |
| 66 | struct { |
| 67 | QShaderDescription::TessellationMode mode = QShaderDescription::TrianglesTessellationMode; |
| 68 | } infoForTesc; |
| 69 | // The tess.control shader will likely declare something like layout(vertices = 3) out; |
| 70 | // For Metal we need to know this value (3) when generating the translated tess.eval. shader. |
| 71 | struct { |
| 72 | int vertexCount = 3; |
| 73 | } infoForTese; |
| 74 | }; |
| 75 | |
| 76 | struct MultiViewInfo { |
| 77 | // layout(num_views = viewCount) in; see GL_OVR_multiview |
| 78 | int viewCount = 0; |
| 79 | }; |
| 80 | |
| 81 | QByteArray translateToGLSL(int version, |
| 82 | GlslFlags flags, |
| 83 | QShader::Stage stage, |
| 84 | const MultiViewInfo &multiViewInfo, |
| 85 | QVector<SeparateToCombinedImageSamplerMapping> *separateToCombinedImageSamplerMappings) const; |
| 86 | QByteArray translateToHLSL(int version, |
| 87 | QShader::NativeResourceBindingMap *nativeBindings) const; |
| 88 | QByteArray translateToMSL(int version, |
| 89 | MslFlags flags, |
| 90 | QShader::Stage stage, |
| 91 | QShader::NativeResourceBindingMap *nativeBindings, |
| 92 | QShader::NativeShaderInfo *shaderInfo, |
| 93 | const MultiViewInfo &multiViewInfo, |
| 94 | const TessellationInfo &tessInfo) const; |
| 95 | QString translationErrorMessage() const; |
| 96 | |
| 97 | private: |
| 98 | Q_DISABLE_COPY(QSpirvShader) |
| 99 | QSpirvShaderPrivate *d = nullptr; |
| 100 | }; |
| 101 | |
| 102 | Q_DECLARE_OPERATORS_FOR_FLAGS(QSpirvShader::GlslFlags) |
| 103 | Q_DECLARE_OPERATORS_FOR_FLAGS(QSpirvShader::MslFlags) |
| 104 | Q_DECLARE_OPERATORS_FOR_FLAGS(QSpirvShader::RemapFlags) |
| 105 | |
| 106 | QT_END_NAMESPACE |
| 107 | |
| 108 | #endif |
| 109 | |