-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] Patch the compiler to account for subpass inputs and PSO metadata. #45739
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,15 +115,13 @@ static CompilerBackend CreateMSLCompiler( | |
static CompilerBackend CreateVulkanCompiler( | ||
const spirv_cross::ParsedIR& ir, | ||
const SourceOptions& source_options) { | ||
// TODO(dnfield): It seems like what we'd want is a CompilerGLSL with | ||
// vulkan_semantics set to true, but that has regressed some things on GLES | ||
// somehow. In the mean time, go back to using CompilerMSL, but set the Metal | ||
// Language version to something really high so that we don't get weird | ||
// complaints about using Metal features while trying to build Vulkan shaders. | ||
// https://github.com/flutter/flutter/issues/123795 | ||
return CreateMSLCompiler( | ||
ir, source_options, | ||
spirv_cross::CompilerMSL::Options::make_msl_version(3, 0, 0)); | ||
auto vk_compiler = std::make_shared<spirv_cross::CompilerGLSL>(ir); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we know how this change had previously broken GLES and how this changed fixed it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original issue was light on details but there is now a separate |
||
spirv_cross::CompilerGLSL::Options sl_options; | ||
sl_options.vulkan_semantics = true; | ||
sl_options.force_zero_initialized_variables = true; | ||
sl_options.es = false; | ||
vk_compiler->set_common_options(sl_options); | ||
return CompilerBackend(vk_compiler); | ||
} | ||
|
||
static CompilerBackend CreateGLSLCompiler(const spirv_cross::ParsedIR& ir, | ||
|
@@ -218,6 +216,7 @@ static CompilerBackend CreateCompiler(const spirv_cross::ParsedIR& ir, | |
break; | ||
case TargetPlatform::kSkSL: | ||
compiler = CreateSkSLCompiler(ir, source_options); | ||
break; | ||
} | ||
if (!compiler) { | ||
return {}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
#include "impeller/compiler/reflector.h" | ||
|
||
#include <atomic> | ||
#include <limits> | ||
#include <optional> | ||
#include <set> | ||
#include <sstream> | ||
|
@@ -216,9 +217,9 @@ std::optional<nlohmann::json> Reflector::GenerateTemplateArguments() const { | |
if (auto storage_buffers_json = | ||
ReflectResources(shader_resources.storage_buffers); | ||
storage_buffers_json.has_value()) { | ||
for (auto uniform_buffer : storage_buffers_json.value()) { | ||
uniform_buffer["descriptor_type"] = "DescriptorType::kStorageBuffer"; | ||
buffers.emplace_back(std::move(uniform_buffer)); | ||
for (auto storage_buffer : storage_buffers_json.value()) { | ||
storage_buffer["descriptor_type"] = "DescriptorType::kStorageBuffer"; | ||
buffers.emplace_back(std::move(storage_buffer)); | ||
} | ||
} else { | ||
return std::nullopt; | ||
|
@@ -261,6 +262,19 @@ std::optional<nlohmann::json> Reflector::GenerateTemplateArguments() const { | |
} | ||
} | ||
|
||
{ | ||
if (auto inputs = ReflectResources(shader_resources.subpass_inputs); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, convenient! |
||
inputs.has_value()) { | ||
auto& subpass_inputs = root["subpass_inputs"] = nlohmann::json::array_t{}; | ||
for (auto input : inputs.value()) { | ||
input["descriptor_type"] = "DescriptorType::kSubpassInput"; | ||
subpass_inputs.emplace_back(std::move(input)); | ||
} | ||
} else { | ||
return std::nullopt; | ||
} | ||
} | ||
|
||
if (auto stage_outputs = ReflectResources(shader_resources.stage_outputs); | ||
stage_outputs.has_value()) { | ||
root["stage_outputs"] = std::move(stage_outputs.value()); | ||
|
@@ -431,6 +445,14 @@ std::vector<size_t> Reflector::ComputeOffsets( | |
return offsets; | ||
} | ||
|
||
static uint32_t GetResourceDecorationIfPresent(const CompilerBackend& compiler, | ||
spirv_cross::ID id, | ||
spv::Decoration decoration) { | ||
return compiler->has_decoration(id, decoration) | ||
? compiler->get_decoration(id, decoration) | ||
: std::numeric_limits<uint32_t>::max(); | ||
} | ||
|
||
std::optional<nlohmann::json::object_t> Reflector::ReflectResource( | ||
const spirv_cross::Resource& resource, | ||
std::optional<size_t> offset) const { | ||
|
@@ -445,6 +467,8 @@ std::optional<nlohmann::json::object_t> Reflector::ReflectResource( | |
resource.id, spv::Decoration::DecorationDescriptorSet); | ||
result["location"] = compiler_->get_decoration( | ||
resource.id, spv::Decoration::DecorationLocation); | ||
result["input_attachment_index"] = GetResourceDecorationIfPresent( | ||
compiler_, resource.id, spv::Decoration::DecorationInputAttachmentIndex); | ||
result["index"] = | ||
compiler_->get_decoration(resource.id, spv::Decoration::DecorationIndex); | ||
result["ext_res_0"] = compiler_.GetExtendedMSLResourceBinding( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Keep default to SourceOver? Although advanced blends are more contentious, so maybe someone flipping through is more likely to notice a problem with Screen as the default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, just thought defaulting to the advanced ones was more likely to throw up issues.