Add -Wshadow.
Fixes lots of dubious variable shadowing.
This commit is contained in:
Родитель
874d30130e
Коммит
926916d745
2
Makefile
2
Makefile
|
@ -10,7 +10,7 @@ STATIC_LIB := lib$(TARGET).a
|
|||
|
||||
DEPS := $(OBJECTS:.o=.d) $(CLI_OBJECTS:.o=.d)
|
||||
|
||||
CXXFLAGS += -std=c++11 -Wall -Wextra
|
||||
CXXFLAGS += -std=c++11 -Wall -Wextra -Wshadow
|
||||
|
||||
ifeq ($(DEBUG), 1)
|
||||
CXXFLAGS += -O0
|
||||
|
|
4
main.cpp
4
main.cpp
|
@ -43,8 +43,8 @@ struct CLICallbacks
|
|||
|
||||
struct CLIParser
|
||||
{
|
||||
CLIParser(CLICallbacks cbs, int argc, char *argv[])
|
||||
: cbs(move(cbs)), argc(argc), argv(argv)
|
||||
CLIParser(CLICallbacks cbs_, int argc_, char *argv_[])
|
||||
: cbs(move(cbs_)), argc(argc_), argv(argv_)
|
||||
{}
|
||||
|
||||
bool parse()
|
||||
|
|
|
@ -136,7 +136,7 @@ namespace spirv_cross
|
|||
struct SPIRUndef : IVariant
|
||||
{
|
||||
enum { type = TypeUndef };
|
||||
SPIRUndef(uint32_t basetype) : basetype(basetype) {}
|
||||
SPIRUndef(uint32_t basetype_) : basetype(basetype_) {}
|
||||
uint32_t basetype;
|
||||
};
|
||||
|
||||
|
@ -198,8 +198,8 @@ namespace spirv_cross
|
|||
GLSL
|
||||
};
|
||||
|
||||
SPIRExtension(Extension ext)
|
||||
: ext(ext) {}
|
||||
SPIRExtension(Extension ext_)
|
||||
: ext(ext_) {}
|
||||
|
||||
Extension ext;
|
||||
};
|
||||
|
@ -209,8 +209,8 @@ namespace spirv_cross
|
|||
enum { type = TypeExpression };
|
||||
|
||||
// Only created by the backend target to avoid creating tons of temporaries.
|
||||
SPIRExpression(std::string expr, uint32_t expression_type, bool immutable)
|
||||
: expression(move(expr)), expression_type(expression_type), immutable(immutable) {}
|
||||
SPIRExpression(std::string expr, uint32_t expression_type_, bool immutable_)
|
||||
: expression(move(expr)), expression_type(expression_type_), immutable(immutable_) {}
|
||||
|
||||
// If non-zero, prepend expression with to_expression(base_expression).
|
||||
// Used in amortizing multiple calls to to_expression()
|
||||
|
@ -239,8 +239,8 @@ namespace spirv_cross
|
|||
{
|
||||
enum { type = TypeFunctionPrototype };
|
||||
|
||||
SPIRFunctionPrototype(uint32_t return_type)
|
||||
: return_type(return_type) {}
|
||||
SPIRFunctionPrototype(uint32_t return_type_)
|
||||
: return_type(return_type_) {}
|
||||
|
||||
uint32_t return_type;
|
||||
std::vector<uint32_t> parameter_types;
|
||||
|
@ -348,8 +348,8 @@ namespace spirv_cross
|
|||
{
|
||||
enum { type = TypeFunction };
|
||||
|
||||
SPIRFunction(uint32_t return_type, uint32_t function_type)
|
||||
: return_type(return_type), function_type(function_type)
|
||||
SPIRFunction(uint32_t return_type_, uint32_t function_type_)
|
||||
: return_type(return_type_), function_type(function_type_)
|
||||
{}
|
||||
|
||||
struct Parameter
|
||||
|
@ -372,10 +372,10 @@ namespace spirv_cross
|
|||
local_variables.push_back(id);
|
||||
}
|
||||
|
||||
void add_parameter(uint32_t type, uint32_t id)
|
||||
void add_parameter(uint32_t parameter_type, uint32_t id)
|
||||
{
|
||||
// Arguments are read-only until proven otherwise.
|
||||
arguments.push_back({ type, id, 0u, 0u });
|
||||
arguments.push_back({ parameter_type, id, 0u, 0u });
|
||||
}
|
||||
|
||||
bool active = false;
|
||||
|
@ -387,8 +387,8 @@ namespace spirv_cross
|
|||
enum { type = TypeVariable };
|
||||
|
||||
SPIRVariable() = default;
|
||||
SPIRVariable(uint32_t basetype, spv::StorageClass storage, uint32_t initializer = 0)
|
||||
: basetype(basetype), storage(storage), initializer(initializer)
|
||||
SPIRVariable(uint32_t basetype_, spv::StorageClass storage_, uint32_t initializer_ = 0)
|
||||
: basetype(basetype_), storage(storage_), initializer(initializer_)
|
||||
{}
|
||||
|
||||
uint32_t basetype = 0;
|
||||
|
@ -459,22 +459,22 @@ namespace spirv_cross
|
|||
inline uint32_t vector_size() const { return m.c[0].vecsize; }
|
||||
inline uint32_t columns() const { return m.columns; }
|
||||
|
||||
SPIRConstant(uint32_t constant_type, const uint32_t *elements, uint32_t num_elements) :
|
||||
constant_type(constant_type)
|
||||
SPIRConstant(uint32_t constant_type_, const uint32_t *elements, uint32_t num_elements) :
|
||||
constant_type(constant_type_)
|
||||
{
|
||||
subconstants.insert(end(subconstants), elements, elements + num_elements);
|
||||
}
|
||||
|
||||
SPIRConstant(uint32_t constant_type, uint32_t v0) :
|
||||
constant_type(constant_type)
|
||||
SPIRConstant(uint32_t constant_type_, uint32_t v0) :
|
||||
constant_type(constant_type_)
|
||||
{
|
||||
m.c[0].r[0].u32 = v0;
|
||||
m.c[0].vecsize = 1;
|
||||
m.columns = 1;
|
||||
}
|
||||
|
||||
SPIRConstant(uint32_t constant_type, uint32_t v0, uint32_t v1) :
|
||||
constant_type(constant_type)
|
||||
SPIRConstant(uint32_t constant_type_, uint32_t v0, uint32_t v1) :
|
||||
constant_type(constant_type_)
|
||||
{
|
||||
m.c[0].r[0].u32 = v0;
|
||||
m.c[0].r[1].u32 = v1;
|
||||
|
@ -482,8 +482,8 @@ namespace spirv_cross
|
|||
m.columns = 1;
|
||||
}
|
||||
|
||||
SPIRConstant(uint32_t constant_type, uint32_t v0, uint32_t v1, uint32_t v2) :
|
||||
constant_type(constant_type)
|
||||
SPIRConstant(uint32_t constant_type_, uint32_t v0, uint32_t v1, uint32_t v2) :
|
||||
constant_type(constant_type_)
|
||||
{
|
||||
m.c[0].r[0].u32 = v0;
|
||||
m.c[0].r[1].u32 = v1;
|
||||
|
@ -492,8 +492,8 @@ namespace spirv_cross
|
|||
m.columns = 1;
|
||||
}
|
||||
|
||||
SPIRConstant(uint32_t constant_type, uint32_t v0, uint32_t v1, uint32_t v2, uint32_t v3) :
|
||||
constant_type(constant_type)
|
||||
SPIRConstant(uint32_t constant_type_, uint32_t v0, uint32_t v1, uint32_t v2, uint32_t v3) :
|
||||
constant_type(constant_type_)
|
||||
{
|
||||
m.c[0].r[0].u32 = v0;
|
||||
m.c[0].r[1].u32 = v1;
|
||||
|
@ -503,27 +503,27 @@ namespace spirv_cross
|
|||
m.columns = 1;
|
||||
}
|
||||
|
||||
SPIRConstant(uint32_t constant_type,
|
||||
SPIRConstant(uint32_t constant_type_,
|
||||
const ConstantVector &vec0) :
|
||||
constant_type(constant_type)
|
||||
constant_type(constant_type_)
|
||||
{
|
||||
m.columns = 1;
|
||||
m.c[0] = vec0;
|
||||
}
|
||||
|
||||
SPIRConstant(uint32_t constant_type,
|
||||
SPIRConstant(uint32_t constant_type_,
|
||||
const ConstantVector &vec0, const ConstantVector &vec1) :
|
||||
constant_type(constant_type)
|
||||
constant_type(constant_type_)
|
||||
{
|
||||
m.columns = 2;
|
||||
m.c[0] = vec0;
|
||||
m.c[1] = vec1;
|
||||
}
|
||||
|
||||
SPIRConstant(uint32_t constant_type,
|
||||
SPIRConstant(uint32_t constant_type_,
|
||||
const ConstantVector &vec0, const ConstantVector &vec1,
|
||||
const ConstantVector &vec2) :
|
||||
constant_type(constant_type)
|
||||
constant_type(constant_type_)
|
||||
{
|
||||
m.columns = 3;
|
||||
m.c[0] = vec0;
|
||||
|
@ -531,10 +531,10 @@ namespace spirv_cross
|
|||
m.c[2] = vec2;
|
||||
}
|
||||
|
||||
SPIRConstant(uint32_t constant_type,
|
||||
SPIRConstant(uint32_t constant_type_,
|
||||
const ConstantVector &vec0, const ConstantVector &vec1,
|
||||
const ConstantVector &vec2, const ConstantVector &vec3) :
|
||||
constant_type(constant_type)
|
||||
constant_type(constant_type_)
|
||||
{
|
||||
m.columns = 4;
|
||||
m.c[0] = vec0;
|
||||
|
@ -568,12 +568,12 @@ namespace spirv_cross
|
|||
return *this;
|
||||
}
|
||||
|
||||
void set(std::unique_ptr<IVariant> val, uint32_t type)
|
||||
void set(std::unique_ptr<IVariant> val, uint32_t new_type)
|
||||
{
|
||||
holder = std::move(val);
|
||||
if (this->type != TypeNone && this->type != type)
|
||||
if (type != TypeNone && type != new_type)
|
||||
throw CompilerError("Overwriting a variant with new type.");
|
||||
this->type = type;
|
||||
type = new_type;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
|
|
@ -25,13 +25,13 @@ void CompilerCPP::emit_buffer_block(const SPIRVariable &var)
|
|||
auto &type = get<SPIRType>(var.basetype);
|
||||
auto instance_name = to_name(var.self);
|
||||
|
||||
uint32_t set = meta[var.self].decoration.set;
|
||||
uint32_t descriptor_set = meta[var.self].decoration.set;
|
||||
uint32_t binding = meta[var.self].decoration.binding;
|
||||
|
||||
emit_struct(type);
|
||||
statement("internal::Resource<", type_to_glsl(type), type_to_array_glsl(type), "> ", instance_name, "__;");
|
||||
statement_no_indent("#define ", instance_name, " __res->", instance_name, "__.get()");
|
||||
resource_registrations.push_back(join("s.register_resource(", instance_name, "__", ", ", set, ", ", binding, ");"));
|
||||
resource_registrations.push_back(join("s.register_resource(", instance_name, "__", ", ", descriptor_set, ", ", binding, ");"));
|
||||
statement("");
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,7 @@ void CompilerCPP::emit_uniform(const SPIRVariable &var)
|
|||
auto &type = get<SPIRType>(var.basetype);
|
||||
auto instance_name = to_name(var.self);
|
||||
|
||||
uint32_t set = meta[var.self].decoration.set;
|
||||
uint32_t descriptor_set = meta[var.self].decoration.set;
|
||||
uint32_t binding = meta[var.self].decoration.binding;
|
||||
uint32_t location = meta[var.self].decoration.location;
|
||||
|
||||
|
@ -74,7 +74,7 @@ void CompilerCPP::emit_uniform(const SPIRVariable &var)
|
|||
{
|
||||
statement("internal::Resource<", type_to_glsl(type), type_to_array_glsl(type), "> ", instance_name, "__;");
|
||||
statement_no_indent("#define ", instance_name, " __res->", instance_name, "__.get()");
|
||||
resource_registrations.push_back(join("s.register_resource(", instance_name, "__", ", ", set, ", ", binding, ");"));
|
||||
resource_registrations.push_back(join("s.register_resource(", instance_name, "__", ", ", descriptor_set, ", ", binding, ");"));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace spirv_cross
|
|||
class CompilerCPP : public CompilerGLSL
|
||||
{
|
||||
public:
|
||||
CompilerCPP(std::vector<uint32_t> spirv) : CompilerGLSL(move(spirv)) {}
|
||||
CompilerCPP(std::vector<uint32_t> spirv_) : CompilerGLSL(move(spirv_)) {}
|
||||
std::string compile() override;
|
||||
|
||||
private:
|
||||
|
|
169
spirv_cross.cpp
169
spirv_cross.cpp
|
@ -248,9 +248,9 @@ void Compiler::flush_all_active_variables()
|
|||
{
|
||||
// Invalidate all temporaries we read from variables in this block since they were forwarded.
|
||||
// Invalidate all temporaries we read from globals.
|
||||
for (auto &v : function->local_variables)
|
||||
for (auto &v : current_function->local_variables)
|
||||
flush_dependees(get<SPIRVariable>(v));
|
||||
for (auto &arg : function->arguments)
|
||||
for (auto &arg : current_function->arguments)
|
||||
flush_dependees(get<SPIRVariable>(arg.id));
|
||||
for (auto global : global_variables)
|
||||
flush_dependees(get<SPIRVariable>(global));
|
||||
|
@ -489,9 +489,9 @@ void Compiler::parse()
|
|||
for (auto &i : inst)
|
||||
parse(i);
|
||||
|
||||
if (function)
|
||||
if (current_function)
|
||||
throw CompilerError("Function was not terminated.");
|
||||
if (block)
|
||||
if (current_block)
|
||||
throw CompilerError("Block was not terminated.");
|
||||
}
|
||||
|
||||
|
@ -797,14 +797,11 @@ void Compiler::unset_decoration(uint32_t id, Decoration decoration)
|
|||
}
|
||||
}
|
||||
|
||||
void Compiler::parse(const Instruction &i)
|
||||
void Compiler::parse(const Instruction &instruction)
|
||||
{
|
||||
auto ops = stream(i);
|
||||
auto op = static_cast<Op>(i.op);
|
||||
uint32_t length = i.length;
|
||||
|
||||
if (i.offset + length > spirv.size())
|
||||
throw CompilerError("Compiler::parse() opcode out of range.");
|
||||
auto ops = stream(instruction);
|
||||
auto op = static_cast<Op>(instruction.op);
|
||||
uint32_t length = instruction.length;
|
||||
|
||||
switch (op)
|
||||
{
|
||||
|
@ -856,7 +853,7 @@ void Compiler::parse(const Instruction &i)
|
|||
case OpExtInstImport:
|
||||
{
|
||||
uint32_t id = ops[0];
|
||||
auto ext = extract_string(spirv, i.offset + 1);
|
||||
auto ext = extract_string(spirv, instruction.offset + 1);
|
||||
if (ext == "GLSL.std.450")
|
||||
set<SPIRExtension>(id, SPIRExtension::GLSL);
|
||||
else
|
||||
|
@ -909,7 +906,7 @@ void Compiler::parse(const Instruction &i)
|
|||
case OpName:
|
||||
{
|
||||
uint32_t id = ops[0];
|
||||
set_name(id, extract_string(spirv, i.offset + 1));
|
||||
set_name(id, extract_string(spirv, instruction.offset + 1));
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -917,7 +914,7 @@ void Compiler::parse(const Instruction &i)
|
|||
{
|
||||
uint32_t id = ops[0];
|
||||
uint32_t member = ops[1];
|
||||
set_member_name(id, member, extract_string(spirv, i.offset + 2));
|
||||
set_member_name(id, member, extract_string(spirv, instruction.offset + 2));
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1127,9 +1124,9 @@ void Compiler::parse(const Instruction &i)
|
|||
|
||||
if (storage == StorageClassFunction)
|
||||
{
|
||||
if (!function)
|
||||
if (!current_function)
|
||||
throw CompilerError("No function currently in scope");
|
||||
function->add_local_variable(id);
|
||||
current_function->add_local_variable(id);
|
||||
}
|
||||
else if (storage == StorageClassPrivate ||
|
||||
storage == StorageClassWorkgroup ||
|
||||
|
@ -1164,9 +1161,9 @@ void Compiler::parse(const Instruction &i)
|
|||
// variable to emulate SSA Phi.
|
||||
case OpPhi:
|
||||
{
|
||||
if (!function)
|
||||
if (!current_function)
|
||||
throw CompilerError("No function currently in scope");
|
||||
if (!block)
|
||||
if (!current_block)
|
||||
throw CompilerError("No block currently in scope");
|
||||
|
||||
uint32_t result_type = ops[0];
|
||||
|
@ -1176,10 +1173,10 @@ void Compiler::parse(const Instruction &i)
|
|||
auto &var = set<SPIRVariable>(id, result_type, spv::StorageClassFunction);
|
||||
var.phi_variable = true;
|
||||
|
||||
function->add_local_variable(id);
|
||||
current_function->add_local_variable(id);
|
||||
|
||||
for (uint32_t i = 2; i + 2 <= length; i += 2)
|
||||
block->phi_variables.push_back({ ops[i], ops[i + 1], id });
|
||||
current_block->phi_variables.push_back({ ops[i], ops[i + 1], id });
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1308,10 +1305,10 @@ void Compiler::parse(const Instruction &i)
|
|||
// Control
|
||||
uint32_t type = ops[3];
|
||||
|
||||
if (function)
|
||||
if (current_function)
|
||||
throw CompilerError("Must end a function before starting a new one!");
|
||||
|
||||
function = &set<SPIRFunction>(id, res, type);
|
||||
current_function = &set<SPIRFunction>(id, res, type);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1320,17 +1317,17 @@ void Compiler::parse(const Instruction &i)
|
|||
uint32_t type = ops[0];
|
||||
uint32_t id = ops[1];
|
||||
|
||||
if (!function)
|
||||
if (!current_function)
|
||||
throw CompilerError("Must be in a function!");
|
||||
|
||||
function->add_parameter(type, id);
|
||||
current_function->add_parameter(type, id);
|
||||
set<SPIRVariable>(id, type, StorageClassFunction);
|
||||
break;
|
||||
}
|
||||
|
||||
case OpFunctionEnd:
|
||||
{
|
||||
function = nullptr;
|
||||
current_function = nullptr;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1338,147 +1335,147 @@ void Compiler::parse(const Instruction &i)
|
|||
case OpLabel:
|
||||
{
|
||||
// OpLabel always starts a block.
|
||||
if (!function)
|
||||
if (!current_function)
|
||||
throw CompilerError("Blocks cannot exist outside functions!");
|
||||
|
||||
uint32_t id = ops[0];
|
||||
|
||||
function->blocks.push_back(id);
|
||||
if (!function->entry_block)
|
||||
function->entry_block = id;
|
||||
current_function->blocks.push_back(id);
|
||||
if (!current_function->entry_block)
|
||||
current_function->entry_block = id;
|
||||
|
||||
if (block)
|
||||
if (current_block)
|
||||
throw CompilerError("Cannot start a block before ending the current block.");
|
||||
|
||||
block = &set<SPIRBlock>(id);
|
||||
current_block = &set<SPIRBlock>(id);
|
||||
break;
|
||||
}
|
||||
|
||||
// Branch instructions end blocks.
|
||||
case OpBranch:
|
||||
{
|
||||
if (!block)
|
||||
if (!current_block)
|
||||
throw CompilerError("Trying to end a non-existing block.");
|
||||
|
||||
uint32_t target = ops[0];
|
||||
block->terminator = SPIRBlock::Direct;
|
||||
block->next_block = target;
|
||||
block = nullptr;
|
||||
current_block->terminator = SPIRBlock::Direct;
|
||||
current_block->next_block = target;
|
||||
current_block = nullptr;
|
||||
break;
|
||||
}
|
||||
|
||||
case OpBranchConditional:
|
||||
{
|
||||
if (!block)
|
||||
if (!current_block)
|
||||
throw CompilerError("Trying to end a non-existing block.");
|
||||
|
||||
block->condition = ops[0];
|
||||
block->true_block = ops[1];
|
||||
block->false_block = ops[2];
|
||||
current_block->condition = ops[0];
|
||||
current_block->true_block = ops[1];
|
||||
current_block->false_block = ops[2];
|
||||
|
||||
block->terminator = SPIRBlock::Select;
|
||||
block = nullptr;
|
||||
current_block->terminator = SPIRBlock::Select;
|
||||
current_block = nullptr;
|
||||
break;
|
||||
}
|
||||
|
||||
case OpSwitch:
|
||||
{
|
||||
if (!block)
|
||||
if (!current_block)
|
||||
throw CompilerError("Trying to end a non-existing block.");
|
||||
|
||||
if (block->merge == SPIRBlock::MergeNone)
|
||||
if (current_block->merge == SPIRBlock::MergeNone)
|
||||
throw CompilerError("Switch statement is not structured");
|
||||
|
||||
block->terminator = SPIRBlock::MultiSelect;
|
||||
current_block->terminator = SPIRBlock::MultiSelect;
|
||||
|
||||
block->condition = ops[0];
|
||||
block->default_block = ops[1];
|
||||
current_block->condition = ops[0];
|
||||
current_block->default_block = ops[1];
|
||||
|
||||
for (uint32_t i = 2; i + 2 <= length; i += 2)
|
||||
block->cases.push_back({ ops[i], ops[i + 1] });
|
||||
current_block->cases.push_back({ ops[i], ops[i + 1] });
|
||||
|
||||
// If we jump to next block, make it break instead since we're inside a switch case block at that point.
|
||||
multiselect_merge_target.insert(block->next_block);
|
||||
multiselect_merge_targets.insert(current_block->next_block);
|
||||
|
||||
block = nullptr;
|
||||
current_block = nullptr;
|
||||
break;
|
||||
}
|
||||
|
||||
case OpKill:
|
||||
{
|
||||
if (!block)
|
||||
if (!current_block)
|
||||
throw CompilerError("Trying to end a non-existing block.");
|
||||
block->terminator = SPIRBlock::Kill;
|
||||
block = nullptr;
|
||||
current_block->terminator = SPIRBlock::Kill;
|
||||
current_block = nullptr;
|
||||
break;
|
||||
}
|
||||
|
||||
case OpReturn:
|
||||
{
|
||||
if (!block)
|
||||
if (!current_block)
|
||||
throw CompilerError("Trying to end a non-existing block.");
|
||||
block->terminator = SPIRBlock::Return;
|
||||
block = nullptr;
|
||||
current_block->terminator = SPIRBlock::Return;
|
||||
current_block = nullptr;
|
||||
break;
|
||||
}
|
||||
|
||||
case OpReturnValue:
|
||||
{
|
||||
if (!block)
|
||||
if (!current_block)
|
||||
throw CompilerError("Trying to end a non-existing block.");
|
||||
block->terminator = SPIRBlock::Return;
|
||||
block->return_value = ops[0];
|
||||
block = nullptr;
|
||||
current_block->terminator = SPIRBlock::Return;
|
||||
current_block->return_value = ops[0];
|
||||
current_block = nullptr;
|
||||
break;
|
||||
}
|
||||
|
||||
case OpUnreachable:
|
||||
{
|
||||
if (!block)
|
||||
if (!current_block)
|
||||
throw CompilerError("Trying to end a non-existing block.");
|
||||
block->terminator = SPIRBlock::Unreachable;
|
||||
block = nullptr;
|
||||
current_block->terminator = SPIRBlock::Unreachable;
|
||||
current_block = nullptr;
|
||||
break;
|
||||
}
|
||||
|
||||
case OpSelectionMerge:
|
||||
{
|
||||
if (!block)
|
||||
if (!current_block)
|
||||
throw CompilerError("Trying to modify a non-existing block.");
|
||||
|
||||
block->next_block = ops[0];
|
||||
block->merge = SPIRBlock::MergeSelection;
|
||||
selection_merge_target.insert(block->next_block);
|
||||
current_block->next_block = ops[0];
|
||||
current_block->merge = SPIRBlock::MergeSelection;
|
||||
selection_merge_targets.insert(current_block->next_block);
|
||||
break;
|
||||
}
|
||||
|
||||
case OpLoopMerge:
|
||||
{
|
||||
if (!block)
|
||||
if (!current_block)
|
||||
throw CompilerError("Trying to modify a non-existing block.");
|
||||
|
||||
block->merge_block = ops[0];
|
||||
block->continue_block = ops[1];
|
||||
block->merge = SPIRBlock::MergeLoop;
|
||||
current_block->merge_block = ops[0];
|
||||
current_block->continue_block = ops[1];
|
||||
current_block->merge = SPIRBlock::MergeLoop;
|
||||
|
||||
loop_block.insert(block->self);
|
||||
loop_merge_target.insert(block->merge_block);
|
||||
loop_blocks.insert(current_block->self);
|
||||
loop_merge_targets.insert(current_block->merge_block);
|
||||
|
||||
// Don't add loop headers to continue blocks,
|
||||
// which would make it impossible branch into the loop header since
|
||||
// they are treated as continues.
|
||||
if (block->continue_block != block->self)
|
||||
continue_block.insert(block->continue_block);
|
||||
if (current_block->continue_block != current_block->self)
|
||||
continue_blocks.insert(current_block->continue_block);
|
||||
break;
|
||||
}
|
||||
|
||||
// Actual opcodes.
|
||||
default:
|
||||
{
|
||||
if (!block)
|
||||
if (!current_block)
|
||||
throw CompilerError("Currently no block to insert opcode.");
|
||||
|
||||
block->ops.push_back(i);
|
||||
current_block->ops.push_back(instruction);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1634,29 +1631,29 @@ bool Compiler::execution_is_branchless(const SPIRBlock &from, const SPIRBlock &t
|
|||
}
|
||||
}
|
||||
|
||||
SPIRBlock::ContinueBlockType Compiler::continue_block_type(const SPIRBlock &continue_block) const
|
||||
SPIRBlock::ContinueBlockType Compiler::continue_block_type(const SPIRBlock &block) const
|
||||
{
|
||||
// The block was deemed too complex during code emit, pick conservative fallback paths.
|
||||
if (continue_block.complex_continue)
|
||||
if (block.complex_continue)
|
||||
return SPIRBlock::ComplexLoop;
|
||||
|
||||
// In older glslang output continue block can be equal to the loop header.
|
||||
// In this case, execution is clearly branchless, so just assume a while loop header here.
|
||||
if (continue_block.merge == SPIRBlock::MergeLoop)
|
||||
if (block.merge == SPIRBlock::MergeLoop)
|
||||
return SPIRBlock::WhileLoop;
|
||||
|
||||
auto &dominator = get<SPIRBlock>(continue_block.loop_dominator);
|
||||
auto &dominator = get<SPIRBlock>(block.loop_dominator);
|
||||
|
||||
if (execution_is_noop(continue_block, dominator))
|
||||
if (execution_is_noop(block, dominator))
|
||||
return SPIRBlock::WhileLoop;
|
||||
else if (execution_is_branchless(continue_block, dominator))
|
||||
else if (execution_is_branchless(block, dominator))
|
||||
return SPIRBlock::ForLoop;
|
||||
else
|
||||
{
|
||||
if (continue_block.merge == SPIRBlock::MergeNone &&
|
||||
continue_block.terminator == SPIRBlock::Select &&
|
||||
continue_block.true_block == dominator.self &&
|
||||
continue_block.false_block == dominator.merge_block)
|
||||
if (block.merge == SPIRBlock::MergeNone &&
|
||||
block.terminator == SPIRBlock::Select &&
|
||||
block.true_block == dominator.self &&
|
||||
block.false_block == dominator.merge_block)
|
||||
{
|
||||
return SPIRBlock::DoWhileLoop;
|
||||
}
|
||||
|
|
|
@ -191,8 +191,8 @@ namespace spirv_cross
|
|||
std::vector<Variant> ids;
|
||||
std::vector<Meta> meta;
|
||||
|
||||
SPIRFunction *function = nullptr;
|
||||
SPIRBlock *block = nullptr;
|
||||
SPIRFunction *current_function = nullptr;
|
||||
SPIRBlock *current_block = nullptr;
|
||||
std::vector<uint32_t> global_variables;
|
||||
std::vector<uint32_t> aliased_variables;
|
||||
|
||||
|
@ -260,11 +260,11 @@ namespace spirv_cross
|
|||
Source() = default;
|
||||
} source;
|
||||
|
||||
std::unordered_set<uint32_t> loop_block;
|
||||
std::unordered_set<uint32_t> continue_block;
|
||||
std::unordered_set<uint32_t> loop_merge_target;
|
||||
std::unordered_set<uint32_t> selection_merge_target;
|
||||
std::unordered_set<uint32_t> multiselect_merge_target;
|
||||
std::unordered_set<uint32_t> loop_blocks;
|
||||
std::unordered_set<uint32_t> continue_blocks;
|
||||
std::unordered_set<uint32_t> loop_merge_targets;
|
||||
std::unordered_set<uint32_t> selection_merge_targets;
|
||||
std::unordered_set<uint32_t> multiselect_merge_targets;
|
||||
|
||||
std::string to_name(uint32_t id);
|
||||
bool is_builtin_variable(const SPIRVariable &var) const;
|
||||
|
@ -283,19 +283,19 @@ namespace spirv_cross
|
|||
|
||||
inline bool is_continue(uint32_t next) const
|
||||
{
|
||||
return continue_block.find(next) != end(continue_block);
|
||||
return continue_blocks.find(next) != end(continue_blocks);
|
||||
}
|
||||
|
||||
inline bool is_break(uint32_t next) const
|
||||
{
|
||||
return loop_merge_target.find(next) != end(loop_merge_target) ||
|
||||
multiselect_merge_target.find(next) != end(multiselect_merge_target);
|
||||
return loop_merge_targets.find(next) != end(loop_merge_targets) ||
|
||||
multiselect_merge_targets.find(next) != end(multiselect_merge_targets);
|
||||
}
|
||||
|
||||
inline bool is_conditional(uint32_t next) const
|
||||
{
|
||||
return selection_merge_target.find(next) != end(selection_merge_target) &&
|
||||
multiselect_merge_target.find(next) == end(multiselect_merge_target);
|
||||
return selection_merge_targets.find(next) != end(selection_merge_targets) &&
|
||||
multiselect_merge_targets.find(next) == end(multiselect_merge_targets);
|
||||
}
|
||||
|
||||
// Dependency tracking for temporaries read from variables.
|
||||
|
@ -343,8 +343,8 @@ namespace spirv_cross
|
|||
|
||||
struct BufferAccessHandler : OpcodeHandler
|
||||
{
|
||||
BufferAccessHandler(const Compiler &compiler, std::vector<BufferRange> &ranges, unsigned id)
|
||||
: compiler(compiler), ranges(ranges), id(id) {}
|
||||
BufferAccessHandler(const Compiler &compiler_, std::vector<BufferRange> &ranges_, unsigned id_)
|
||||
: compiler(compiler_), ranges(ranges_), id(id_) {}
|
||||
|
||||
bool handle(spv::Op opcode, const uint32_t *args, uint32_t length) override;
|
||||
|
||||
|
|
|
@ -104,7 +104,7 @@ void CompilerGLSL::reset()
|
|||
|
||||
// Clear invalid expression tracking.
|
||||
invalid_expressions.clear();
|
||||
function = nullptr;
|
||||
current_function = nullptr;
|
||||
|
||||
// Clear temporary usage tracking.
|
||||
expression_usage_counts.clear();
|
||||
|
@ -1322,8 +1322,8 @@ void CompilerGLSL::emit_mix_op(uint32_t result_type, uint32_t id,
|
|||
expr = join(to_expression(lerp), " ? ", to_expression(right), " : ", to_expression(left));
|
||||
else
|
||||
{
|
||||
auto swiz = [this](uint32_t id, uint32_t i) {
|
||||
return join(to_expression(id), ".", index_to_swizzle(i));
|
||||
auto swiz = [this](uint32_t expression, uint32_t i) {
|
||||
return join(to_expression(expression), ".", index_to_swizzle(i));
|
||||
};
|
||||
|
||||
expr = type_to_glsl_constructor(restype);
|
||||
|
@ -2277,11 +2277,11 @@ string CompilerGLSL::build_composite_combiner(const uint32_t *elems, uint32_t le
|
|||
return op;
|
||||
}
|
||||
|
||||
void CompilerGLSL::emit_instruction(const Instruction &i)
|
||||
void CompilerGLSL::emit_instruction(const Instruction &instruction)
|
||||
{
|
||||
auto ops = stream(i);
|
||||
auto op = static_cast<Op>(i.op);
|
||||
uint32_t length = i.length;
|
||||
auto ops = stream(instruction);
|
||||
auto opcode = static_cast<Op>(instruction.op);
|
||||
uint32_t length = instruction.length;
|
||||
|
||||
#define BOP(op) emit_binary_op(ops[0], ops[1], ops[2], ops[3], #op)
|
||||
#define UOP(op) emit_unary_op(ops[0], ops[1], ops[2], #op)
|
||||
|
@ -2290,7 +2290,7 @@ void CompilerGLSL::emit_instruction(const Instruction &i)
|
|||
#define BFOP(op) emit_binary_func_op(ops[0], ops[1], ops[2], ops[3], #op)
|
||||
#define UFOP(op) emit_unary_func_op(ops[0], ops[1], ops[2], #op)
|
||||
|
||||
switch (op)
|
||||
switch (opcode)
|
||||
{
|
||||
// Dealing with memory
|
||||
case OpLoad:
|
||||
|
@ -2459,13 +2459,13 @@ void CompilerGLSL::emit_instruction(const Instruction &i)
|
|||
splat = false;
|
||||
}
|
||||
|
||||
auto op = type_to_glsl_constructor(get<SPIRType>(result_type)) + "(";
|
||||
auto constructor_op = type_to_glsl_constructor(get<SPIRType>(result_type)) + "(";
|
||||
if (splat)
|
||||
op += to_expression(elems[0]);
|
||||
constructor_op += to_expression(elems[0]);
|
||||
else
|
||||
op += build_composite_combiner(elems, length);
|
||||
op += ")";
|
||||
emit_op(result_type, id, op, forward, false);
|
||||
constructor_op += build_composite_combiner(elems, length);
|
||||
constructor_op += ")";
|
||||
emit_op(result_type, id, constructor_op, forward, false);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -3039,7 +3039,7 @@ void CompilerGLSL::emit_instruction(const Instruction &i)
|
|||
case OpImageGather:
|
||||
case OpImageDrefGather:
|
||||
// Gets a bit hairy, so move this to a separate instruction.
|
||||
emit_texture_op(i);
|
||||
emit_texture_op(instruction);
|
||||
break;
|
||||
|
||||
case OpImage:
|
||||
|
@ -3218,10 +3218,10 @@ void CompilerGLSL::emit_instruction(const Instruction &i)
|
|||
|
||||
case OpExtInst:
|
||||
{
|
||||
uint32_t set = ops[2];
|
||||
if (get<SPIRExtension>(set).ext != SPIRExtension::GLSL)
|
||||
uint32_t extension_set = ops[2];
|
||||
if (get<SPIRExtension>(extension_set).ext != SPIRExtension::GLSL)
|
||||
{
|
||||
statement("// unimplemented ext op ", i.op);
|
||||
statement("// unimplemented ext op ", instruction.op);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -3230,7 +3230,7 @@ void CompilerGLSL::emit_instruction(const Instruction &i)
|
|||
}
|
||||
|
||||
default:
|
||||
statement("// unimplemented op ", i.op);
|
||||
statement("// unimplemented op ", instruction.op);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -3640,8 +3640,8 @@ void CompilerGLSL::emit_function(SPIRFunction &func, uint64_t return_flags)
|
|||
if (op == OpFunctionCall)
|
||||
{
|
||||
// Recursively emit functions which are called.
|
||||
uint32_t func = ops[2];
|
||||
emit_function(get<SPIRFunction>(func), meta[ops[1]].decoration.decoration_flags);
|
||||
uint32_t id = ops[2];
|
||||
emit_function(get<SPIRFunction>(id), meta[ops[1]].decoration.decoration_flags);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3649,7 +3649,7 @@ void CompilerGLSL::emit_function(SPIRFunction &func, uint64_t return_flags)
|
|||
emit_function_prototype(func, return_flags);
|
||||
begin_scope();
|
||||
|
||||
function = &func;
|
||||
current_function = &func;
|
||||
|
||||
for (auto &v : func.local_variables)
|
||||
{
|
||||
|
@ -3721,7 +3721,7 @@ void CompilerGLSL::branch(uint32_t from, uint32_t to)
|
|||
flush_all_active_variables();
|
||||
|
||||
// This is only a continue if we branch to our loop dominator.
|
||||
if (loop_block.find(to) != end(loop_block) &&
|
||||
if (loop_blocks.find(to) != end(loop_blocks) &&
|
||||
get<SPIRBlock>(from).loop_dominator == to)
|
||||
{
|
||||
// This can happen if we had a complex continue block which was emitted.
|
||||
|
@ -3731,14 +3731,14 @@ void CompilerGLSL::branch(uint32_t from, uint32_t to)
|
|||
}
|
||||
else if (is_continue(to))
|
||||
{
|
||||
auto &continue_block = get<SPIRBlock>(to);
|
||||
if (continue_block.complex_continue)
|
||||
auto &to_block = get<SPIRBlock>(to);
|
||||
if (to_block.complex_continue)
|
||||
{
|
||||
// Just emit the whole block chain as is.
|
||||
auto usage_counts = expression_usage_counts;
|
||||
auto invalid = invalid_expressions;
|
||||
|
||||
emit_block_chain(continue_block);
|
||||
emit_block_chain(to_block);
|
||||
|
||||
// Expression usage counts and invalid expressions
|
||||
// are moot after returning from the continue block.
|
||||
|
@ -3749,12 +3749,12 @@ void CompilerGLSL::branch(uint32_t from, uint32_t to)
|
|||
}
|
||||
else
|
||||
{
|
||||
auto &block = get<SPIRBlock>(from);
|
||||
auto &dominator = get<SPIRBlock>(block.loop_dominator);
|
||||
auto &from_block = get<SPIRBlock>(from);
|
||||
auto &dominator = get<SPIRBlock>(from_block.loop_dominator);
|
||||
|
||||
// For non-complex continue blocks, we implicitly branch to the continue block
|
||||
// by having the continue block be part of the loop header in for (; ; continue-block).
|
||||
bool outside_control_flow = block_is_outside_flow_control_from_block(dominator, block);
|
||||
bool outside_control_flow = block_is_outside_flow_control_from_block(dominator, from_block);
|
||||
|
||||
// Some simplification for for-loops. We always end up with a useless continue;
|
||||
// statement since we branch to a loop block.
|
||||
|
@ -3825,13 +3825,13 @@ void CompilerGLSL::propagate_loop_dominators(const SPIRBlock &block)
|
|||
uint32_t dominator = block.merge == SPIRBlock::MergeLoop ?
|
||||
block.self : block.loop_dominator;
|
||||
|
||||
auto set_dominator = [this](uint32_t self, uint32_t dominator) {
|
||||
auto &block = this->get<SPIRBlock>(self);
|
||||
auto set_dominator = [this](uint32_t self, uint32_t new_dominator) {
|
||||
auto &dominated_block = this->get<SPIRBlock>(self);
|
||||
|
||||
// If we already have a loop dominator, we're trying to break out to merge targets
|
||||
// which should not update the loop dominator.
|
||||
if (!block.loop_dominator)
|
||||
block.loop_dominator = dominator;
|
||||
if (!dominated_block.loop_dominator)
|
||||
dominated_block.loop_dominator = new_dominator;
|
||||
};
|
||||
|
||||
// After merging a loop, we inherit the loop dominator always.
|
||||
|
@ -3872,7 +3872,7 @@ string CompilerGLSL::emit_continue_block(uint32_t continue_block)
|
|||
redirect_statement = &statements;
|
||||
|
||||
// Stamp out all blocks one after each other.
|
||||
while (loop_block.find(block->self) == end(loop_block))
|
||||
while (loop_blocks.find(block->self) == end(loop_blocks))
|
||||
{
|
||||
propagate_loop_dominators(*block);
|
||||
// Write out all instructions we have in this block.
|
||||
|
@ -3898,10 +3898,10 @@ string CompilerGLSL::emit_continue_block(uint32_t continue_block)
|
|||
|
||||
// Somewhat ugly, strip off the last ';' since we use ',' instead.
|
||||
// Ideally, we should select this behavior in statement().
|
||||
for (auto &statement : statements)
|
||||
for (auto &s : statements)
|
||||
{
|
||||
if (!statement.empty() && statement.back() == ';')
|
||||
statement.pop_back();
|
||||
if (!s.empty() && s.back() == ';')
|
||||
s.pop_back();
|
||||
}
|
||||
|
||||
current_continue_block = nullptr;
|
||||
|
@ -4003,16 +4003,16 @@ bool CompilerGLSL::attempt_emit_loop_header(SPIRBlock &block, SPIRBlock::Method
|
|||
void CompilerGLSL::flush_undeclared_variables()
|
||||
{
|
||||
// Declare undeclared variables.
|
||||
if (function->flush_undeclared)
|
||||
if (current_function->flush_undeclared)
|
||||
{
|
||||
for (auto &v : function->local_variables)
|
||||
for (auto &v : current_function->local_variables)
|
||||
{
|
||||
auto &var = get<SPIRVariable>(v);
|
||||
if (var.deferred_declaration)
|
||||
statement(variable_decl(var), ";");
|
||||
var.deferred_declaration = false;
|
||||
}
|
||||
function->flush_undeclared = false;
|
||||
current_function->flush_undeclared = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4170,7 +4170,7 @@ void CompilerGLSL::emit_block_chain(SPIRBlock &block)
|
|||
// we do not need an explicit return which looks out of place. Just end the function here.
|
||||
// In the very weird case of for(;;) { return; } executing return is unconditional,
|
||||
// but we actually need a return here ...
|
||||
else if (!block_is_outside_flow_control_from_block(get<SPIRBlock>(function->entry_block), block) ||
|
||||
else if (!block_is_outside_flow_control_from_block(get<SPIRBlock>(current_function->entry_block), block) ||
|
||||
block.loop_dominator != SPIRBlock::NoDominator)
|
||||
statement("return;");
|
||||
break;
|
||||
|
|
|
@ -90,7 +90,7 @@ namespace spirv_cross
|
|||
remap_pls_variables();
|
||||
}
|
||||
|
||||
CompilerGLSL(std::vector<uint32_t> spirv) : Compiler(move(spirv))
|
||||
CompilerGLSL(std::vector<uint32_t> spirv_) : Compiler(move(spirv_))
|
||||
{
|
||||
if (source.known)
|
||||
{
|
||||
|
|
|
@ -22,7 +22,7 @@ using namespace spv;
|
|||
using namespace spirv_cross;
|
||||
using namespace std;
|
||||
|
||||
CompilerMSL::CompilerMSL(vector<uint32_t> spirv) : CompilerGLSL(move(spirv)) {
|
||||
CompilerMSL::CompilerMSL(vector<uint32_t> spirv_) : CompilerGLSL(move(spirv_)) {
|
||||
options.vertex.fixup_clipspace = false;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче