HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VE_ShaderCompile.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: VE_ShaderCompile.h ( VE Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __VE_SHADER_COMPILE_H__
12 #define __VE_SHADER_COMPILE_H__
13 
14 #include "VE_API.h"
15 
16 #include <UT/UT_Array.h>
17 #include <UT/UT_Map.h>
18 #include <UT/UT_StringHolder.h>
19 #include <UT/UT_UniquePtr.h>
20 
21 class UT_WorkBuffer;
22 struct VE_SpvProgramCompileImpl;
23 struct VE_SpvStageCompileImpl;
25 
26 // Values of this enum must be in sync with RE_ShaderType!
28 {
34 
36 
37  // RE_SHADER_ALL isn't an actual stage, so we don't need a corresponding
38  // value here.
39 };
40 
41 // ~~ Overview
42 // takes a collection of GLSL shader files
43 // compiles them into SPIR-V modules
44 // optionally does linkage checks as well
45 
46 // ~~ Shader Compiler Ownership
47 // Implemented using glslang library
48 // glslang interface has the quirks that:
49 // - shaders cannot be detatched from a program
50 // - shaders cannot be used in multiple programs
51 // - shaders must be destroyed after program
52 // so, the program compiler takes ownership of any shaders
53 // added to it
54 
56 {
57 public:
60 
62 
63  // Must be called in order:
64  // add shaders, compile, link, get modules
65  bool addShader(UT_UniquePtr<VE_ShaderStageCompiler>&& shr);
66  bool compileShaders(UT_WorkBuffer& messages_out);
67  bool linkShaders(UT_WorkBuffer& messages_out);
68  // T can be uint8_t or uint32_t.
69  template <typename T>
70  bool getSpvModules(UT_Map<VE_ShaderType, UT_Array<T>>& modules_out,
71  UT_WorkBuffer& messages_out);
72 
73  bool isValid() const;
74 
75 private:
77  friend VE_SpvProgramCompileImpl;
78 };
79 
81 {
82 public:
83  VE_ShaderStageCompiler(const char* source, const char* name,
84  VE_ShaderType stage, int version = 0);
86 
87  bool compile(UT_WorkBuffer& messages_out);
88 
89  bool isCompiled();
90  bool isValid();
91 
92  VE_ShaderType getStageType();
93  void getString(UT_WorkBuffer& string);
94  const char* getname()
95  {
96  return myName;
97  }
98 
99 private:
100  UT_StringHolder myName;
101  UT_StringHolder mySource;
102  VE_ShaderType myStage;
104  int myVersion;
105 
106  friend VE_SpvStageCompileImpl;
108 };
109 
110 #endif
111 
Unsorted map container.
Definition: UT_Map.h:109
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
VE_ShaderType
#define VE_API
Definition: VE_API.h:20
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
GLuint const GLchar * name
Definition: glcorearb.h:786
GT_API const UT_StringHolder version