ShaderImpl.cpp (2773B)
1 // 2 // Copyright 2019 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.cpp: Implementation methods of ShaderImpl 8 9 #include "libANGLE/renderer/ShaderImpl.h" 10 11 #include "libANGLE/Context.h" 12 #include "libANGLE/trace.h" 13 14 namespace rx 15 { 16 17 WaitableCompileEvent::WaitableCompileEvent(std::shared_ptr<angle::WaitableEvent> waitableEvent) 18 : mWaitableEvent(waitableEvent) 19 {} 20 21 WaitableCompileEvent::~WaitableCompileEvent() 22 { 23 mWaitableEvent.reset(); 24 } 25 26 void WaitableCompileEvent::wait() 27 { 28 mWaitableEvent->wait(); 29 } 30 31 bool WaitableCompileEvent::isReady() 32 { 33 return mWaitableEvent->isReady(); 34 } 35 36 const std::string &WaitableCompileEvent::getInfoLog() 37 { 38 return mInfoLog; 39 } 40 41 class TranslateTask : public angle::Closure 42 { 43 public: 44 TranslateTask(ShHandle handle, const ShCompileOptions &options, const std::string &source) 45 : mHandle(handle), mOptions(options), mSource(source), mResult(false) 46 {} 47 48 void operator()() override 49 { 50 ANGLE_TRACE_EVENT1("gpu.angle", "TranslateTask::run", "source", mSource); 51 const char *source = mSource.c_str(); 52 mResult = sh::Compile(mHandle, &source, 1, mOptions); 53 } 54 55 bool getResult() { return mResult; } 56 57 ShHandle getHandle() { return mHandle; } 58 59 private: 60 ShHandle mHandle; 61 ShCompileOptions mOptions; 62 std::string mSource; 63 bool mResult; 64 }; 65 66 class WaitableCompileEventImpl final : public WaitableCompileEvent 67 { 68 public: 69 WaitableCompileEventImpl(std::shared_ptr<angle::WaitableEvent> waitableEvent, 70 std::shared_ptr<TranslateTask> translateTask) 71 : WaitableCompileEvent(waitableEvent), mTranslateTask(translateTask) 72 {} 73 74 bool getResult() override { return mTranslateTask->getResult(); } 75 76 bool postTranslate(std::string *infoLog) override { return true; } 77 78 private: 79 std::shared_ptr<TranslateTask> mTranslateTask; 80 }; 81 82 std::shared_ptr<WaitableCompileEvent> ShaderImpl::compileImpl( 83 const gl::Context *context, 84 gl::ShCompilerInstance *compilerInstance, 85 const std::string &source, 86 ShCompileOptions *compileOptions) 87 { 88 #if defined(ANGLE_ENABLE_ASSERTS) 89 compileOptions->validateAST = true; 90 #endif 91 92 auto workerThreadPool = context->getShaderCompileThreadPool(); 93 auto translateTask = 94 std::make_shared<TranslateTask>(compilerInstance->getHandle(), *compileOptions, source); 95 96 return std::make_shared<WaitableCompileEventImpl>( 97 angle::WorkerThreadPool::PostWorkerTask(workerThreadPool, translateTask), translateTask); 98 } 99 100 angle::Result ShaderImpl::onLabelUpdate(const gl::Context *context) 101 { 102 return angle::Result::Continue; 103 } 104 105 } // namespace rx