Format code
This commit is contained in:
parent
fe5de5e03c
commit
a778c363e1
@ -2388,8 +2388,10 @@ SPIREntryPoint &Compiler::get_entry_point()
|
||||
bool Compiler::interface_variable_exists_in_entry_point(uint32_t id) const
|
||||
{
|
||||
auto &var = get<SPIRVariable>(id);
|
||||
if (var.storage != StorageClassInput && var.storage != StorageClassOutput && var.storage != StorageClassUniformConstant)
|
||||
throw CompilerError("Only Input, Output variables and Uniform constants are part of a shader linking interface.");
|
||||
if (var.storage != StorageClassInput && var.storage != StorageClassOutput &&
|
||||
var.storage != StorageClassUniformConstant)
|
||||
throw CompilerError(
|
||||
"Only Input, Output variables and Uniform constants are part of a shader linking interface.");
|
||||
|
||||
// This is to avoid potential problems with very old glslang versions which did
|
||||
// not emit input/output interfaces properly.
|
||||
|
@ -158,7 +158,8 @@ void CompilerMSL::extract_global_variables_from_functions()
|
||||
{
|
||||
auto &var = id.get<SPIRVariable>();
|
||||
if (var.storage == StorageClassInput || var.storage == StorageClassUniform ||
|
||||
var.storage == StorageClassUniformConstant || var.storage == StorageClassPushConstant) {
|
||||
var.storage == StorageClassUniformConstant || var.storage == StorageClassPushConstant)
|
||||
{
|
||||
global_var_ids.insert(var.self);
|
||||
}
|
||||
}
|
||||
@ -177,7 +178,8 @@ void CompilerMSL::extract_global_variables_from_function(uint32_t func_id, std::
|
||||
std::unordered_set<uint32_t> &processed_func_ids)
|
||||
{
|
||||
// Avoid processing a function more than once
|
||||
if (processed_func_ids.find(func_id) != processed_func_ids.end()) {
|
||||
if (processed_func_ids.find(func_id) != processed_func_ids.end())
|
||||
{
|
||||
// Return function global variables
|
||||
added_arg_ids = function_global_vars[func_id];
|
||||
return;
|
||||
@ -328,7 +330,6 @@ uint32_t CompilerMSL::add_interface_block(StorageClass storage)
|
||||
ib_var_ref = stage_uniform_var_name;
|
||||
}
|
||||
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -375,9 +376,11 @@ uint32_t CompilerMSL::add_interface_block(StorageClass storage)
|
||||
mbr_idx++;
|
||||
}
|
||||
}
|
||||
else if (type.basetype == SPIRType::Boolean || type.basetype == SPIRType::Char || type.basetype == SPIRType::Int ||
|
||||
type.basetype == SPIRType::UInt || type.basetype == SPIRType::Int64 || type.basetype == SPIRType::UInt64 ||
|
||||
type.basetype == SPIRType::Float || type.basetype == SPIRType::Double || type.basetype == SPIRType::Boolean)
|
||||
else if (type.basetype == SPIRType::Boolean || type.basetype == SPIRType::Char ||
|
||||
type.basetype == SPIRType::Int || type.basetype == SPIRType::UInt ||
|
||||
type.basetype == SPIRType::Int64 || type.basetype == SPIRType::UInt64 ||
|
||||
type.basetype == SPIRType::Float || type.basetype == SPIRType::Double ||
|
||||
type.basetype == SPIRType::Boolean)
|
||||
{
|
||||
// Add a reference to the variable type to the interface struct.
|
||||
uint32_t ib_mbr_idx = uint32_t(ib_type.member_types.size());
|
||||
@ -394,7 +397,8 @@ uint32_t CompilerMSL::add_interface_block(StorageClass storage)
|
||||
// Copy the variable location from the original variable to the member
|
||||
auto &dec = meta[p_var->self].decoration;
|
||||
uint32_t locn = dec.location;
|
||||
if (is_decoration_set(p_var->self, DecorationLocation)) {
|
||||
if (is_decoration_set(p_var->self, DecorationLocation))
|
||||
{
|
||||
set_member_decoration(ib_type.self, ib_mbr_idx, DecorationLocation, locn);
|
||||
}
|
||||
mark_location_as_used_by_shader(locn, storage);
|
||||
@ -421,7 +425,8 @@ uint32_t CompilerMSL::add_interface_block(StorageClass storage)
|
||||
// Sort input or output variables alphabetical
|
||||
auto &execution = get_entry_point();
|
||||
if ((execution.model == ExecutionModelFragment && storage == StorageClassInput) ||
|
||||
(execution.model == ExecutionModelVertex && storage == StorageClassOutput)) {
|
||||
(execution.model == ExecutionModelVertex && storage == StorageClassOutput))
|
||||
{
|
||||
MemberSorter memberSorter(ib_type, meta[ib_type.self], MemberSorter::Alphabetical);
|
||||
memberSorter.sort();
|
||||
}
|
||||
@ -666,9 +671,11 @@ void CompilerMSL::emit_function_declarations()
|
||||
if (id.get_type() == TypeFunction)
|
||||
{
|
||||
auto &func = id.get<SPIRFunction>();
|
||||
if (func.self != entry_point) {
|
||||
if (func.self != entry_point)
|
||||
{
|
||||
auto &dec = meta[func.self].decoration;
|
||||
if (dec.alias[0] != 'm') {
|
||||
if (dec.alias[0] != 'm')
|
||||
{
|
||||
// Add prefix to all fuctions in order to avoid ambiguous function names (e.g. builtin functions)
|
||||
// TODO: check if current function is a builtin function
|
||||
dec.alias = join("m", dec.alias);
|
||||
@ -1048,7 +1055,8 @@ void CompilerMSL::emit_fixup()
|
||||
/*const char *suffix = backend.float_literal_suffix ? "f" : "";
|
||||
statement(qual_pos_var_name, ".z = 2.0", suffix, " * ", qual_pos_var_name, ".z - ", qual_pos_var_name,
|
||||
".w;", " // Adjust clip-space for Metal");*/
|
||||
statement(qual_pos_var_name, ".z = (", qual_pos_var_name, ".z + ", qual_pos_var_name, ".w) * 0.5; // Adjust clip-space for Metal");
|
||||
statement(qual_pos_var_name, ".z = (", qual_pos_var_name, ".z + ", qual_pos_var_name,
|
||||
".w) * 0.5; // Adjust clip-space for Metal");
|
||||
}
|
||||
|
||||
if (msl_config.flip_vert_y)
|
||||
@ -1261,8 +1269,10 @@ string CompilerMSL::clean_func_name(string func_name)
|
||||
return (iter != func_name_overrides.end()) ? iter->second : func_name;
|
||||
}
|
||||
|
||||
void CompilerMSL::set_entry_point_name(string func_name) {
|
||||
if (func_name.find("main") == std::string::npos) func_name += "_main";
|
||||
void CompilerMSL::set_entry_point_name(string func_name)
|
||||
{
|
||||
if (func_name.find("main") == std::string::npos)
|
||||
func_name += "_main";
|
||||
meta.at(entry_point).decoration.alias = func_name;
|
||||
}
|
||||
|
||||
@ -1382,7 +1392,8 @@ uint32_t CompilerMSL::get_metal_resource_index(SPIRVariable &var, SPIRType::Base
|
||||
switch (basetype)
|
||||
{
|
||||
case SPIRType::Struct:
|
||||
if (execution.model == ExecutionModelVertex && next_metal_resource_index.msl_buffer == 0) next_metal_resource_index.msl_buffer = 1;
|
||||
if (execution.model == ExecutionModelVertex && next_metal_resource_index.msl_buffer == 0)
|
||||
next_metal_resource_index.msl_buffer = 1;
|
||||
return next_metal_resource_index.msl_buffer++;
|
||||
case SPIRType::Image:
|
||||
return next_metal_resource_index.msl_texture++;
|
||||
@ -1408,7 +1419,8 @@ string CompilerMSL::argument_decl(const SPIRFunction::Parameter &arg)
|
||||
bool pointer = type.storage == StorageClassUniformConstant;
|
||||
|
||||
auto &var = get<SPIRVariable>(arg.id);
|
||||
return join(constref ? "const " : "", type_to_glsl(type), pointer ? " " : "& ", to_name(var.self), type_to_array_glsl(type));
|
||||
return join(constref ? "const " : "", type_to_glsl(type), pointer ? " " : "& ", to_name(var.self),
|
||||
type_to_array_glsl(type));
|
||||
}
|
||||
|
||||
// If we're currently in the entry point function, and the object
|
||||
@ -1443,13 +1455,16 @@ string CompilerMSL::to_qualified_member_name(const SPIRType &type, uint32_t inde
|
||||
// if the first chars are _ and a digit, which indicate a transient name.
|
||||
string CompilerMSL::ensure_valid_name(string name, string pfx)
|
||||
{
|
||||
if (name.size() >= 2 && name[0] == '_' && isdigit(name[1])) {
|
||||
if (name.size() >= 2 && name[0] == '_' && isdigit(name[1]))
|
||||
{
|
||||
return join(pfx, name);
|
||||
}
|
||||
else if (std::find(reserved_names.begin(), reserved_names.end(), name) != reserved_names.end()) {
|
||||
else if (std::find(reserved_names.begin(), reserved_names.end(), name) != reserved_names.end())
|
||||
{
|
||||
return join(pfx, name);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ protected:
|
||||
std::string stage_out_var_name = "out";
|
||||
std::string stage_uniform_var_name = "uniforms";
|
||||
std::string sampler_name_suffix = "Smplr";
|
||||
std::vector<std::string> reserved_names = {"kernel", "bias"};
|
||||
std::vector<std::string> reserved_names = { "kernel", "bias" };
|
||||
|
||||
// Extracts a set of opcodes that should be implemented as a bespoke custom function
|
||||
// whose full source code is output as part of the shader source code.
|
||||
|
Loading…
Reference in New Issue
Block a user