1 | // Copyright (C) 2023 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 QSHADER_P_H |
5 | #define QSHADER_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 <rhi/qshader.h> |
19 | #include <QtCore/QAtomicInt> |
20 | #include <QtCore/QMap> |
21 | #include <QtCore/QDebug> |
22 | |
23 | QT_BEGIN_NAMESPACE |
24 | |
25 | struct Q_GUI_EXPORT QShaderPrivate |
26 | { |
27 | static const int QSB_VERSION = 9; |
28 | static const int QSB_VERSION_WITHOUT_INPUT_OUTPUT_INTERFACE_BLOCKS = 8; |
29 | static const int QSB_VERSION_WITHOUT_EXTENDED_STORAGE_BUFFER_INFO = 7; |
30 | static const int QSB_VERSION_WITHOUT_NATIVE_SHADER_INFO = 6; |
31 | static const int QSB_VERSION_WITHOUT_SEPARATE_IMAGES_AND_SAMPLERS = 5; |
32 | static const int QSB_VERSION_WITHOUT_VAR_ARRAYDIMS = 4; |
33 | static const int QSB_VERSION_WITH_CBOR = 3; |
34 | static const int QSB_VERSION_WITH_BINARY_JSON = 2; |
35 | static const int QSB_VERSION_WITHOUT_BINDINGS = 1; |
36 | |
37 | enum { |
38 | MslTessVertIndicesBufferBinding = 0, |
39 | MslTessVertTescOutputBufferBinding, |
40 | MslTessTescTessLevelBufferBinding, |
41 | MslTessTescPatchOutputBufferBinding, |
42 | MslTessTescParamsBufferBinding, |
43 | MslTessTescInputBufferBinding, |
44 | MslBufferSizeBufferBinding |
45 | }; |
46 | |
47 | QShaderPrivate() |
48 | : ref(1) |
49 | { |
50 | } |
51 | |
52 | QShaderPrivate(const QShaderPrivate &other) |
53 | : ref(1), |
54 | qsbVersion(other.qsbVersion), |
55 | stage(other.stage), |
56 | desc(other.desc), |
57 | shaders(other.shaders), |
58 | bindings(other.bindings), |
59 | combinedImageMap(other.combinedImageMap), |
60 | nativeShaderInfoMap(other.nativeShaderInfoMap) |
61 | { |
62 | } |
63 | |
64 | static QShaderPrivate *get(QShader *s) { return s->d; } |
65 | static const QShaderPrivate *get(const QShader *s) { return s->d; } |
66 | static int qtQsbVersion(QShader::SerializedFormatVersion qtVersion) { |
67 | switch (qtVersion) { |
68 | case QShader::SerializedFormatVersion::Qt_6_4: |
69 | return (QShaderPrivate::QSB_VERSION_WITHOUT_SEPARATE_IMAGES_AND_SAMPLERS + 1); |
70 | case QShader::SerializedFormatVersion::Qt_6_5: |
71 | return (QShaderPrivate::QSB_VERSION_WITHOUT_EXTENDED_STORAGE_BUFFER_INFO + 1); |
72 | default: |
73 | return QShaderPrivate::QSB_VERSION; |
74 | } |
75 | } |
76 | |
77 | QAtomicInt ref; |
78 | int qsbVersion = QSB_VERSION; |
79 | QShader::Stage stage = QShader::VertexStage; |
80 | QShaderDescription desc; |
81 | // QMap not QHash because we need to be able to iterate based on sorted keys |
82 | QMap<QShaderKey, QShaderCode> shaders; |
83 | QMap<QShaderKey, QShader::NativeResourceBindingMap> bindings; |
84 | QMap<QShaderKey, QShader::SeparateToCombinedImageSamplerMappingList> combinedImageMap; |
85 | QMap<QShaderKey, QShader::NativeShaderInfo> nativeShaderInfoMap; |
86 | }; |
87 | |
88 | QT_END_NAMESPACE |
89 | |
90 | #endif |
91 | |