• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 The Amber Authors.
2 // Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef AMBER_SHADER_INFO_H_
17 #define AMBER_SHADER_INFO_H_
18 
19 #include <cstdint>
20 #include <string>
21 #include <vector>
22 
23 namespace amber {
24 
25 enum ShaderFormat {
26   kShaderFormatDefault = 0,
27   kShaderFormatText,
28   kShaderFormatGlsl,
29   kShaderFormatHlsl,
30   kShaderFormatSpirvAsm,
31   kShaderFormatSpirvHex,
32   kShaderFormatSpirvBin,
33   kShaderFormatOpenCLC,
34 };
35 
36 enum ShaderType {
37   kShaderTypeCompute = 0,
38   kShaderTypeGeometry,
39   kShaderTypeFragment,
40   kShaderTypeVertex,
41   kShaderTypeTessellationControl,
42   kShaderTypeTessellationEvaluation,
43   kShaderTypeRayGeneration,
44   kShaderTypeAnyHit,
45   kShaderTypeClosestHit,
46   kShaderTypeMiss,
47   kShaderTypeIntersection,
48   kShaderTypeCall,
49   kShaderTypeMulti,
50 };
51 
isRayTracingShaderType(ShaderType type)52 inline bool isRayTracingShaderType(ShaderType type) {
53   return type == kShaderTypeRayGeneration || type == kShaderTypeAnyHit ||
54          type == kShaderTypeClosestHit || type == kShaderTypeMiss ||
55          type == kShaderTypeIntersection || type == kShaderTypeCall;
56 }
57 
58 /// Stores information for a shader.
59 struct ShaderInfo {
60   /// The format of the shader.
61   ShaderFormat format;
62   /// The type of shader.
63   ShaderType type;
64   /// This is a unique name for this shader. The name is produced from the
65   /// input script, possibly with extra prefix contents. This name, if used
66   /// in the ShaderMap will map to this specific shader.
67   std::string shader_name;
68   /// This is the shader source, the source is in the |format| given above.
69   std::string shader_source;
70   /// A list of SPIR-V optimization passes to execute on the shader.
71   std::vector<std::string> optimizations;
72   /// Target environment for the shader compilation.
73   std::string target_env;
74   /// The shader SPIR-V if it was compiled by Amber
75   std::vector<uint32_t> shader_data;
76 };
77 
78 }  // namespace amber
79 
80 #endif  // AMBER_SHADER_INFO_H_
81