| 1 | // Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB). |
|---|---|
| 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 QT3DRENDER_RENDER_RHI_RHIGRAPHICSPIPELINE_H |
| 5 | #define QT3DRENDER_RENDER_RHI_RHIGRAPHICSPIPELINE_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 other Qt classes. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <rhi/qrhi.h> |
| 19 | #include <rhihandle_types_p.h> |
| 20 | #include <pipelineuboset_p.h> |
| 21 | #include <Qt3DCore/qnodeid.h> |
| 22 | #include <Qt3DRender/private/handle_types_p.h> |
| 23 | #include <Qt3DRender/qgeometryrenderer.h> |
| 24 | |
| 25 | QT_BEGIN_NAMESPACE |
| 26 | |
| 27 | namespace Qt3DRender { |
| 28 | |
| 29 | namespace Render { |
| 30 | |
| 31 | namespace Rhi { |
| 32 | |
| 33 | class RHIBuffer; |
| 34 | |
| 35 | // Geometry | Shader | RenderStateMask |
| 36 | struct GraphicsPipelineIdentifier |
| 37 | { |
| 38 | int geometryLayoutKey; |
| 39 | Qt3DCore::QNodeId shader; |
| 40 | Qt3DCore::QNodeId renderTarget; |
| 41 | Qt3DRender::QGeometryRenderer::PrimitiveType primitiveType; |
| 42 | int renderStatesKey = 0; |
| 43 | }; |
| 44 | |
| 45 | struct ComputePipelineIdentifier |
| 46 | { |
| 47 | Qt3DCore::QNodeId shader; |
| 48 | int renderViewIndex; |
| 49 | }; |
| 50 | |
| 51 | template<typename Pipeline, typename Key> |
| 52 | class RHIPipelineBase |
| 53 | { |
| 54 | public: |
| 55 | virtual ~RHIPipelineBase() {} |
| 56 | |
| 57 | PipelineUBOSet* uboSet() { return &m_uboSet; } |
| 58 | |
| 59 | Pipeline *pipeline() const { return m_pipeline; } |
| 60 | void setPipeline(Pipeline *pipeline) { m_pipeline = pipeline; } |
| 61 | |
| 62 | void setKey(const Key &key) { m_key = key; } |
| 63 | Key key() const { return m_key; } |
| 64 | |
| 65 | void setShaderResourceBindings(QRhiShaderResourceBindings *shaderResourceBindings) { m_shaderResourceBindings = shaderResourceBindings; } |
| 66 | QRhiShaderResourceBindings *shaderResourceBindings() const { return m_shaderResourceBindings; } |
| 67 | |
| 68 | int score() const { return m_score; } |
| 69 | void increaseScore() { m_score += 2; } |
| 70 | void decreaseScore() { --m_score; } |
| 71 | |
| 72 | bool isComplete() { return m_complete; } |
| 73 | void markComplete() { m_complete = true; } |
| 74 | |
| 75 | virtual void cleanup() |
| 76 | { |
| 77 | delete m_shaderResourceBindings; |
| 78 | delete m_pipeline; |
| 79 | m_pipeline = nullptr; |
| 80 | m_shaderResourceBindings = nullptr; |
| 81 | m_uboSet.releaseResources(); |
| 82 | m_uboSet.clear(); |
| 83 | m_key = {}; |
| 84 | m_score = 5; |
| 85 | } |
| 86 | |
| 87 | protected: |
| 88 | RHIPipelineBase() {} |
| 89 | |
| 90 | Pipeline *m_pipeline = nullptr; |
| 91 | QRhiShaderResourceBindings *m_shaderResourceBindings = nullptr; |
| 92 | // For user defined uniforms |
| 93 | PipelineUBOSet m_uboSet; |
| 94 | Key m_key = {}; |
| 95 | int m_score = 5; |
| 96 | int m_complete = false; |
| 97 | }; |
| 98 | |
| 99 | class RHIGraphicsPipeline : public RHIPipelineBase<QRhiGraphicsPipeline, GraphicsPipelineIdentifier> |
| 100 | { |
| 101 | public: |
| 102 | void setAttributesToBindingHash(const QHash<int, int> &attributeNameToBinding) |
| 103 | { |
| 104 | m_attributeNameIdToBindingIndex = attributeNameToBinding; |
| 105 | } |
| 106 | |
| 107 | int bindingIndexForAttribute(int attributeNameId) const |
| 108 | { |
| 109 | return m_attributeNameIdToBindingIndex.value(key: attributeNameId, defaultValue: -1); |
| 110 | } |
| 111 | |
| 112 | virtual void cleanup() override |
| 113 | { |
| 114 | RHIPipelineBase<QRhiGraphicsPipeline, GraphicsPipelineIdentifier>::cleanup(); |
| 115 | m_attributeNameIdToBindingIndex.clear(); |
| 116 | } |
| 117 | |
| 118 | private: |
| 119 | // For user defined uniforms |
| 120 | QHash<int, int> m_attributeNameIdToBindingIndex; |
| 121 | }; |
| 122 | |
| 123 | class RHIComputePipeline : public RHIPipelineBase<QRhiComputePipeline, ComputePipelineIdentifier> |
| 124 | { |
| 125 | }; |
| 126 | |
| 127 | } // Rhi |
| 128 | |
| 129 | } // Render |
| 130 | |
| 131 | } // Qt3DRender |
| 132 | |
| 133 | QT_END_NAMESPACE |
| 134 | |
| 135 | #endif // QT3DRENDER_RENDER_RHI_RHIGRAPHICSPIPELINE_H |
| 136 |
