• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 LOADER_SHADER_STATE_LOADER_H
17 #define LOADER_SHADER_STATE_LOADER_H
18 
19 #include <base/containers/string.h>
20 #include <base/containers/vector.h>
21 #include <base/util/uid.h>
22 #include <core/namespace.h>
23 #include <render/device/pipeline_state_desc.h>
24 #include <render/namespace.h>
25 
26 CORE_BEGIN_NAMESPACE()
27 class IFileManager;
28 CORE_END_NAMESPACE()
29 RENDER_BEGIN_NAMESPACE()
30 
31 struct ShaderStateLoaderVariantData {
32     BASE_NS::string renderSlot;
33     BASE_NS::string variantName;
34 
35     BASE_NS::string baseShaderState;
36     BASE_NS::string baseVariantName;
37 
38     bool renderSlotDefaultState { false };
39 };
40 
41 /** Shader state loader.
42  * A class that can be used to load shader (graphics) state data from a json.
43  */
44 class ShaderStateLoader final {
45 public:
46     /** Describes result of the parsing operation. */
47     struct LoadResult {
48         LoadResult() = default;
LoadResultLoadResult49         explicit LoadResult(const BASE_NS::string& aError) : success(false), error(aError) {}
50 
51         /** Indicates, whether the parsing operation is successful. */
52         bool success { true };
53 
54         /** In case of parsing error, contains the description of the error. */
55         BASE_NS::string error;
56     };
57 
58     struct GraphicsStates {
59         BASE_NS::vector<GraphicsState> states;
60         BASE_NS::vector<ShaderStateLoaderVariantData> variantData;
61     };
62 
63     /** Retrieve uri of shader state.
64      * @return String view to uri of shader state.
65      */
66     BASE_NS::string_view GetUri() const;
67 
68     /** Retrieve graphics state variant names.
69      * @return Graphics state variant names, as defined in the json file.
70      */
71     BASE_NS::array_view<const ShaderStateLoaderVariantData> GetGraphicsStateVariantData() const;
72 
73     /** Retrieve graphics states.
74      * @return Graphics states, as defined in the json file.
75      */
76     BASE_NS::array_view<const GraphicsState> GetGraphicsStates() const;
77 
78     /** Loads shader state from given uri, using file manager.
79      * @param fileManager A file manager to access the file in given uri.
80      * @param uri Uri to json file.
81      * @return A structure containing result for the parsing operation.
82      */
83     LoadResult Load(CORE_NS::IFileManager& fileManager, BASE_NS::string_view uri);
84 
85 private:
86     BASE_NS::string uri_;
87     BASE_NS::vector<GraphicsState> graphicsStates_;
88     BASE_NS::vector<ShaderStateLoaderVariantData> graphicsStateVariantData_;
89 };
90 RENDER_END_NAMESPACE()
91 
92 #endif // LOADER_SHADER_STATE_LOADER_H
93