1 /*
2 * Copyright (C) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #ifndef DEVICE_SHADER_PIPELINE_BINDER_H
17 #define DEVICE_SHADER_PIPELINE_BINDER_H
18
19 #include <atomic>
20
21 #include <base/containers/array_view.h>
22 #include <base/containers/refcnt_ptr.h>
23 #include <render/device/intf_shader_pipeline_binder.h>
24 #include <render/namespace.h>
25 #include <render/resource_handle.h>
26
RENDER_BEGIN_NAMESPACE()27 RENDER_BEGIN_NAMESPACE()
28 class ShaderPipelineBinder : public IShaderPipelineBinder {
29 public:
30 ShaderPipelineBinder() = delete;
31 ShaderPipelineBinder(const RenderHandleReference& shader, const PipelineLayout& pipelineLayout);
32 ~ShaderPipelineBinder() override = default;
33
34 bool GetBindingValidity() const override;
35 RenderHandleReference GetShaderHandle() const override;
36
37 void Bind(const uint32_t set, const uint32_t binding, const RenderHandleReference& handle) override;
38 void SetUniformData(
39 const uint32_t set, const uint32_t binding, const BASE_NS::array_view<const uint8_t> data) override;
40 void SetPushConstantData(const BASE_NS::array_view<const uint8_t> data) override;
41
42 void BindBuffer(const uint32_t set, const uint32_t binding, const Buffer& handle) override;
43 void BindImage(const uint32_t set, const uint32_t binding, const Image& handle) override;
44 void BindSampler(const uint32_t set, const uint32_t binding, const Sampler& resource) override;
45
46 DescriptorSetView GetDescriptorSetView(const uint32_t set) const override;
47 BASE_NS::array_view<const uint8_t> GetPushData() const override;
48
49 protected:
50 void Ref() override;
51 void Unref() override;
52
53 private:
54 std::atomic<int32_t> refcnt_ { 0 };
55
56 RenderHandleReference shader_;
57 PipelineLayout pipelineLayout_;
58
59 // NOTE: initial version with multiple vectors per descriptor set
60 // vectors are resized in the constructor
61 struct DescriptorSetResources {
62 BASE_NS::vector<Buffer> buffers;
63 BASE_NS::vector<Image> images;
64 BASE_NS::vector<Sampler> samplers;
65
66 BASE_NS::vector<Binding> bindings;
67
68 uint8_t bindingToIndex[PipelineLayoutConstants::MAX_DESCRIPTOR_SET_BINDING_COUNT] { 16, 16, 16, 16, 16, 16, 16,
69 16, 16, 16, 16, 16, 16, 16, 16, 16 };
70 uint32_t maxBindingCount { 0u };
71 };
72 BASE_NS::vector<DescriptorSetResources> descriptorSetResources_;
73
74 BASE_NS::vector<uint8_t> pushData_;
75 };
76 RENDER_END_NAMESPACE()
77
78 #endif // DEVICE_SHADER_PIPELINE_BINDER_H
79