Skip to content

Commit

Permalink
MSL: Add test for bool-in-struct edge cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
HansKristian-Work committed Jun 6, 2023
1 parent bbcd8de commit b0b2fd8
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 0 deletions.
98 changes: 98 additions & 0 deletions reference/shaders-msl-no-opt/frag/struct-bool-edge-cases.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#pragma clang diagnostic ignored "-Wmissing-prototypes"
#pragma clang diagnostic ignored "-Wmissing-braces"

#include <metal_stdlib>
#include <simd/simd.h>

using namespace metal;

template<typename T, size_t Num>
struct spvUnsafeArray
{
T elements[Num ? Num : 1];

thread T& operator [] (size_t pos) thread
{
return elements[pos];
}
constexpr const thread T& operator [] (size_t pos) const thread
{
return elements[pos];
}

device T& operator [] (size_t pos) device
{
return elements[pos];
}
constexpr const device T& operator [] (size_t pos) const device
{
return elements[pos];
}

constexpr const constant T& operator [] (size_t pos) const constant
{
return elements[pos];
}

threadgroup T& operator [] (size_t pos) threadgroup
{
return elements[pos];
}
constexpr const threadgroup T& operator [] (size_t pos) const threadgroup
{
return elements[pos];
}
};

struct Test
{
short a;
short2 b;
short3 c;
short4 d;
};

struct Test2
{
spvUnsafeArray<short, 2> a;
spvUnsafeArray<short2, 2> b;
spvUnsafeArray<short3, 2> c;
spvUnsafeArray<short4, 2> d;
Test e;
};

constant spvUnsafeArray<bool, 2> _40 = spvUnsafeArray<bool, 2>({ true, false });
constant spvUnsafeArray<bool2, 2> _44 = spvUnsafeArray<bool2, 2>({ bool2(true, false), bool2(false, true) });
constant spvUnsafeArray<bool3, 2> _48 = spvUnsafeArray<bool3, 2>({ bool3(true, false, true), bool3(false, true, false) });
constant spvUnsafeArray<bool4, 2> _52 = spvUnsafeArray<bool4, 2>({ bool4(true, false, true, false), bool4(false, true, false, true) });
constant spvUnsafeArray<bool, 2> _82 = spvUnsafeArray<bool, 2>({ true, true });
constant spvUnsafeArray<bool2, 2> _85 = spvUnsafeArray<bool2, 2>({ bool2(true), bool2(false) });
constant spvUnsafeArray<bool3, 2> _87 = spvUnsafeArray<bool3, 2>({ bool3(true), bool3(false) });
constant spvUnsafeArray<bool4, 2> _89 = spvUnsafeArray<bool4, 2>({ bool4(true), bool4(false) });

fragment void main0()
{
spvUnsafeArray<Test, 2> _95 = spvUnsafeArray<Test, 2>({ Test{ true, bool2(true, false), bool3(true), bool4(false) }, Test{ false, bool2(false, true), bool3(false), bool4(true) } });

Test t;
t.a = short(true);
t.b = short2(bool2(true, false));
t.c = short3(bool3(true, false, true));
t.d = short4(bool4(true, false, true, false));
Test2 t2;
t2.a = { short(_40[0]), short(_40[1]) };
t2.b = { short2(_44[0]), short2(_44[1]) };
t2.c = { short3(_48[0]), short3(_48[1]) };
t2.d = { short4(_52[0]), short4(_52[1]) };
bool a = bool(t.a);
bool2 b = bool2(t.b);
bool3 c = bool3(t.c);
bool4 d = bool4(t.d);
spvUnsafeArray<bool, 2> a2 = { bool(t2.a[0]), bool(t2.a[1]) };
spvUnsafeArray<bool2, 2> b2 = { bool2(t2.b[0]), bool2(t2.b[1]) };
spvUnsafeArray<bool3, 2> c2 = { bool3(t2.c[0]), bool3(t2.c[1]) };
spvUnsafeArray<bool4, 2> d2 = { bool4(t2.d[0]), bool4(t2.d[1]) };
t = Test{ true, bool2(true, false), bool3(true), bool4(false) };
t2 = Test2{ spvUnsafeArray<bool, 2>({ true, true }), spvUnsafeArray<bool2, 2>({ bool2(true), bool2(false) }), spvUnsafeArray<bool3, 2>({ bool3(true), bool3(false) }), spvUnsafeArray<bool4, 2>({ bool4(true), bool4(false) }), Test{ true, bool2(true, false), bool3(true), bool4(false) } };
}

58 changes: 58 additions & 0 deletions shaders-msl-no-opt/frag/struct-bool-edge-cases.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#version 450

layout(location = 0) out float FragColor;

struct Test
{
bool a;
bvec2 b;
bvec3 c;
bvec4 d;
};

struct Test2
{
bool a[2];
bvec2 b[2];
bvec3 c[2];
bvec4 d[2];
Test e;
};

void main()
{
Test t;
Test2 t2;

t.a = true;
t.b = bvec2(true, false);
t.c = bvec3(true, false, true);
t.d = bvec4(true, false, true, false);

t2.a = bool[](true, false);
t2.b = bvec2[](bvec2(true, false), bvec2(false, true));
t2.c = bvec3[](bvec3(true, false, true), bvec3(false, true, false));
t2.d = bvec4[](bvec4(true, false, true, false), bvec4(false, true, false, true));

bool a = t.a;
bvec2 b = t.b;
bvec3 c = t.c;
bvec4 d = t.d;

bool a2[2] = t2.a;
bvec2 b2[2] = t2.b;
bvec3 c2[2] = t2.c;
bvec4 d2[2] = t2.d;

t = Test(true, bvec2(true, false), bvec3(true), bvec4(false));
t2 = Test2(
bool[](true, true),
bvec2[](bvec2(true), bvec2(false)),
bvec3[](bvec3(true), bvec3(false)),
bvec4[](bvec4(true), bvec4(false)),
Test(true, bvec2(true, false), bvec3(true), bvec4(false)));

Test t3[2] = Test[](
Test(true, bvec2(true, false), bvec3(true), bvec4(false)),
Test(false, bvec2(false, true), bvec3(false), bvec4(true)));
}

0 comments on commit b0b2fd8

Please sign in to comment.