Add clean_func_name() to support overrides to function names.
This commit is contained in:
parent
e6dab816b0
commit
4a6358bb9f
@ -2710,6 +2710,15 @@ string CompilerGLSL::to_function_args(uint32_t img, const SPIRType &, bool, bool
|
||||
return farg_str;
|
||||
}
|
||||
|
||||
// Some languages may have additional standard library functions whose names conflict
|
||||
// with a function defined in the body of the shader. Subclasses can override to rename
|
||||
// the function name defined in the shader to avoid conflict with the language standard
|
||||
// functions (eg. MSL includes saturate()).
|
||||
string CompilerGLSL::clean_func_name(string func_name)
|
||||
{
|
||||
return func_name;
|
||||
}
|
||||
|
||||
void CompilerGLSL::emit_glsl_op(uint32_t result_type, uint32_t id, uint32_t eop, const uint32_t *args, uint32_t)
|
||||
{
|
||||
GLSLstd450 op = static_cast<GLSLstd450>(eop);
|
||||
@ -3638,7 +3647,7 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
|
||||
|
||||
string funexpr;
|
||||
vector<string> arglist;
|
||||
funexpr += to_name(func) + "(";
|
||||
funexpr += clean_func_name(to_name(func)) + "(";
|
||||
for (uint32_t i = 0; i < length; i++)
|
||||
{
|
||||
// Do not pass in separate images or samplers if we're remapping
|
||||
@ -5359,11 +5368,11 @@ void CompilerGLSL::emit_function_prototype(SPIRFunction &func, uint64_t return_f
|
||||
|
||||
if (func.self == entry_point)
|
||||
{
|
||||
decl += "main";
|
||||
decl += clean_func_name("main");
|
||||
processing_entry_point = true;
|
||||
}
|
||||
else
|
||||
decl += to_name(func.self);
|
||||
decl += clean_func_name(to_name(func.self));
|
||||
|
||||
decl += "(";
|
||||
vector<string> arglist;
|
||||
|
@ -168,6 +168,7 @@ protected:
|
||||
uint32_t grad_x, uint32_t grad_y, uint32_t lod, uint32_t coffset,
|
||||
uint32_t offset, uint32_t bias, uint32_t comp, uint32_t sample,
|
||||
bool *p_forward);
|
||||
virtual std::string clean_func_name(std::string func_name);
|
||||
|
||||
std::unique_ptr<std::ostringstream> buffer;
|
||||
|
||||
|
@ -27,6 +27,15 @@ CompilerMSL::CompilerMSL(vector<uint32_t> spirv_)
|
||||
: CompilerGLSL(move(spirv_))
|
||||
{
|
||||
options.vertex.fixup_clipspace = false;
|
||||
|
||||
populate_func_name_overrides();
|
||||
}
|
||||
|
||||
// Populate the collection of function names that need to be overridden
|
||||
void CompilerMSL::populate_func_name_overrides()
|
||||
{
|
||||
func_name_overrides["main"] = "main0";
|
||||
func_name_overrides["saturate"] = "saturate0";
|
||||
}
|
||||
|
||||
string CompilerMSL::compile(MSLConfiguration &msl_cfg, vector<MSLVertexAttr> *p_vtx_attrs,
|
||||
@ -1203,8 +1212,8 @@ string CompilerMSL::func_type_decl(SPIRType &type)
|
||||
// Ensures the function name is not "main", which is illegal in MSL
|
||||
string CompilerMSL::clean_func_name(string func_name)
|
||||
{
|
||||
static std::string _clean_msl_main_func_name = "mmain";
|
||||
return (func_name == "main") ? _clean_msl_main_func_name : func_name;
|
||||
auto iter = func_name_overrides.find(func_name);
|
||||
return (iter != func_name_overrides.end()) ? iter->second : func_name;
|
||||
}
|
||||
|
||||
// Returns a string containing a comma-delimited list of args for the entry point function
|
||||
|
@ -115,6 +115,7 @@ protected:
|
||||
uint32_t coord, uint32_t coord_components, uint32_t dref, uint32_t grad_x,
|
||||
uint32_t grad_y, uint32_t lod, uint32_t coffset, uint32_t offset, uint32_t bias,
|
||||
uint32_t comp, uint32_t sample, bool *p_forward) override;
|
||||
std::string clean_func_name(std::string func_name) override;
|
||||
|
||||
void register_custom_functions();
|
||||
void emit_custom_functions();
|
||||
@ -129,9 +130,9 @@ protected:
|
||||
void emit_interface_block(uint32_t ib_var_id);
|
||||
void emit_function_prototype(SPIRFunction &func, bool is_decl);
|
||||
void emit_function_declarations();
|
||||
void populate_func_name_overrides();
|
||||
|
||||
std::string func_type_decl(SPIRType &type);
|
||||
std::string clean_func_name(std::string func_name);
|
||||
std::string entry_point_args(bool append_comma);
|
||||
std::string get_entry_point_name();
|
||||
std::string to_qualified_member_name(const SPIRType &type, uint32_t index);
|
||||
@ -148,6 +149,7 @@ protected:
|
||||
std::string to_component_argument(uint32_t id);
|
||||
|
||||
MSLConfiguration msl_config;
|
||||
std::unordered_map<std::string,std::string> func_name_overrides;
|
||||
std::set<uint32_t> custom_function_ops;
|
||||
std::unordered_map<uint32_t, MSLVertexAttr *> vtx_attrs_by_location;
|
||||
std::vector<MSLResourceBinding *> resource_bindings;
|
||||
|
Loading…
Reference in New Issue
Block a user