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_PIPELINEUBOSET_H |
5 | #define QT3DRENDER_RENDER_RHI_PIPELINEUBOSET_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 <rhihandle_types_p.h> |
19 | #include <rhi/qrhi.h> |
20 | #include <shadervariables_p.h> |
21 | #include <rhishader_p.h> |
22 | |
23 | QT_BEGIN_NAMESPACE |
24 | |
25 | namespace Qt3DRender { |
26 | |
27 | namespace Render { |
28 | |
29 | class ShaderData; |
30 | class NodeManagers; |
31 | |
32 | namespace Rhi { |
33 | |
34 | class RHIShader; |
35 | class RHIBuffer; |
36 | class RenderCommand; |
37 | class SubmissionContext; |
38 | class RenderView; |
39 | class RHIResourceManagers; |
40 | |
41 | class PipelineUBOSet |
42 | { |
43 | public: |
44 | struct UBOBufferWithBindingAndBlockSize |
45 | { |
46 | int binding = -1; |
47 | int blockSize = -1; |
48 | size_t alignedBlockSize = 0; |
49 | HRHIBuffer buffer; |
50 | }; |
51 | |
52 | struct MultiUBOBufferWithBindingAndBlockSize |
53 | { |
54 | int binding = -1; |
55 | int blockSize = -1; |
56 | size_t alignedBlockSize = 0; |
57 | size_t alignment = 0; |
58 | size_t commandsPerUBO = 0; |
59 | std::vector<HRHIBuffer> buffers; |
60 | |
61 | HRHIBuffer bufferForCommand(size_t distanceToCommand) const; |
62 | size_t localOffsetInBufferForCommand(size_t distanceToCommand) const; |
63 | }; |
64 | |
65 | PipelineUBOSet(); |
66 | ~PipelineUBOSet(); |
67 | |
68 | void clear(); |
69 | void addRenderCommand(const RenderCommand &cmd); |
70 | |
71 | size_t distanceToCommand(const RenderCommand &command) const; |
72 | std::vector<QRhiCommandBuffer::DynamicOffset> offsets(const RenderCommand &command) const; |
73 | std::vector<QRhiShaderResourceBinding> resourceLayout(const RHIShader *shader); |
74 | std::vector<QRhiShaderResourceBinding> resourceBindings(const RenderCommand &command); |
75 | |
76 | bool allocateUBOs(SubmissionContext *ctx); |
77 | void uploadUBOs(SubmissionContext *ctx, RenderView *rv); |
78 | void setResourceManager(RHIResourceManagers *managers); |
79 | void setNodeManagers(NodeManagers *manager); |
80 | void initializeLayout(SubmissionContext *ctx, RHIShader *shader); |
81 | |
82 | private: |
83 | void releaseResources(); |
84 | void uploadUBOsForCommand(const RenderCommand &command, |
85 | size_t distanceToCommand); |
86 | void uploadShaderDataProperty(const ShaderData *shaderData, |
87 | const PipelineUBOSet::MultiUBOBufferWithBindingAndBlockSize *ubo, |
88 | const RHIShader::UBO_Member &uboMemberInstance, |
89 | size_t distanceToCommand, int arrayOffset = 0); |
90 | |
91 | UBOBufferWithBindingAndBlockSize m_rvUBO; // Fixed size |
92 | MultiUBOBufferWithBindingAndBlockSize m_commandsUBO; // Variable size |
93 | std::vector<MultiUBOBufferWithBindingAndBlockSize> m_materialsUBOs; // Variable size |
94 | std::vector<ShaderStorageBlock> m_storageBlocks; // Fixed size |
95 | |
96 | // TO DO: We also need to handle cases where UBO was directly provided by the frontend |
97 | // API and is not built up from Parameters |
98 | std::vector<const RenderCommand *> m_renderCommands; |
99 | RHIResourceManagers *m_resourceManagers = nullptr; |
100 | NodeManagers *m_nodeManagers = nullptr; |
101 | |
102 | template<typename Pipeline, typename Key> |
103 | friend class RHIPipelineBase; |
104 | }; |
105 | |
106 | |
107 | } // Rhi |
108 | |
109 | } // Render |
110 | |
111 | } // Qt3DRender |
112 | |
113 | QT_END_NAMESPACE |
114 | |
115 | #endif // QT3DRENDER_RENDER_RHI_PIPELINEUBOSET_H |
116 |