#include "builtin.h"
#include "compiler.h"
#include "debug.h"
-#include "deviceinfo.h"
#include "error.h"
#include "finalize.h"
#include "generate.h"
namespace GL {
namespace SL {
-Compiler::Compiler():
- features(DeviceInfo::get_global().glsl_features)
-{ }
-
Compiler::Compiler(const Features &f):
features(f)
{ }
for(Stage &s: module->stages)
generate(s);
ConstantIdAssigner().apply(*module, features);
+ LocationAllocator().apply(*module, features, false);
for(Stage &s: module->stages)
validate(s);
for(Stage &s: module->stages)
ConstantSpecializer().apply(s, spec_values);
}
+ if(mode==PROGRAM)
+ {
+ for(Stage &s: module->stages)
+ DepthRangeConverter().apply(s, features);
+ }
for(auto i=module->stages.begin(); i!=module->stages.end(); )
{
OptimizeResult result = optimize(*i);
++i;
}
+ Stage *prev_stage = 0;
+ for(auto i=module->stages.begin(); i!=module->stages.end(); )
+ {
+ if(i->functions.empty())
+ i = module->stages.erase(i);
+ else
+ {
+ i->previous = prev_stage;
+ prev_stage = &*i;
+ ++i;
+ }
+ }
+
+ for(Stage &s: module->stages)
+ {
+ StructuralFeatureConverter().apply(s, features);
+ resolve(s, RESOLVE_VARIABLES|RESOLVE_FUNCTIONS);
+ }
LocationAllocator().apply(*module, features);
for(Stage &s: module->stages)
finalize(s, mode);
if(!compiled)
throw invalid_operation("Compiler::get_combined_spirv");
SpirVGenerator gen;
- gen.apply(*module);
+ gen.apply(*module, features);
return gen.get_code();
}
return module->source_map;
}
-string Compiler::get_stage_debug(Stage::Type stage_type) const
+string Compiler::get_stage_debug(Stage::Type stage_type, bool use_colors) const
{
auto i = find_member(module->stages, stage_type, &Stage::type);
if(i!=module->stages.end())
- return DumpTree().apply(*i);
+ return DumpTree(use_colors).apply(*i);
throw key_error(Stage::get_stage_name(stage_type));
}
variables through interfaces. */
InterfaceGenerator().apply(stage);
resolve(stage, RESOLVE_BLOCKS|RESOLVE_TYPES|RESOLVE_VARIABLES);
+
+ ArraySizer().apply(stage);
+ resolve(stage, RESOLVE_EXPRESSIONS);
}
template<typename T>
void Compiler::validate(Stage &stage)
{
- DeclarationValidator().apply(stage);
+ DeclarationValidator().apply(stage, features);
IdentifierValidator().apply(stage);
ReferenceValidator().apply(stage);
ExpressionValidator().apply(stage);
{
if(ConstantFolder().apply(stage))
resolve(stage, RESOLVE_EXPRESSIONS);
- ConstantConditionEliminator().apply(stage);
+ if(ConstantConditionEliminator().apply(stage))
+ resolve(stage, RESOLVE_VARIABLES);
bool any_inlined = false;
if(FunctionInliner().apply(stage))
void Compiler::finalize(Stage &stage, Mode mode)
{
- if(mode==PROGRAM)
- {
- StructuralFeatureConverter().apply(stage, features);
- QualifierConverter().apply(stage, features);
- resolve(stage, RESOLVE_VARIABLES|RESOLVE_FUNCTIONS);
- PrecisionConverter().apply(stage);
- }
- else if(mode==SPIRV)
+ QualifierConverter().apply(stage, features);
+ PrecisionConverter().apply(stage);
+ if(mode==SPIRV)
StructOrganizer().apply(stage);
// Collect bindings from all stages into the shared stage's maps