MSL: Always use input_attachment_index for framebuffer fetch binding.

--msl-decoration-binding would end up overriding the input attachment
index to binding which is very unexpected and broken.
This commit is contained in:
Hans-Kristian Arntzen 2021-01-07 14:30:35 +01:00
parent 134a520034
commit 3136e34215
4 changed files with 49 additions and 11 deletions

View File

@ -0,0 +1,23 @@
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct spvDescriptorSetBuffer0
{
sampler uSampler [[id(8)]];
texture2d<float> uTex [[id(9)]];
};
struct main0_out
{
float4 FragColor [[color(0)]];
};
fragment main0_out main0(constant spvDescriptorSetBuffer0& spvDescriptorSet0 [[buffer(0)]], float4 uSub [[color(1)]])
{
main0_out out = {};
out.FragColor = uSub + spvDescriptorSet0.uTex.sample(spvDescriptorSet0.uSampler, float2(0.5));
return out;
}

View File

@ -0,0 +1,12 @@
#version 450
layout(set = 0, binding = 10, input_attachment_index = 1) uniform subpassInput uSub;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 9) uniform texture2D uTex;
layout(set = 0, binding = 8) uniform sampler uSampler;
void main()
{
FragColor = subpassLoad(uSub) + texture(sampler2D(uTex, uSampler), vec2(0.5));
}

View File

@ -11723,10 +11723,18 @@ uint32_t CompilerMSL::get_metal_resource_index(SPIRVariable &var, SPIRType::Base
if (has_extended_decoration(var.self, resource_decoration))
return get_extended_decoration(var.self, resource_decoration);
// Allow user to enable decoration binding
if (msl_options.enable_decoration_binding)
auto &type = get<SPIRType>(var.basetype);
if (type_is_msl_framebuffer_fetch(type))
{
// If there is no explicit mapping of bindings to MSL, use the declared binding.
// Frame-buffer fetch gets its fallback resource index from the input attachment index,
// which is then treated as color index.
return get_decoration(var.self, DecorationInputAttachmentIndex);
}
else if (msl_options.enable_decoration_binding)
{
// Allow user to enable decoration binding.
// If there is no explicit mapping of bindings to MSL, use the declared binding as a fallback.
if (has_decoration(var.self, DecorationBinding))
{
var_binding = get_decoration(var.self, DecorationBinding);
@ -11745,7 +11753,6 @@ uint32_t CompilerMSL::get_metal_resource_index(SPIRVariable &var, SPIRType::Base
allocate_argument_buffer_ids = descriptor_set_is_argument_buffer(var_desc_set);
uint32_t binding_stride = 1;
auto &type = get<SPIRType>(var.basetype);
for (uint32_t i = 0; i < uint32_t(type.array.size()); i++)
binding_stride *= to_array_size_literal(type, i);
@ -11754,13 +11761,7 @@ uint32_t CompilerMSL::get_metal_resource_index(SPIRVariable &var, SPIRType::Base
// If a binding has not been specified, revert to incrementing resource indices.
uint32_t resource_index;
if (type_is_msl_framebuffer_fetch(type))
{
// Frame-buffer fetch gets its fallback resource index from the input attachment index,
// which is then treated as color index.
resource_index = get_decoration(var.self, DecorationInputAttachmentIndex);
}
else if (allocate_argument_buffer_ids)
if (allocate_argument_buffer_ids)
{
// Allocate from a flat ID binding space.
resource_index = next_metal_resource_ids[var_desc_set];

View File

@ -321,6 +321,8 @@ def cross_compile_msl(shader, spirv, opt, iterations, paths):
msl_args.append('32')
if '.force-sample.' in shader:
msl_args.append('--msl-force-sample-rate-shading')
if '.decoration-binding.' in shader:
msl_args.append('--msl-decoration-binding')
subprocess.check_call(msl_args)