• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 LOADER_SHADER_DATA_LOADER_H
17 #define LOADER_SHADER_DATA_LOADER_H
18 
19 #include <utility>
20 
21 #include <base/containers/string.h>
22 #include <base/containers/string_view.h>
23 #include <base/containers/vector.h>
24 #include <core/namespace.h>
25 #include <render/device/intf_shader_manager.h>
26 #include <render/device/pipeline_state_desc.h>
27 #include <render/namespace.h>
28 
29 CORE_BEGIN_NAMESPACE()
30 class IFileManager;
31 CORE_END_NAMESPACE()
RENDER_BEGIN_NAMESPACE()32 RENDER_BEGIN_NAMESPACE()
33 
34 /** Shader data loader.
35  * A class that can be used to load all shader related data from shader json structure.
36  */
37 class ShaderDataLoader final {
38 public:
39     /** Describes result of the parsing operation. */
40     struct LoadResult {
41         LoadResult() = default;
42         explicit LoadResult(BASE_NS::string error) : success(false), error(BASE_NS::move(error)) {}
43 
44         /** Indicates, whether the parsing operation is successful. */
45         bool success { true };
46 
47         /** In case of parsing error, contains the description of the error. */
48         BASE_NS::string error;
49     };
50 
51     /** Uri of the loaded file.
52      * @return Uri path.
53      */
54     BASE_NS::string_view GetUri() const;
55 
56     /** Base category for all shader variants.
57      * @return Base category for shaders.
58      */
59     BASE_NS::string_view GetBaseCategory() const;
60 
61     /** Get all shader variants.
62      * @return Array view of shader variants.
63      */
64     BASE_NS::array_view<const IShaderManager::ShaderVariant> GetShaderVariants() const;
65 
66     /** Loads shader state from given uri, using file manager.
67      * @param fileManager A file manager to access the file in given uri.
68      * @param uri Uri to json file.
69      * @return A structure containing result for the parsing operation.
70      */
71     LoadResult Load(CORE_NS::IFileManager& fileManager, BASE_NS::string_view uri);
72 
73 private:
74     LoadResult Load(BASE_NS::string_view uri, BASE_NS::string&& jsonData);
75 
76     BASE_NS::string uri_;
77     BASE_NS::string baseCategory_;
78 
79     BASE_NS::vector<IShaderManager::ShaderVariant> shaderVariants_;
80 };
81 CORE_END_NAMESPACE()
82 
83 #endif // LOADER_SHADER_DATA_LOADER_H
84