1 /*
2  * Copyright (c) 2024 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_GPU_PROGRAM_UTIL_H
17 #define DEVICE_GPU_PROGRAM_UTIL_H
18 
19 #include <cstdint>
20 
21 #include <base/containers/vector.h>
22 #include <base/math/vector.h>
23 #include <base/util/formats.h>
24 #include <render/device/pipeline_layout_desc.h>
25 #include <render/device/pipeline_state_desc.h>
26 #include <render/namespace.h>
27 
RENDER_BEGIN_NAMESPACE()28 RENDER_BEGIN_NAMESPACE()
29 namespace GpuProgramUtil {
30 uint32_t SpecializationByteSize(RENDER_NS::ShaderSpecialization::Constant::Type type);
31 
32 void AddSpecializationConstants(
33     const BASE_NS::array_view<const ShaderSpecialization::Constant> inSpecializationConstants,
34     BASE_NS::vector<ShaderSpecialization::Constant>& outSpecializationConstants);
35 // has sorting for constants
36 void CombineSpecializationConstants(const BASE_NS::array_view<const ShaderSpecialization::Constant> inSc,
37     BASE_NS::vector<ShaderSpecialization::Constant>& outSc);
38 
39 // returns true if combination of descriptor sets is valid
40 [[nodiscard]] bool AddBindings(
41     const DescriptorSetLayout& inDescriptorSetLayout, DescriptorSetLayout& outDescriptorSetLayout);
42 // has sorting for bindings and sets
43 void CombinePipelineLayouts(const BASE_NS::array_view<const PipelineLayout> inPl, PipelineLayout& outPl);
44 
45 uint32_t FormatByteSize(BASE_NS::Format format);
46 } // namespace GpuProgramUtil
47 RENDER_END_NAMESPACE()
48 
49 #endif // DEVICE_GPU_PROGRAM_UTIL_H
50