Test implicit packing of struct members.

This commit is contained in:
Hans-Kristian Arntzen 2019-07-23 12:04:15 +02:00
parent 46e757b278
commit 978253c804
2 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,27 @@
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct Foo
{
packed_float3 a;
};
struct Bar
{
packed_float3 a;
};
struct SSBOScalar
{
Foo foo;
Bar bar;
};
kernel void main0(device SSBOScalar& buffer_scalar [[buffer(0)]])
{
buffer_scalar.foo.a[0u] = 10.0;
buffer_scalar.bar.a[0u] = 20.0;
}

View File

@ -0,0 +1,27 @@
#version 450
#extension GL_EXT_scalar_block_layout : require
layout(local_size_x = 1) in;
// Foo will be marked packed_float3 because offset of bar is just 12 bytes after foo.
struct Foo
{
vec3 a;
};
// Bar will be marked as packed due to alignment of the struct itself cannot work without packed.
struct Bar
{
vec3 a;
};
layout(scalar, set = 0, binding = 0) buffer SSBOScalar
{
Foo foo;
Bar bar;
} buffer_scalar;
void main()
{
buffer_scalar.foo.a.x = 10.0;
buffer_scalar.bar.a.x = 20.0;
}