7
7
#include " impeller/compiler/reflector.h"
8
8
9
9
#include < atomic>
10
+ #include < limits>
10
11
#include < optional>
11
12
#include < set>
12
13
#include < sstream>
@@ -216,9 +217,9 @@ std::optional<nlohmann::json> Reflector::GenerateTemplateArguments() const {
216
217
if (auto storage_buffers_json =
217
218
ReflectResources (shader_resources.storage_buffers );
218
219
storage_buffers_json.has_value ()) {
219
- for (auto uniform_buffer : storage_buffers_json.value ()) {
220
- uniform_buffer [" descriptor_type" ] = " DescriptorType::kStorageBuffer" ;
221
- buffers.emplace_back (std::move (uniform_buffer ));
220
+ for (auto storage_buffer : storage_buffers_json.value ()) {
221
+ storage_buffer [" descriptor_type" ] = " DescriptorType::kStorageBuffer" ;
222
+ buffers.emplace_back (std::move (storage_buffer ));
222
223
}
223
224
} else {
224
225
return std::nullopt ;
@@ -261,6 +262,19 @@ std::optional<nlohmann::json> Reflector::GenerateTemplateArguments() const {
261
262
}
262
263
}
263
264
265
+ {
266
+ if (auto inputs = ReflectResources (shader_resources.subpass_inputs );
267
+ inputs.has_value ()) {
268
+ auto & subpass_inputs = root[" subpass_inputs" ] = nlohmann::json::array_t {};
269
+ for (auto input : inputs.value ()) {
270
+ input[" descriptor_type" ] = " DescriptorType::kSubpassInput" ;
271
+ subpass_inputs.emplace_back (std::move (input));
272
+ }
273
+ } else {
274
+ return std::nullopt ;
275
+ }
276
+ }
277
+
264
278
if (auto stage_outputs = ReflectResources (shader_resources.stage_outputs );
265
279
stage_outputs.has_value ()) {
266
280
root[" stage_outputs" ] = std::move (stage_outputs.value ());
@@ -431,6 +445,14 @@ std::vector<size_t> Reflector::ComputeOffsets(
431
445
return offsets;
432
446
}
433
447
448
+ static uint32_t GetResourceDecorationIfPresent (const CompilerBackend& compiler,
449
+ spirv_cross::ID id,
450
+ spv::Decoration decoration) {
451
+ return compiler->has_decoration (id, decoration)
452
+ ? compiler->get_decoration (id, decoration)
453
+ : std::numeric_limits<uint32_t >::max ();
454
+ }
455
+
434
456
std::optional<nlohmann::json::object_t > Reflector::ReflectResource (
435
457
const spirv_cross::Resource& resource,
436
458
std::optional<size_t > offset) const {
@@ -445,6 +467,8 @@ std::optional<nlohmann::json::object_t> Reflector::ReflectResource(
445
467
resource.id , spv::Decoration::DecorationDescriptorSet);
446
468
result[" location" ] = compiler_->get_decoration (
447
469
resource.id , spv::Decoration::DecorationLocation);
470
+ result[" input_attachment_index" ] = GetResourceDecorationIfPresent (
471
+ compiler_, resource.id , spv::Decoration::DecorationInputAttachmentIndex);
448
472
result[" index" ] =
449
473
compiler_->get_decoration (resource.id , spv::Decoration::DecorationIndex);
450
474
result[" ext_res_0" ] = compiler_.GetExtendedMSLResourceBinding (
0 commit comments