Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/KhronosGroup/SPIRV-Cross.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Hollings <bill.hollings@brenwill.com>2020-10-30 01:50:42 +0300
committerBill Hollings <bill.hollings@brenwill.com>2020-10-30 01:50:42 +0300
commitb7b0e804e5f3509c7bd8aaef806d955c0731d33f (patch)
tree3c7fabfb920f94f93dcb2e06fb8bf99f8d9442da /spirv_msl.cpp
parent78c6d2d62897e700f7f6bbd6289ff22245058ed7 (diff)
MSL: Support run-time sized image and sampler arrays
(GL_EXT_nonuniform_qualifier/SPV_EXT_descriptor_indexing). MSLResourceBinding includes array size through API, and substitutes in that size if the image or sampler array is not explicitly sized. OpCopyObject supports SPIRCombinedImageSampler type in MSL.
Diffstat (limited to 'spirv_msl.cpp')
-rw-r--r--spirv_msl.cpp34
1 files changed, 29 insertions, 5 deletions
diff --git a/spirv_msl.cpp b/spirv_msl.cpp
index 2fc7df10..499d723a 100644
--- a/spirv_msl.cpp
+++ b/spirv_msl.cpp
@@ -103,6 +103,15 @@ bool CompilerMSL::is_msl_resource_binding_used(ExecutionModel model, uint32_t de
return itr != end(resource_bindings) && itr->second.second;
}
+uint32_t CompilerMSL::get_resource_array_size(uint32_t id) const
+{
+ StageSetBinding tuple = { get_entry_point().model,
+ get_decoration(id, DecorationDescriptorSet),
+ get_decoration(id, DecorationBinding) };
+ auto itr = resource_bindings.find(tuple);
+ return itr != end(resource_bindings) ? itr->second.first.size : 0;
+}
+
uint32_t CompilerMSL::get_automatic_msl_resource_binding(uint32_t id) const
{
return get_extended_decoration(id, SPIRVCrossDecorationResourceIndexPrimary);
@@ -8136,7 +8145,7 @@ void CompilerMSL::emit_function_prototype(SPIRFunction &func, const Bitset &)
// Manufacture automatic sampler arg for SampledImage texture
if (arg_type.image.dim != DimBuffer)
- decl += join(", thread const ", sampler_type(arg_type), " ", to_sampler_expression(arg.id));
+ decl += join(", thread const ", sampler_type(arg_type, arg.id), " ", to_sampler_expression(arg.id));
}
// Manufacture automatic swizzle arg.
@@ -10449,7 +10458,7 @@ void CompilerMSL::entry_point_args_discrete_descriptors(string &ep_args)
case SPIRType::Sampler:
if (!ep_args.empty())
ep_args += ", ";
- ep_args += sampler_type(type) + " " + r.name;
+ ep_args += sampler_type(type, var_id) + " " + r.name;
ep_args += " [[sampler(" + convert_to_string(r.index) + ")]]";
break;
case SPIRType::Image:
@@ -11702,7 +11711,7 @@ string CompilerMSL::type_to_glsl(const SPIRType &type, uint32_t id)
return image_type_glsl(type, id);
case SPIRType::Sampler:
- return sampler_type(type);
+ return sampler_type(type, id);
case SPIRType::Void:
return "void";
@@ -11833,8 +11842,15 @@ std::string CompilerMSL::variable_decl(const SPIRType &type, const std::string &
return CompilerGLSL::variable_decl(type, name, id);
}
-std::string CompilerMSL::sampler_type(const SPIRType &type)
+std::string CompilerMSL::sampler_type(const SPIRType &type, uint32_t id)
{
+ auto *var = maybe_get<SPIRVariable>(id);
+ if (var && var->basevariable)
+ {
+ // Check against the base variable, and not a fake ID which might have been generated for this variable.
+ id = var->basevariable;
+ }
+
if (!type.array.empty())
{
if (!msl_options.supports_msl_version(2))
@@ -11844,12 +11860,16 @@ std::string CompilerMSL::sampler_type(const SPIRType &type)
SPIRV_CROSS_THROW("Arrays of arrays of samplers are not supported in MSL.");
// Arrays of samplers in MSL must be declared with a special array<T, N> syntax ala C++11 std::array.
+ // If we have a runtime array, it could be a variable-count descriptor set binding.
uint32_t array_size = to_array_size_literal(type);
if (array_size == 0)
+ array_size = get_resource_array_size(id);
+
+ if (array_size == 0)
SPIRV_CROSS_THROW("Unsized array of samplers is not supported in MSL.");
auto &parent = get<SPIRType>(get_pointee_type(type).parent_type);
- return join("array<", sampler_type(parent), ", ", array_size, ">");
+ return join("array<", sampler_type(parent, id), ", ", array_size, ">");
}
else
return "sampler";
@@ -11886,8 +11906,12 @@ string CompilerMSL::image_type_glsl(const SPIRType &type, uint32_t id)
SPIRV_CROSS_THROW("Arrays of arrays of textures are not supported in MSL.");
// Arrays of images in MSL must be declared with a special array<T, N> syntax ala C++11 std::array.
+ // If we have a runtime array, it could be a variable-count descriptor set binding.
uint32_t array_size = to_array_size_literal(type);
if (array_size == 0)
+ array_size = get_resource_array_size(id);
+
+ if (array_size == 0)
SPIRV_CROSS_THROW("Unsized array of images is not supported in MSL.");
auto &parent = get<SPIRType>(get_pointee_type(type).parent_type);