-
Notifications
You must be signed in to change notification settings - Fork 994
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: test(naga): add
struct-layout
test
* TODO: Anything left to test here?
- Loading branch information
1 parent
5c8cffb
commit 145464b
Showing
11 changed files
with
604 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Create several type definitions to test `align` and `size` layout. | ||
|
||
struct NoPadding { | ||
@location(0) | ||
v3: vec3f, // align 16, size 12; no start padding needed | ||
@location(1) | ||
f3: f32, // align 4, size 4; no start padding needed | ||
} | ||
@fragment | ||
fn no_padding_frag(input: NoPadding) -> @location(0) vec4f { | ||
_ = input; | ||
return vec4f(0.0); | ||
} | ||
@vertex | ||
fn no_padding_vert(input: NoPadding) -> @builtin(position) vec4f { | ||
_ = input; | ||
return vec4f(0.0); | ||
} | ||
@group(0) @binding(0) var<uniform> no_padding_uniform: NoPadding; | ||
@group(0) @binding(1) var<storage, read_write> no_padding_storage: NoPadding; | ||
@compute @workgroup_size(16,1,1) | ||
fn no_padding_comp() { | ||
var x: NoPadding; | ||
x = no_padding_uniform; | ||
x = no_padding_storage; | ||
} | ||
|
||
struct NeedsPadding { | ||
@location(0) f3_forces_padding: f32, // align 4, size 4; no start padding needed | ||
@location(1) v3_needs_padding: vec3f, // align 16, size 12; needs 12 bytes of padding | ||
@location(2) f3: f32, // align 4, size 4; no start padding needed | ||
} | ||
@fragment | ||
fn needs_padding_frag(input: NeedsPadding) -> @location(0) vec4f { | ||
_ = input; | ||
return vec4f(0.0); | ||
} | ||
@vertex | ||
fn needs_padding_vert(input: NeedsPadding) -> @builtin(position) vec4f { | ||
_ = input; | ||
return vec4f(0.0); | ||
} | ||
@group(0) @binding(2) var<uniform> needs_padding_uniform: NeedsPadding; | ||
@group(0) @binding(3) var<storage, read_write> needs_padding_storage: NeedsPadding; | ||
@compute @workgroup_size(16,1,1) | ||
fn needs_padding_comp() { | ||
var x: NeedsPadding; | ||
x = needs_padding_uniform; | ||
x = needs_padding_storage; | ||
} |
25 changes: 25 additions & 0 deletions
25
naga/tests/out/glsl/struct-layout.needs_padding_frag.Fragment.glsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#version 310 es | ||
|
||
precision highp float; | ||
precision highp int; | ||
|
||
struct NoPadding { | ||
vec3 v3_; | ||
float f3_; | ||
}; | ||
struct NeedsPadding { | ||
float f3_forces_padding; | ||
vec3 v3_needs_padding; | ||
float f3_; | ||
}; | ||
layout(location = 0) smooth in float _vs2fs_location0; | ||
layout(location = 1) smooth in vec3 _vs2fs_location1; | ||
layout(location = 2) smooth in float _vs2fs_location2; | ||
layout(location = 0) out vec4 _fs2p_location0; | ||
|
||
void main() { | ||
NeedsPadding input_2 = NeedsPadding(_vs2fs_location0, _vs2fs_location1, _vs2fs_location2); | ||
_fs2p_location0 = vec4(0.0); | ||
return; | ||
} | ||
|
25 changes: 25 additions & 0 deletions
25
naga/tests/out/glsl/struct-layout.needs_padding_vert.Vertex.glsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#version 310 es | ||
|
||
precision highp float; | ||
precision highp int; | ||
|
||
struct NoPadding { | ||
vec3 v3_; | ||
float f3_; | ||
}; | ||
struct NeedsPadding { | ||
float f3_forces_padding; | ||
vec3 v3_needs_padding; | ||
float f3_; | ||
}; | ||
layout(location = 0) in float _p2vs_location0; | ||
layout(location = 1) in vec3 _p2vs_location1; | ||
layout(location = 2) in float _p2vs_location2; | ||
|
||
void main() { | ||
NeedsPadding input_3 = NeedsPadding(_p2vs_location0, _p2vs_location1, _p2vs_location2); | ||
gl_Position = vec4(0.0); | ||
gl_Position.yz = vec2(-gl_Position.y, gl_Position.z * 2.0 - gl_Position.w); | ||
return; | ||
} | ||
|
24 changes: 24 additions & 0 deletions
24
naga/tests/out/glsl/struct-layout.no_padding_frag.Fragment.glsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#version 310 es | ||
|
||
precision highp float; | ||
precision highp int; | ||
|
||
struct NoPadding { | ||
vec3 v3_; | ||
float f3_; | ||
}; | ||
struct NeedsPadding { | ||
float f3_forces_padding; | ||
vec3 v3_needs_padding; | ||
float f3_; | ||
}; | ||
layout(location = 0) smooth in vec3 _vs2fs_location0; | ||
layout(location = 1) smooth in float _vs2fs_location1; | ||
layout(location = 0) out vec4 _fs2p_location0; | ||
|
||
void main() { | ||
NoPadding input_ = NoPadding(_vs2fs_location0, _vs2fs_location1); | ||
_fs2p_location0 = vec4(0.0); | ||
return; | ||
} | ||
|
24 changes: 24 additions & 0 deletions
24
naga/tests/out/glsl/struct-layout.no_padding_vert.Vertex.glsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#version 310 es | ||
|
||
precision highp float; | ||
precision highp int; | ||
|
||
struct NoPadding { | ||
vec3 v3_; | ||
float f3_; | ||
}; | ||
struct NeedsPadding { | ||
float f3_forces_padding; | ||
vec3 v3_needs_padding; | ||
float f3_; | ||
}; | ||
layout(location = 0) in vec3 _p2vs_location0; | ||
layout(location = 1) in float _p2vs_location1; | ||
|
||
void main() { | ||
NoPadding input_1 = NoPadding(_p2vs_location0, _p2vs_location1); | ||
gl_Position = vec4(0.0); | ||
gl_Position.yz = vec2(-gl_Position.y, gl_Position.z * 2.0 - gl_Position.w); | ||
return; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
struct NoPadding { | ||
float3 v3_ : LOC0; | ||
float f3_ : LOC1; | ||
}; | ||
|
||
struct NeedsPadding { | ||
float f3_forces_padding : LOC0; | ||
float3 v3_needs_padding : LOC1; | ||
float f3_ : LOC2; | ||
}; | ||
|
||
cbuffer no_padding_uniform : register(b0) { NoPadding no_padding_uniform; } | ||
RWByteAddressBuffer no_padding_storage : register(u1); | ||
cbuffer needs_padding_uniform : register(b2) { NeedsPadding needs_padding_uniform; } | ||
RWByteAddressBuffer needs_padding_storage : register(u3); | ||
|
||
struct FragmentInput_no_padding_frag { | ||
float3 v3_ : LOC0; | ||
float f3_ : LOC1; | ||
}; | ||
|
||
struct FragmentInput_needs_padding_frag { | ||
float f3_forces_padding : LOC0; | ||
float3 v3_needs_padding : LOC1; | ||
float f3_1 : LOC2; | ||
}; | ||
|
||
float4 no_padding_frag(FragmentInput_no_padding_frag fragmentinput_no_padding_frag) : SV_Target0 | ||
{ | ||
NoPadding input = { fragmentinput_no_padding_frag.v3_, fragmentinput_no_padding_frag.f3_ }; | ||
return (0.0).xxxx; | ||
} | ||
|
||
float4 no_padding_vert(NoPadding input_1) : SV_Position | ||
{ | ||
return (0.0).xxxx; | ||
} | ||
|
||
NoPadding ConstructNoPadding(float3 arg0, float arg1) { | ||
NoPadding ret = (NoPadding)0; | ||
ret.v3_ = arg0; | ||
ret.f3_ = arg1; | ||
return ret; | ||
} | ||
|
||
[numthreads(16, 1, 1)] | ||
void no_padding_comp() | ||
{ | ||
NoPadding x = (NoPadding)0; | ||
|
||
NoPadding _expr2 = no_padding_uniform; | ||
x = _expr2; | ||
NoPadding _expr4 = ConstructNoPadding(asfloat(no_padding_storage.Load3(0)), asfloat(no_padding_storage.Load(12))); | ||
x = _expr4; | ||
return; | ||
} | ||
|
||
float4 needs_padding_frag(FragmentInput_needs_padding_frag fragmentinput_needs_padding_frag) : SV_Target0 | ||
{ | ||
NeedsPadding input_2 = { fragmentinput_needs_padding_frag.f3_forces_padding, fragmentinput_needs_padding_frag.v3_needs_padding, fragmentinput_needs_padding_frag.f3_1 }; | ||
return (0.0).xxxx; | ||
} | ||
|
||
float4 needs_padding_vert(NeedsPadding input_3) : SV_Position | ||
{ | ||
return (0.0).xxxx; | ||
} | ||
|
||
NeedsPadding ConstructNeedsPadding(float arg0, float3 arg1, float arg2) { | ||
NeedsPadding ret = (NeedsPadding)0; | ||
ret.f3_forces_padding = arg0; | ||
ret.v3_needs_padding = arg1; | ||
ret.f3_ = arg2; | ||
return ret; | ||
} | ||
|
||
[numthreads(16, 1, 1)] | ||
void needs_padding_comp() | ||
{ | ||
NeedsPadding x_1 = (NeedsPadding)0; | ||
|
||
NeedsPadding _expr2 = needs_padding_uniform; | ||
x_1 = _expr2; | ||
NeedsPadding _expr4 = ConstructNeedsPadding(asfloat(needs_padding_storage.Load(0)), asfloat(needs_padding_storage.Load3(16)), asfloat(needs_padding_storage.Load(28))); | ||
x_1 = _expr4; | ||
return; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
( | ||
vertex:[ | ||
( | ||
entry_point:"no_padding_vert", | ||
target_profile:"vs_5_1", | ||
), | ||
( | ||
entry_point:"needs_padding_vert", | ||
target_profile:"vs_5_1", | ||
), | ||
], | ||
fragment:[ | ||
( | ||
entry_point:"no_padding_frag", | ||
target_profile:"ps_5_1", | ||
), | ||
( | ||
entry_point:"needs_padding_frag", | ||
target_profile:"ps_5_1", | ||
), | ||
], | ||
compute:[ | ||
( | ||
entry_point:"no_padding_comp", | ||
target_profile:"cs_5_1", | ||
), | ||
( | ||
entry_point:"needs_padding_comp", | ||
target_profile:"cs_5_1", | ||
), | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// language: metal1.0 | ||
#include <metal_stdlib> | ||
#include <simd/simd.h> | ||
|
||
using metal::uint; | ||
|
||
struct NoPadding { | ||
metal::packed_float3 v3_; | ||
float f3_; | ||
}; | ||
struct NeedsPadding { | ||
float f3_forces_padding; | ||
char _pad1[12]; | ||
metal::packed_float3 v3_needs_padding; | ||
float f3_; | ||
}; | ||
|
||
struct no_padding_fragInput { | ||
metal::float3 v3_ [[user(loc0), center_perspective]]; | ||
float f3_ [[user(loc1), center_perspective]]; | ||
}; | ||
struct no_padding_fragOutput { | ||
metal::float4 member [[color(0)]]; | ||
}; | ||
fragment no_padding_fragOutput no_padding_frag( | ||
no_padding_fragInput varyings [[stage_in]] | ||
) { | ||
const NoPadding input = { varyings.v3_, varyings.f3_ }; | ||
return no_padding_fragOutput { metal::float4(0.0) }; | ||
} | ||
|
||
|
||
struct no_padding_vertInput { | ||
metal::float3 v3_ [[attribute(0)]]; | ||
float f3_ [[attribute(1)]]; | ||
}; | ||
struct no_padding_vertOutput { | ||
metal::float4 member_1 [[position]]; | ||
}; | ||
vertex no_padding_vertOutput no_padding_vert( | ||
no_padding_vertInput varyings_1 [[stage_in]] | ||
) { | ||
const NoPadding input_1 = { varyings_1.v3_, varyings_1.f3_ }; | ||
return no_padding_vertOutput { metal::float4(0.0) }; | ||
} | ||
|
||
|
||
kernel void no_padding_comp( | ||
constant NoPadding& no_padding_uniform [[user(fake0)]] | ||
, device NoPadding const& no_padding_storage [[user(fake0)]] | ||
) { | ||
NoPadding x = {}; | ||
NoPadding _e2 = no_padding_uniform; | ||
x = _e2; | ||
NoPadding _e4 = no_padding_storage; | ||
x = _e4; | ||
return; | ||
} | ||
|
||
|
||
struct needs_padding_fragInput { | ||
float f3_forces_padding [[user(loc0), center_perspective]]; | ||
metal::float3 v3_needs_padding [[user(loc1), center_perspective]]; | ||
float f3_ [[user(loc2), center_perspective]]; | ||
}; | ||
struct needs_padding_fragOutput { | ||
metal::float4 member_3 [[color(0)]]; | ||
}; | ||
fragment needs_padding_fragOutput needs_padding_frag( | ||
needs_padding_fragInput varyings_3 [[stage_in]] | ||
) { | ||
const NeedsPadding input_2 = { varyings_3.f3_forces_padding, {}, varyings_3.v3_needs_padding, varyings_3.f3_ }; | ||
return needs_padding_fragOutput { metal::float4(0.0) }; | ||
} | ||
|
||
|
||
struct needs_padding_vertInput { | ||
float f3_forces_padding [[attribute(0)]]; | ||
metal::float3 v3_needs_padding [[attribute(1)]]; | ||
float f3_ [[attribute(2)]]; | ||
}; | ||
struct needs_padding_vertOutput { | ||
metal::float4 member_4 [[position]]; | ||
}; | ||
vertex needs_padding_vertOutput needs_padding_vert( | ||
needs_padding_vertInput varyings_4 [[stage_in]] | ||
) { | ||
const NeedsPadding input_3 = { varyings_4.f3_forces_padding, {}, varyings_4.v3_needs_padding, varyings_4.f3_ }; | ||
return needs_padding_vertOutput { metal::float4(0.0) }; | ||
} | ||
|
||
|
||
kernel void needs_padding_comp( | ||
constant NeedsPadding& needs_padding_uniform [[user(fake0)]] | ||
, device NeedsPadding const& needs_padding_storage [[user(fake0)]] | ||
) { | ||
NeedsPadding x_1 = {}; | ||
NeedsPadding _e2 = needs_padding_uniform; | ||
x_1 = _e2; | ||
NeedsPadding _e4 = needs_padding_storage; | ||
x_1 = _e4; | ||
return; | ||
} |
Oops, something went wrong.