Hash :
9b63700b
Author :
Date :
2023-07-11T10:25:40
Translator: Reorganize files This change makes the translator files more organized by: - Grouping files that are specific to a certain output under their own directory, - Moving transformations under tree_ops - Removing Direct from metal translation now that that SPIR-V Cross path is removed Bug: angleproject:6394 Change-Id: Iaf5bb8d5604b84748dece029821b1f77b2813967 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4678780 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
//
// Copyright 2019 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// ShaderMtl.mm:
// Implements the class methods for ShaderMtl.
//
#include "libANGLE/renderer/metal/ShaderMtl.h"
#include "common/WorkerThread.h"
#include "common/debug.h"
#include "libANGLE/Context.h"
#include "libANGLE/Shader.h"
#include "libANGLE/renderer/metal/ContextMtl.h"
#include "libANGLE/renderer/metal/DisplayMtl.h"
#include "libANGLE/trace.h"
namespace rx
{
ShaderMtl::ShaderMtl(const gl::ShaderState &state) : ShaderImpl(state) {}
ShaderMtl::~ShaderMtl() {}
class TranslateTask : public angle::Closure
{
public:
TranslateTask(ShHandle handle, const ShCompileOptions &options, const std::string &source)
: mHandle(handle), mOptions(options), mSource(source), mResult(false)
{}
void operator()() override
{
ANGLE_TRACE_EVENT1("gpu.angle", "TranslateTaskMetal::run", "source", mSource);
const char *source = mSource.c_str();
mResult = sh::Compile(mHandle, &source, 1, mOptions);
}
bool getResult() { return mResult; }
ShHandle getHandle() { return mHandle; }
private:
ShHandle mHandle;
ShCompileOptions mOptions;
std::string mSource;
bool mResult;
};
class MTLWaitableCompileEventImpl final : public WaitableCompileEvent
{
public:
MTLWaitableCompileEventImpl(ShaderMtl *shader,
std::shared_ptr<angle::WaitableEvent> waitableEvent,
std::shared_ptr<TranslateTask> translateTask)
: WaitableCompileEvent(waitableEvent), mTranslateTask(translateTask), mShader(shader)
{}
bool getResult() override { return mTranslateTask->getResult(); }
bool postTranslate(std::string *infoLog) override
{
sh::TShHandleBase *base = static_cast<sh::TShHandleBase *>(mTranslateTask->getHandle());
auto translatorMetalDirect = base->getAsTranslatorMSL();
if (translatorMetalDirect != nullptr)
{
// Copy reflection from translation.
mShader->translatorMetalReflection =
*(translatorMetalDirect->getTranslatorMetalReflection());
translatorMetalDirect->getTranslatorMetalReflection()->reset();
}
return true;
}
private:
std::shared_ptr<TranslateTask> mTranslateTask;
ShaderMtl *mShader;
};
std::shared_ptr<WaitableCompileEvent> ShaderMtl::compileImplMtl(
const gl::Context *context,
gl::ShCompilerInstance *compilerInstance,
const std::string &source,
ShCompileOptions *compileOptions)
{
// TODO(jcunningham): Remove this workaround once correct fix to move validation to the very end is
// in place. See: https://bugs.webkit.org/show_bug.cgi?id=224991
#if defined(ANGLE_ENABLE_ASSERTS) && 0
compileOptions->validateAst = true;
#endif
auto workerThreadPool = context->getWorkerThreadPool();
auto translateTask =
std::make_shared<TranslateTask>(compilerInstance->getHandle(), *compileOptions, source);
return std::make_shared<MTLWaitableCompileEventImpl>(
this, workerThreadPool->postWorkerTask(translateTask), translateTask);
}
std::shared_ptr<WaitableCompileEvent> ShaderMtl::compile(const gl::Context *context,
gl::ShCompilerInstance *compilerInstance,
ShCompileOptions *options)
{
ContextMtl *contextMtl = mtl::GetImpl(context);
DisplayMtl *displayMtl = contextMtl->getDisplay();
options->initializeUninitializedLocals = true;
if (context->isWebGL() && mState.getShaderType() != gl::ShaderType::Compute)
{
options->initOutputVariables = true;
}
options->metal.generateShareableShaders =
displayMtl->getFeatures().generateShareableShaders.enabled;
if (displayMtl->getFeatures().intelExplicitBoolCastWorkaround.enabled ||
options->metal.generateShareableShaders)
{
options->addExplicitBoolCasts = true;
}
options->clampPointSize = true;
#if ANGLE_PLATFORM_IOS_FAMILY && !ANGLE_PLATFORM_MACCATALYST
options->clampFragDepth = true;
#endif
if (displayMtl->getFeatures().emulateAlphaToCoverage.enabled)
{
options->emulateAlphaToCoverage = true;
}
// Constants:
options->metal.driverUniformsBindingIndex = mtl::kDriverUniformsBindingIndex;
options->metal.defaultUniformsBindingIndex = mtl::kDefaultUniformsBindingIndex;
options->metal.UBOArgumentBufferBindingIndex = mtl::kUBOArgumentBufferBindingIndex;
// GL_ANGLE_shader_pixel_local_storage.
if (displayMtl->getNativeExtensions().shaderPixelLocalStorageANGLE)
{
options->pls = displayMtl->getNativePixelLocalStorageOptions();
}
return compileImplMtl(context, compilerInstance, getState().getSource(), options);
}
std::string ShaderMtl::getDebugInfo() const
{
std::string debugInfo = mState.getTranslatedSource();
if (debugInfo.empty())
{
return mState.getCompiledBinary().empty() ? "" : "<binary blob>";
}
return debugInfo;
}
} // namespace rx