1 //
2 // Copyright (c) 2016 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // HLSLCompiler: Wrapper for the D3DCompiler DLL.
7 //
8 
9 #ifndef LIBANGLE_RENDERER_D3D_HLSLCOMPILER_H_
10 #define LIBANGLE_RENDERER_D3D_HLSLCOMPILER_H_
11 
12 #include "libANGLE/Error.h"
13 
14 #include "common/angleutils.h"
15 #include "common/platform.h"
16 
17 #include <vector>
18 #include <string>
19 
20 namespace gl
21 {
22 class InfoLog;
23 }
24 
25 namespace rx
26 {
27 
28 struct CompileConfig
29 {
30     UINT flags;
31     std::string name;
32 
33     CompileConfig();
34     CompileConfig(UINT flags, const std::string &name);
35 };
36 
37 class HLSLCompiler : angle::NonCopyable
38 {
39   public:
40     HLSLCompiler();
41     ~HLSLCompiler();
42 
43     void release();
44 
45     // Attempt to compile a HLSL shader using the supplied configurations, may output a NULL compiled blob
46     // even if no GL errors are returned.
47     gl::Error compileToBinary(gl::InfoLog &infoLog, const std::string &hlsl, const std::string &profile,
48                               const std::vector<CompileConfig> &configs, const D3D_SHADER_MACRO *overrideMacros,
49                               ID3DBlob **outCompiledBlob, std::string *outDebugInfo);
50 
51     gl::Error disassembleBinary(ID3DBlob *shaderBinary, std::string *disassemblyOut);
52     gl::Error ensureInitialized();
53 
54   private:
55 
56     bool mInitialized;
57     HMODULE mD3DCompilerModule;
58     pD3DCompile mD3DCompileFunc;
59     pD3DDisassemble mD3DDisassembleFunc;
60 };
61 
62 }
63 
64 #endif  // LIBANGLE_RENDERER_D3D_HLSLCOMPILER_H_
65