• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2014 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 
7 // ShaderImpl.h: Defines the abstract rx::ShaderImpl class.
8 
9 #ifndef LIBANGLE_RENDERER_SHADERIMPL_H_
10 #define LIBANGLE_RENDERER_SHADERIMPL_H_
11 
12 #include <functional>
13 
14 #include "common/CompiledShaderState.h"
15 #include "common/WorkerThread.h"
16 #include "common/angleutils.h"
17 #include "libANGLE/Shader.h"
18 
19 namespace gl
20 {
21 class ShCompilerInstance;
22 }  // namespace gl
23 
24 namespace rx
25 {
26 // The compile task is generally just a call to the translator.  However, different backends behave
27 // differently afterwards:
28 //
29 // - The Vulkan backend which generates binary (i.e. SPIR-V), does nothing more
30 // - The backends that generate text (HLSL and MSL), do nothing at this stage, but modify the text
31 //   at link time before invoking the native compiler.  These expensive calls are handled in link
32 //   sub-tasks (see LinkSubTask in ProgramImpl.h).
33 // - The GL backend needs to invoke the native driver, which is problematic when done in another
34 //   thread (and is avoided).
35 //
36 // The call to the translator can thus be done in a separate thread or without holding the share
37 // group lock on all backends except GL.  On the GL backend, the translator call is done on the main
38 // thread followed by a call to the native driver.  If the driver supports
39 // GL_KHR_parallel_shader_compile, ANGLE still delays post-processing of the results to when
40 // compilation is done (just as if it was ANGLE itself that was doing the compilation in a thread).
41 class ShaderTranslateTask
42 {
43   public:
44     virtual ~ShaderTranslateTask() = default;
45     virtual bool translate(ShHandle compiler,
46                            const ShCompileOptions &options,
47                            const std::string &source);
postTranslate(ShHandle compiler,const gl::CompiledShaderState & compiledState)48     virtual void postTranslate(ShHandle compiler, const gl::CompiledShaderState &compiledState) {}
49 
50     // Used by the GL backend to query whether the driver is compiling in parallel internally.
isCompilingInternally()51     virtual bool isCompilingInternally() { return false; }
52     // Used by the GL backend to finish internal compilation and return results.
getResult(std::string & infoLog)53     virtual angle::Result getResult(std::string &infoLog) { return angle::Result::Continue; }
54 };
55 
56 class ShaderImpl : angle::NonCopyable
57 {
58   public:
ShaderImpl(const gl::ShaderState & state)59     ShaderImpl(const gl::ShaderState &state) : mState(state) {}
~ShaderImpl()60     virtual ~ShaderImpl() {}
61 
destroy()62     virtual void destroy() {}
63 
64     virtual std::shared_ptr<ShaderTranslateTask> compile(const gl::Context *context,
65                                                          ShCompileOptions *options) = 0;
66 
67     virtual std::string getDebugInfo() const = 0;
68 
getState()69     const gl::ShaderState &getState() const { return mState; }
70 
71     virtual angle::Result onLabelUpdate(const gl::Context *context);
72 
73   protected:
74     const gl::ShaderState &mState;
75 };
76 
77 }  // namespace rx
78 
79 #endif  // LIBANGLE_RENDERER_SHADERIMPL_H_
80