Skip to content

Commit 2fffb05

Browse files
committed
always enabl remapping
1 parent 8f41b7d commit 2fffb05

File tree

5 files changed

+49
-40
lines changed

5 files changed

+49
-40
lines changed

impeller/compiler/compiler.cc

Lines changed: 49 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,24 @@
2020
namespace impeller {
2121
namespace compiler {
2222

23+
static std::optional<spv::ExecutionModel> SourceTypeToExecutionModel(
24+
const SourceType& type) {
25+
switch (type) {
26+
case SourceType::kUnknown:
27+
return std::nullopt;
28+
case SourceType::kVertexShader:
29+
return spv::ExecutionModel::ExecutionModelVertex;
30+
case SourceType::kFragmentShader:
31+
return spv::ExecutionModel::ExecutionModelFragment;
32+
case SourceType::kTessellationControlShader:
33+
return spv::ExecutionModel::ExecutionModelTessellationControl;
34+
case SourceType::kTessellationEvaluationShader:
35+
return spv::ExecutionModel::ExecutionModelTessellationEvaluation;
36+
case SourceType::kComputeShader:
37+
return spv::ExecutionModel::ExecutionModelGLCompute;
38+
}
39+
}
40+
2341
const uint32_t kFragBindingBase = 128;
2442
const size_t kNumUniformKinds =
2543
static_cast<int>(shaderc_uniform_kind::shaderc_uniform_kind_buffer) + 1;
@@ -34,42 +52,40 @@ static CompilerBackend CreateMSLCompiler(const spirv_cross::ParsedIR& ir,
3452
// Metal to AIR must be updated as well.
3553
sl_options.msl_version =
3654
spirv_cross::CompilerMSL::Options::make_msl_version(1, 2);
55+
sl_options.enable_decoration_binding = true;
3756
sl_compiler->set_msl_options(sl_options);
3857

3958
// Set metal resource mappings to be consistent with location based mapping
40-
// used on other backends when creating fragment shaders. This relies on the
41-
// fact that the order of uniforms in the IR mirrors the declared order in the
42-
// shader source.
43-
if (source_options.remap_samplers) {
44-
std::vector<uint32_t> sampler_offsets;
45-
ir.for_each_typed_id<spirv_cross::SPIRVariable>(
46-
[&](uint32_t, const spirv_cross::SPIRVariable& var) {
47-
if (var.storage != spv::StorageClassUniformConstant) {
48-
return;
49-
}
50-
const auto spir_type = sl_compiler->get_type(var.basetype);
51-
if (spir_type.basetype !=
52-
spirv_cross::SPIRType::BaseType::SampledImage) {
53-
return;
54-
}
55-
auto location = sl_compiler->get_decoration(
56-
var.self, spv::Decoration::DecorationLocation);
57-
sampler_offsets.push_back(location);
58-
});
59-
if (sampler_offsets.size() > 0) {
60-
auto start_offset =
61-
*std::min_element(sampler_offsets.begin(), sampler_offsets.end());
62-
for (auto offset : sampler_offsets) {
63-
sl_compiler->add_msl_resource_binding({
64-
.stage = spv::ExecutionModel::ExecutionModelFragment,
65-
.basetype = spirv_cross::SPIRType::BaseType::SampledImage,
66-
.binding = offset,
67-
.count = 1u,
68-
.msl_buffer = offset - start_offset,
69-
.msl_texture = offset - start_offset,
70-
.msl_sampler = offset - start_offset,
71-
});
72-
}
59+
// used on other backends when creating shaders.
60+
std::vector<uint32_t> sampler_offsets;
61+
ir.for_each_typed_id<spirv_cross::SPIRVariable>(
62+
[&](uint32_t, const spirv_cross::SPIRVariable& var) {
63+
if (var.storage != spv::StorageClassUniformConstant) {
64+
return;
65+
}
66+
const auto spir_type = sl_compiler->get_type(var.basetype);
67+
if (spir_type.basetype !=
68+
spirv_cross::SPIRType::BaseType::SampledImage) {
69+
return;
70+
}
71+
auto location = sl_compiler->get_decoration(
72+
var.self, spv::Decoration::DecorationLocation);
73+
sampler_offsets.push_back(location);
74+
});
75+
auto stage = SourceTypeToExecutionModel(source_options.type);
76+
if (stage.has_value() && sampler_offsets.size() > 0) {
77+
auto start_offset =
78+
*std::min_element(sampler_offsets.begin(), sampler_offsets.end());
79+
for (auto offset : sampler_offsets) {
80+
sl_compiler->add_msl_resource_binding({
81+
.stage = stage.value(),
82+
.basetype = spirv_cross::SPIRType::BaseType::SampledImage,
83+
.binding = offset,
84+
.count = 1u,
85+
.msl_buffer = offset - start_offset,
86+
.msl_texture = offset - start_offset,
87+
.msl_sampler = offset - start_offset,
88+
});
7389
}
7490
}
7591

impeller/compiler/impellerc_main.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ bool Main(const fml::CommandLine& command_line) {
7373
switches.source_file_name, options.type, options.source_language,
7474
switches.entry_point);
7575
options.json_format = switches.json_format;
76-
options.remap_samplers = switches.remap_samplers;
7776
options.gles_language_version = switches.gles_language_version;
7877

7978
Reflector::Options reflector_options;

impeller/compiler/source_options.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ struct SourceOptions {
2727
uint32_t gles_language_version = 100;
2828
std::vector<std::string> defines;
2929
bool json_format = false;
30-
bool remap_samplers = false;
3130

3231
SourceOptions();
3332

impeller/compiler/switches.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@ void Switches::PrintHelp(std::ostream& stream) {
7171
stream << "[optional] --depfile=<depfile_path>" << std::endl;
7272
stream << "[optional] --gles-language-verision=<number>" << std::endl;
7373
stream << "[optional] --json" << std::endl;
74-
stream << "[optional] --remap-samplers (force metal sampler index to match "
75-
"declared order)"
76-
<< std::endl;
7774
}
7875

7976
Switches::Switches() = default;
@@ -128,7 +125,6 @@ Switches::Switches(const fml::CommandLine& command_line)
128125
command_line.GetOptionValueWithDefault("reflection-cc", "")),
129126
depfile_path(command_line.GetOptionValueWithDefault("depfile", "")),
130127
json_format(command_line.HasOption("json")),
131-
remap_samplers(command_line.HasOption("remap-samplers")),
132128
gles_language_version(
133129
stoi(command_line.GetOptionValueWithDefault("gles-language-version",
134130
"0"))),

impeller/compiler/switches.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ struct Switches {
3232
std::string depfile_path;
3333
std::vector<std::string> defines;
3434
bool json_format;
35-
bool remap_samplers;
3635
SourceLanguage source_language = SourceLanguage::kUnknown;
3736
uint32_t gles_language_version;
3837
std::string entry_point;

0 commit comments

Comments
 (0)