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
23QT_BEGIN_NAMESPACE
24
25namespace Qt3DRender {
26
27namespace Render {
28
29class ShaderData;
30class NodeManagers;
31
32namespace Rhi {
33
34class RHIShader;
35class RHIBuffer;
36class RenderCommand;
37class SubmissionContext;
38class RenderView;
39class RHIResourceManagers;
40
41class PipelineUBOSet
42{
43public:
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
82private:
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
113QT_END_NAMESPACE
114
115#endif // QT3DRENDER_RENDER_RHI_PIPELINEUBOSET_H
116

source code of qt3d/src/plugins/renderers/rhi/renderer/pipelineuboset_p.h