Path: blob/main_old/src/compiler/translator/BuiltInFunctionEmulator.h
1693 views
//1// Copyright 2011 The ANGLE Project Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4//56#ifndef COMPILER_TRANSLATOR_BUILTINFUNCTIONEMULATOR_H_7#define COMPILER_TRANSLATOR_BUILTINFUNCTIONEMULATOR_H_89#include "compiler/translator/InfoSink.h"1011namespace sh12{1314class TIntermNode;15class TFunction;16class TSymbolUniqueId;1718using BuiltinQueryFunc = const char *(int);1920//21// This class decides which built-in functions need to be replaced with the emulated ones. It can be22// used to work around driver bugs or implement functions that are not natively implemented on a23// specific platform.24//25class BuiltInFunctionEmulator26{27public:28BuiltInFunctionEmulator();2930void markBuiltInFunctionsForEmulation(TIntermNode *root);3132void cleanup();3334// "name" gets written as "name_emu".35static void WriteEmulatedFunctionName(TInfoSinkBase &out, const char *name);3637bool isOutputEmpty() const;3839// Output function emulation definition. This should be before any other shader source.40void outputEmulatedFunctions(TInfoSinkBase &out) const;4142// Add functions that need to be emulated.43void addEmulatedFunction(const TSymbolUniqueId &uniqueId,44const char *emulatedFunctionDefinition);4546void addEmulatedFunctionWithDependency(const TSymbolUniqueId &dependency,47const TSymbolUniqueId &uniqueId,48const char *emulatedFunctionDefinition);4950void addFunctionMap(BuiltinQueryFunc queryFunc);5152private:53class BuiltInFunctionEmulationMarker;5455// Records that a function is called by the shader and might need to be emulated. If the56// function is not in mEmulatedFunctions, this becomes a no-op. Returns true if the function57// call needs to be replaced with an emulated one.58bool setFunctionCalled(const TFunction *function);59bool setFunctionCalled(int uniqueId);6061const char *findEmulatedFunction(int uniqueId) const;6263// Map from function unique id to emulated function definition64std::map<int, std::string> mEmulatedFunctions;6566// Map from dependent functions to their dependencies. This structure allows each function to67// have at most one dependency.68std::map<int, int> mFunctionDependencies;6970// Called function ids71std::vector<int> mFunctions;7273// Constexpr function tables.74std::vector<BuiltinQueryFunc *> mQueryFunctions;75};7677} // namespace sh7879#endif // COMPILER_TRANSLATOR_BUILTINFUNCTIONEMULATOR_H_808182