Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSL: Inherit interpolation qualifiers through recursive composites. #2312

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <metal_stdlib>
#include <simd/simd.h>

using namespace metal;

struct Foo
{
float2 M;
float F;
};

struct V
{
Foo foo;
};

struct main0_out
{
float Fo [[color(0)]];
};

struct main0_in
{
float2 m_13_foo_M [[user(locn0), flat]];
float m_13_foo_F [[user(locn1), flat]];
};

fragment main0_out main0(main0_in in [[stage_in]])
{
main0_out out = {};
V _13 = {};
_13.foo.M = in.m_13_foo_M;
_13.foo.F = in.m_13_foo_F;
out.Fo = _13.foo.F;
return out;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <metal_stdlib>
#include <simd/simd.h>

using namespace metal;

struct Foo
{
float2 M;
float F;
};

struct V
{
Foo foo;
};

struct main0_out
{
float Fo [[color(0)]];
};

struct main0_in
{
float2 m_13_foo_M [[user(locn0), flat]];
float m_13_foo_F [[user(locn1), flat]];
};

fragment main0_out main0(main0_in in [[stage_in]])
{
main0_out out = {};
V _13 = {};
_13.foo.M = in.m_13_foo_M;
_13.foo.F = in.m_13_foo_F;
out.Fo = _13.foo.F;
return out;
}

15 changes: 15 additions & 0 deletions shaders-msl/frag/block-io-inherited-interpolation-qualifiers.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#version 450

struct Foo
{
vec2 M;
float F;
};

layout(location = 0) in V { flat Foo foo; };
layout(location = 0) out float Fo;

void main()
{
Fo = foo.F;
}
33 changes: 24 additions & 9 deletions spirv_msl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2921,20 +2921,35 @@ void CompilerMSL::add_composite_member_variable_to_interface_block(StorageClass
uint32_t mbr_idx, InterfaceBlockMeta &meta,
const string &mbr_name_qual,
const string &var_chain_qual,
uint32_t &location, uint32_t &var_mbr_idx)
uint32_t &location, uint32_t &var_mbr_idx,
const Bitset &interpolation_qual)
{
auto &entry_func = get<SPIRFunction>(ir.default_entry_point);

BuiltIn builtin = BuiltInMax;
bool is_builtin = is_member_builtin(var_type, mbr_idx, &builtin);
bool is_flat =
has_member_decoration(var_type.self, mbr_idx, DecorationFlat) || has_decoration(var.self, DecorationFlat);
bool is_noperspective = has_member_decoration(var_type.self, mbr_idx, DecorationNoPerspective) ||
bool is_flat = interpolation_qual.get(DecorationFlat) ||
has_member_decoration(var_type.self, mbr_idx, DecorationFlat) ||
has_decoration(var.self, DecorationFlat);
bool is_noperspective = interpolation_qual.get(DecorationNoPerspective) ||
has_member_decoration(var_type.self, mbr_idx, DecorationNoPerspective) ||
has_decoration(var.self, DecorationNoPerspective);
bool is_centroid = has_member_decoration(var_type.self, mbr_idx, DecorationCentroid) ||
bool is_centroid = interpolation_qual.get(DecorationCentroid) ||
has_member_decoration(var_type.self, mbr_idx, DecorationCentroid) ||
has_decoration(var.self, DecorationCentroid);
bool is_sample =
has_member_decoration(var_type.self, mbr_idx, DecorationSample) || has_decoration(var.self, DecorationSample);
bool is_sample = interpolation_qual.get(DecorationSample) ||
has_member_decoration(var_type.self, mbr_idx, DecorationSample) ||
has_decoration(var.self, DecorationSample);

Bitset inherited_qual;
if (is_flat)
inherited_qual.set(DecorationFlat);
if (is_noperspective)
inherited_qual.set(DecorationNoPerspective);
if (is_centroid)
inherited_qual.set(DecorationCentroid);
if (is_sample)
inherited_qual.set(DecorationSample);

uint32_t mbr_type_id = var_type.member_types[mbr_idx];
auto &mbr_type = get<SPIRType>(mbr_type_id);
Expand Down Expand Up @@ -2998,7 +3013,7 @@ void CompilerMSL::add_composite_member_variable_to_interface_block(StorageClass
add_composite_member_variable_to_interface_block(storage, ib_var_ref, ib_type,
var, mbr_type, sub_mbr_idx,
meta, mbr_name, var_chain,
location, var_mbr_idx);
location, var_mbr_idx, inherited_qual);
// FIXME: Recursive structs and tessellation breaks here.
var_mbr_idx++;
}
Expand Down Expand Up @@ -3684,7 +3699,7 @@ void CompilerMSL::add_variable_to_interface_block(StorageClass storage, const st
add_composite_member_variable_to_interface_block(storage, ib_var_ref, ib_type,
var, var_type, mbr_idx, meta,
mbr_name_qual, var_chain_qual,
location, var_mbr_idx);
location, var_mbr_idx, {});
}
else
{
Expand Down
3 changes: 2 additions & 1 deletion spirv_msl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,8 @@ class CompilerMSL : public CompilerGLSL
uint32_t mbr_idx, InterfaceBlockMeta &meta,
const std::string &mbr_name_qual,
const std::string &var_chain_qual,
uint32_t &location, uint32_t &var_mbr_idx);
uint32_t &location, uint32_t &var_mbr_idx,
const Bitset &interpolation_qual);
void add_tess_level_input_to_interface_block(const std::string &ib_var_ref, SPIRType &ib_type, SPIRVariable &var);
void add_tess_level_input(const std::string &base_ref, const std::string &mbr_name, SPIRVariable &var);

Expand Down
Loading