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